recon_step

Contents

recon_step#

ptyrad.reconstruction.recon_step(batches, grad_accumulation, model, optimizer, loss_fn, constraint_fn, niter, verbose=True, acc=None)[source]#

Performs one iteration (or step) of the ptychographic reconstruction in the optimization loop.

This function executes a single iteration of the reconstruction process, including: - Computing the forward model to generate diffraction patterns. - Calculating the loss by comparing the modeled and measured diffraction patterns. - Performing a backward pass to compute gradients and update the model parameters using the optimizer. - Applying iteration-wise constraints after all batches are processed.

Parameters:
  • batches (list of numpy.ndarray) – List of batches where each batch contains indices grouped according to the selected grouping mode.

  • model (PtychoAD) – The ptychographic model containing the parameters and variables to be optimized.

  • optimizer (torch.optim.Optimizer) – The optimizer used to update the model parameters.

  • loss_fn (CombinedLoss) – The loss function object used to compute the loss for each batch.

  • constraint_fn (CombinedConstraint) – The constraint function object applied after each iteration to enforce specific constraints on the model.

  • niter (int) – The current iteration number in the optimization loop.

  • verbose (bool, optional) – If True, prints progress information during the batch processing. Defaults to True.

Returns:

A tuple containing:
  • batch_losses (dict): A dictionary where each key corresponds to a loss component name, and the value is a list of loss values computed for each batch in the iteration.

  • iter_t (float): The total time taken to complete the iteration.

Return type:

tuple