optuna_objective#
- ptyrad.reconstruction.optuna_objective(trial, params, init, loss_fn, constraint_fn, device='cuda', verbose=False)[source]#
Objective function for Optuna hyperparameter tuning in ptychographic reconstruction.
This function is used by Optuna to optimize the hyperparameters of the ptychographic reconstruction process. The function updates the reconstruction parameters based on the trial’s suggestions and runs the reconstruction loop to evaluate the performance. The function also implements Optuna’s pruning mechanism to stop unpromising trials early.
- Parameters:
trial (optuna.trial.Trial) – A trial object that suggests hyperparameter values and handles pruning.
params (dict) – A dictionary containing all the parameters for the reconstruction, including experimental parameters, model parameters, and hyperparameter tuning configurations.
init (Initializer) – An instance of the Initializer class that holds initialized variables and methods for updating them based on the trial’s suggestions.
loss_fn (CombinedLoss) – The loss function object that calculates the reconstruction loss.
constraint_fn (CombinedConstraint) – The constraint function object that applies constraints during optimization.
device (str, optional) – The device to run the reconstruction on, e.g., ‘cuda’. Defaults to ‘cuda’.
verbose (bool, optional) – If True, enables verbose output. Defaults to False.
- Returns:
The total loss for the final iteration of the reconstruction process, used by Optuna to evaluate the trial’s performance.
- Return type:
float
- Raises:
optuna.exceptions.TrialPruned – Raised when the trial should be pruned based on the
intermediate results. –