Adds two classmethods to CDIModel and its ptychography subclasses that
allow models to be reconstructed from saved .h5 result files without
needing the original dataset.
- CDIModel base class: add model_class and cdtools_version to
save_results(); add _load_results_dict() helper (restores state_dict
+ training metadata); add from_results_dict() interface method and a
concrete from_results_h5() that reads a file and delegates to
from_results_dict() — subclasses inherit this for free.
- SimplePtycho: make save_results(dataset=None) optional (dataset was
accepted but never used); add from_results_dict() which reconstructs
from probe, obj, wavelength, probe_basis, and min_translation stored
in the state_dict.
- FancyPtycho: add optional translations parameter to __init__,
registered as original_translations buffer; update from_dataset to
pass translations; make corrected_translations(dataset=None) fall back
to self.original_translations when no dataset is provided; make
save_results(dataset=None) use stored translations when no dataset is
provided; add from_results_dict() that detects all optional features
(mask, translation_offsets, weights, near-field propagators, etc.)
from the state_dict and reconstructs the full model. Also fix a latent
bug where background was passed to t.nn.Parameter() without
t.as_tensor(), which now fails when given a numpy array.
All existing tests pass; new tests added for both models verifying that
state_dict, training metadata, and forward pass output are all restored
exactly after a round-trip through from_results_dict and from_results_h5.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Revert test_Adam_gold_balls to default amplitude_mse
- Add new test_intensity_MSE test (gold balls + AdamReconstructor)
- Update near_field threshold to 17 (poisson_nll scale)
Thresholds for test_intensity_MSE to be tuned after GPU run.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use poisson_nll in test_near_field_ptycho and intensity_mse in
test_Adam_gold_balls to exercise these loss paths end-to-end.
Thresholds left as-is pending re-running on a GPU machine.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
poisson_nll now returns a sum rather than a mean, consistent with the
normalizer pattern. Remove the per-pixel divisions from the numpy
reference calculations accordingly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Updates tutorial_simple_ptycho.py to match simple_ptycho.py: removes
the def loss() method and instead assigns self.loss and
self.loss_normalizer as instance attributes in __init__.
Updates tutorial.rst accordingly: adds the loss assignment to the
__init__ code block with an explanation, and removes def loss() from
the forward model section.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds 'intensity_mse' as a selectable loss function (alongside the
existing 'amplitude_mse' and 'poisson_nll') to FancyPtycho,
MultislicePtycho, Bragg2DPtycho, Multislice2DPtycho, and RPI.
Models that previously had a hardcoded amplitude_mse assignment now
use the same configurable pattern as FancyPtycho, with the loss
parameter threaded through from_dataset and from_calibration as well.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Enables versioned documentation on ReadTheDocs. Installs the package
with its docs extras (sphinx, sphinx-rtd-theme, sphinx-argparse) so
autodoc can import cdtools during the build.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
All public functions in plotting.py now use the expanded multi-line
signature format with trailing commas for consistency and readability.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>