tsadar.inverse.loops#

Functions

angular_multiple_optax(config, sa, loss_fn, ...)

This performs an fitting routines from the optax packages, different minimizers have different requirements for updating steps Performs parameter optimization using Optax minimizers for angular Thomson scattering data.

angular_optax(config, sa, loss_fn, actual_data)

This performs an fitting routines from the optax packages, different minimizers have different requirements for updating steps Performs parameter optimization using Optax minimizers for angular Thomson scattering data.

label(diff_params, cfg_params)

multirun_angular_optax(config, all_data, sa)

Higher level wrapper for angular Thomson scattering data optimization using Optax.

one_d_loop(config, all_data, sa, ...[, ...])

Higher level wrapper form minimization of 1D fits, preparing data and dispatching to the appropriate optimizer.

tsadar.inverse.loops.one_d_loop(config: Dict, all_data: Dict, sa: Tuple, batch_indices: ndarray, num_batches: int, previous_weights=None) Tuple[List, float, LossFunction]Source#

Higher level wrapper form minimization of 1D fits, preparing data and dispatching to the appropriate optimizer. This function prepares batches of data and fits model parameters using either the ADAM optimizer or a SciPy optimizer, depending on the configuration. It supports sequential optimization by passing weights between batches if enabled.

Parameters:
  • config (Dict) – Configuration dictionary containing optimizer settings and batch size.

  • all_data (Dict) – Dictionary containing all input data arrays required for fitting.

  • sa (Tuple) – Scattering angles and weights used to calculate k-smea r corrections.

  • batch_indices (np.ndarray) – Array of indices specifying how to split data into batches.

  • num_batches (int) – Number of batches to process.

  • previous_weights (np.ndarray, optional) – Weights to initialize the optimizer. If None, initializes new parameters.

Returns:

all_weights (List) – List of weights from each batch. overall_loss (float): Overall accumulated loss across all batches. loss_fn (LossFunction): The final LossFunction instance used for fitting.

Notes

  • The function uses a progress bar to display the fitting progress for each batch.

  • The function logs metrics to MLflow for tracking the fitting process.

tsadar.inverse.loops.angular_optax(config, sa, loss_fn, actual_data, previous_weights=None, previous_epoch=None)Source#

This performs an fitting routines from the optax packages, different minimizers have different requirements for updating steps Performs parameter optimization using Optax minimizers for angular Thomson scattering data. This function sets up and runs a fitting routine using the Optax optimization library, applying the specified minimizer to fit model parameters to experimental data. It handles data batching, optimizer initialization, training loop with early stopping, and logging of metrics and optimizer state.

Parameters:
  • config (dict) – Configuration dictionary built from the input decks, specifying optimizer, data, and parameter settings.

  • all_data (dict) – Dictionary containing datasets, amplitudes, and backgrounds as constructed by the prepare.py code.

  • sa (dict) – Dictionary of the scattering angles and their relative weights.

Returns:

best_weights (dict) – Best parameter weights as returned by the minimizer. best_loss (float): Best value of the fit metric found by the minimizer. ts_instance (LossFunction): Instance of the LossFunction object used for minimization.

Notes

  • Supports early stopping based on loss improvement or degradation.

  • Logs training metrics and optimizer state using mlflow.

  • Handles both single and multiple shot number data configurations for rotated repeats of data.

tsadar.inverse.loops.multirun_angular_optax(config: Dict, all_data: Dict, sa: Tuple) Tuple[List, float, LossFunction]Source#

Higher level wrapper for angular Thomson scattering data optimization using Optax.

Parameters:
  • config (Dict) – Configuration dictionary containing optimizer settings and batch size.

  • all_data (Dict) – Dictionary containing all input data arrays required for fitting.

  • sa (Tuple) – Scattering angles and weights used to calculate k-smea r corrections.

  • batch_indices (np.ndarray) – Array of indices specifying how to split data into batches.

  • num_batches (int) – Number of batches to process.

  • previous_weights (np.ndarray, optional) – Weights to initialize the optimizer. If None, initializes new parameters.

Returns:

all_weights (List) – List of weights from each batch. overall_loss (float): Overall accumulated loss across all batches. loss_fn (LossFunction): The final LossFunction instance used for fitting.

Notes

  • The function uses a progress bar to display the fitting progress for each batch.

  • The function logs metrics to MLflow for tracking the fitting process.

tsadar.inverse.loops.angular_multiple_optax(config, sa, loss_fn, actual_data, previous_weights=None, previous_epoch=None)Source#

This performs an fitting routines from the optax packages, different minimizers have different requirements for updating steps Performs parameter optimization using Optax minimizers for angular Thomson scattering data. This function sets up and runs a fitting routine using the Optax optimization library, applying the specified minimizer to fit model parameters to experimental data. It handles data batching, optimizer initialization, training loop with early stopping, and logging of metrics and optimizer state.

Parameters:
  • config (dict) – Configuration dictionary built from the input decks, specifying optimizer, data, and parameter settings.

  • all_data (dict) – Dictionary containing datasets, amplitudes, and backgrounds as constructed by the prepare.py code.

  • sa (dict) – Dictionary of the scattering angles and their relative weights.

Returns:

best_weights (dict) – Best parameter weights as returned by the minimizer. best_loss (float): Best value of the fit metric found by the minimizer. ts_instance (LossFunction): Instance of the LossFunction object used for minimization.

Notes

  • Supports early stopping based on loss improvement or degradation.

  • Logs training metrics and optimizer state using mlflow.

  • Handles both single and multiple shot number data configurations for rotated repeats of data.

tsadar.inverse.loops.label(diff_params, cfg_params)Source#