ptyrad.runtime.convergence#
ConvergenceMonitor: periodic convergence metric tracking for optimizable tensors.
Functions
Factory that returns a |
Classes
|
Tracks convergence of optimizable tensors during ptychographic reconstruction. |
- class ptyrad.runtime.convergence.ConvergenceMonitor(params, model)[source]#
Bases:
objectTracks convergence of optimizable tensors during ptychographic reconstruction.
Takes periodic snapshots of tracked tensors and computes the iter-to-iter change (relative to the previous snapshot) at each snapshot.
Tracked tensors:
obja,objp,probe,probe_pos_shifts.slice_thicknessandobj_tiltsare excluded — they are already tracked every iteration viamodel.dz_itersandmodel.avg_tilt_itersand fed directly to the dashboard.For
objaandobjp, metrics are computed on the ROI crop (scanned area bounding box) only.objais transformed as1 - objaso vacuum → 0 and material → >0. Two scalars are stored per tensor per step using percentile masking on the current snapshot: a background metric (pixels belowp_low) and a signal metric (pixels abovep_high). The results are stored under keysobja_bg,obja_fg,objp_bg,objp_fg.For
probe, the fractional intensity change (sum|ΔI| / sum(I_prev)) of mode-summed probe intensity is tracked. Forprobe_pos_shifts, the RMS displacement change in Å is tracked.Results are stored in
model.convergence_itersas a dict of lists of 2-tuples(niter, value).- Parameters:
params (dict) – Parsed
ConvergenceMonitorParamsdict (with keystensors,every_n_iters,percentile_range).model –
PtychoModelinstance. An initial snapshot is taken during__init__so the baseline is the state before the first optimizer update.
- ptyrad.runtime.convergence.create_convergence_monitor(convergence_monitor_params, model)[source]#
Factory that returns a
ConvergenceMonitorwhenconvergence_monitor_paramsis not None.- Parameters:
convergence_monitor_params – Parsed dict from
ReconParams.convergence_monitor, orNoneto disable monitoring.model –
PtychoModelinstance used for the initial snapshot.
- Returns:
A configured
ConvergenceMonitor, or None if params is None.- Return type:
ConvergenceMonitor | None