pyextal.jaxEngine.setParams =========================== .. py:module:: pyextal.jaxEngine.setParams Classes ------- .. autoapisummary:: pyextal.jaxEngine.setParams.OptConfig Functions --------- .. autoapisummary:: pyextal.jaxEngine.setParams.prepare_reflection_bounds pyextal.jaxEngine.setParams.denorm_fn pyextal.jaxEngine.setParams.norm_fn pyextal.jaxEngine.setParams.denormalize_params pyextal.jaxEngine.setParams.normalize_params pyextal.jaxEngine.setParams.get_bloch_constants pyextal.jaxEngine.setParams.calculate_tilt_dependent_values pyextal.jaxEngine.setParams.calculate_static_ugh pyextal.jaxEngine.setParams._check_thickness_range pyextal.jaxEngine.setParams.setup_optimization_params pyextal.jaxEngine.setParams.setup_optimization_model pyextal.jaxEngine.setParams.setup_structure_factors pyextal.jaxEngine.setParams.fridel_symmetry_only pyextal.jaxEngine.setParams.spgsym Module Contents --------------- .. py:class:: OptConfig Bases: :py:obj:`NamedTuple` Configuration for optimization parameters One can choose to 1. normalize everything to a 0-1 range (set *_normalize=True) and optimize in the normalized space, then denormalize for the forward model. 2. normalize all other parameters to a range similar to structure factors but not the structure factors, (set beams_normalize=False, *_normalize= SOME SCALING FACTOR) There is no obvious difference in the result but the second approach is easier to extract results and no need to set up bounds for structure factors. Different learning rate might be needed for different approaches. Args: .. py:attribute:: reflections :type: Tuple[Tuple[int, int, int], ...] | int .. py:attribute:: reflections_normalize :type: bool :value: False .. py:attribute:: reflections_upperbound :type: Optional[Tuple] :value: None .. py:attribute:: reflections_lowerbound :type: Optional[Tuple] :value: None .. py:attribute:: sf_mask :type: Tuple[bool, bool, bool, bool] :value: (True, True, True, True) .. py:attribute:: symmetry_constraint :type: str :value: 'Friedel' .. py:attribute:: loss_function :type: str :value: 'chi2' .. py:attribute:: batch_mode :type: str :value: 'chunking' .. py:attribute:: update_mode :type: str :value: 'per_epoch' .. py:attribute:: thickness_optimize :type: bool :value: False .. py:attribute:: initial_thickness :type: float :value: 100.0 .. py:attribute:: thickness_range :type: Tuple[float, float] :value: (0.0, 200.0) .. py:attribute:: thickness_normalize :type: bool :value: True .. py:attribute:: probe_optimize :type: bool :value: False .. py:attribute:: initial_sigma_probe :type: float :value: 0.0 .. py:attribute:: initial_gamma_probe :type: float :value: 0.0 .. py:attribute:: probe_sigma_range :type: Tuple[float, float] :value: (0.0, 10.0) .. py:attribute:: probe_gamma_range :type: Tuple[float, float] :value: (0.0, 10.0) .. py:attribute:: probe_normalize :type: bool :value: True .. py:attribute:: use_voigt :type: bool :value: False .. py:attribute:: output_indices :type: Tuple[int, ...] :value: () .. py:attribute:: output_shape :type: Tuple[int, int] :value: (0, 0) .. py:attribute:: chunk_shape :type: Tuple[int, int] :value: (0, 0) .. py:attribute:: kernel_radius :type: int :value: 0 .. py:attribute:: stride :type: Tuple[int, int] :value: (0, 0) .. py:attribute:: learning_rate :type: float :value: 0.001 .. py:attribute:: num_steps :type: int :value: 1000 .. py:attribute:: warmup_steps :type: int :value: 0 .. py:attribute:: fix_after :type: int :value: 0 .. py:attribute:: initial_scale :type: float :value: 1.0 .. py:attribute:: scale_range :type: Tuple[float, float] :value: (0.0, 10.0) .. py:attribute:: intensity_scale_optimize :type: bool :value: True .. py:attribute:: intensity_scale_normalize :type: bool :value: True .. py:attribute:: initial_background :type: float :value: 0.0 .. py:attribute:: background_range :type: Tuple[float, float] :value: (0.0, 1.0) .. py:attribute:: background_optimize :type: bool :value: True .. py:attribute:: background_normalize :type: bool :value: True .. py:attribute:: power_regularization_weight :type: float :value: 0.0 .. py:attribute:: nlayers :type: int :value: 1 .. py:attribute:: frozen_layers :type: Tuple[int, ...] :value: () .. py:attribute:: diagonalise_measured :type: bool :value: True .. py:attribute:: model_name :type: Optional[str] :value: None .. py:attribute:: model_params :type: Optional[list[dict]] :value: None .. py:attribute:: model_params_normalize :type: bool :value: True .. py:attribute:: model_params_range :type: Optional[list[dict]] :value: None .. py:attribute:: refined_entity :type: str :value: 'structure_factor' .. py:attribute:: oversub_indices :type: Tuple[int, ...] :value: () .. py:attribute:: oversub_leak_index :type: int :value: -1 .. py:attribute:: oversub_optimize :type: bool :value: False .. py:attribute:: initial_oversub_offset :type: Tuple[float, ...] :value: () .. py:attribute:: initial_oversub_leak :type: Tuple[float, ...] :value: () .. py:attribute:: oversub_offset_upper :type: Tuple[float, ...] :value: () .. py:attribute:: oversub_leak_upper :type: Tuple[float, ...] :value: () .. py:method:: from_yaml(filepath: str) -> OptConfig :classmethod: Load OptConfig from YAML file .. py:method:: to_yaml(filepath: str) -> None Save OptConfig to YAML file in a human-readable format. .. py:function:: prepare_reflection_bounds(reflections: List[Tuple[int, int, int]], values: Optional[List[Tuple[float, float, float, float]]] = None, upperbounds: Optional[List[Tuple[float, float, float, float]]] = None, lowerbounds: Optional[List[Tuple[float, float, float, float]]] = None, bound_percentage: tuple = (0.05, 0.05, 0.05, 0.05)) -> Tuple[Tuple[Tuple[int, int, int], ...], Tuple[Tuple[float, float, float, float], ...], Tuple[Tuple[float, float, float, float], ...], Tuple[Tuple[float, float, float, float], ...]] Prepare reflection bounds for optimization. :param reflections: List of reflection tuples (h, k, l) :param values: Optional list of initial values [U_amp, U_phase, UA_amp, UA_phase] for each reflection :param upperbounds: Optional list of upper bounds for each reflection :param lowerbounds: Optional list of lower bounds for each reflection :param bound_percentage: Percentage to use for automatic bounds (default 5%) :returns: Tuple of (reflections, values, upperbounds, lowerbounds) as tuples for OptConfig .. py:function:: denorm_fn(p, lower, upper, m) .. py:function:: norm_fn(p, lower, upper, m) .. py:function:: denormalize_params(params: Dict, metadata: Dict, mask: Dict) -> Dict .. py:function:: normalize_params(params: Dict, metadata: Dict, mask: Dict) -> Dict .. py:function:: get_bloch_constants(alpha: float) -> Dict Extract constants from blochwave module with float32 precision .. py:function:: calculate_tilt_dependent_values(tilts: jax.numpy.ndarray, constants: Dict, config: OptConfig) -> Dict Calculate all tilt-dependent values that don't change during optimization. This includes excitation errors (sg), bigkz, and bigkn values. :param tilts: Array of tilt vectors, shape (n_tilts, 3) :param constants: Dictionary containing hkl, gmxr, bigk, zone, alpha, snorm :returns: Dict containing pre-calculated values for all tilts .. py:function:: calculate_static_ugh(params_dict: Dict, reflection_list: List, phase: jax.numpy.ndarray, mask: jax.numpy.ndarray, nbeams: int) -> Tuple[jax.numpy.ndarray, jax.numpy.ndarray] Calculate Ugh contribution from static reflections. .. py:function:: _check_thickness_range(config: OptConfig) -> None Warns when ``thickness_range`` looks like Angstrom rather than a ratio. The forward model uses the thickness parameter as a ratio of ``initial_thickness``, so the bounds are ratios too. Bounds in Angstrom make every normalised Adam step ``initial_thickness`` times too large. .. py:function:: setup_optimization_params(config: OptConfig, tilts: jax.numpy.ndarray, constants: Dict, initial_value: Optional[List[Dict]] = None) -> Dict Setup initial parameters and metadata for optimization. :returns: Dict with 'params' (dict of dicts) and 'metadata' for reconstruction .. py:function:: setup_optimization_model(config: OptConfig, tilts: jax.numpy.ndarray, constants: Dict) -> Dict Setup initial parameters and metadata for optimization. :returns: Dict with 'params' (dict of dicts) and 'metadata' for reconstruction .. py:function:: setup_structure_factors(hkl_all: numpy.ndarray, sym: pyextal.symmetry.GroupSymmetry, config: OptConfig, sf: numpy.ndarray = None) -> Tuple[Dict, List[Tuple[int, int, int]], jax.numpy.ndarray, jax.numpy.ndarray] .. py:function:: fridel_symmetry_only(hkl_all: numpy.ndarray, sf: numpy.ndarray = None) -> Tuple[List[Tuple[int, int, int]], Dict] Generate parameters dict and metadata for Friedel symmetry only case. .. py:function:: spgsym(hkl_all: numpy.ndarray, sym: pyextal.symmetry.GroupSymmetry, sf: numpy.ndarray = None)