Commit Graph
510 Commits
Author SHA1 Message Date
levita_a d5f898a3fd Fix a memory leak in the plotting which was causing issues over long reconstructions 2026-07-22 10:56:26 +02:00
Abe Levitan 49cafdb177 Merge pull request #86 from cdtools-developers/fix_near_field_pr
Get position refinement working in near-field ptycho.
2026-07-15 13:11:59 +02:00
levita_a 211f0ac533 Apply a fix to the subpixel shifting for near-field ptycho to enable good position refinement 2026-07-11 07:14:48 +02:00
Abe Levitan a00085ba0a Merge pull request #82 from cdtools-developers/bump032dev1
bump the dev version to help referencing the latest batch of changes
2026-06-18 09:33:06 +02:00
allevitan f94ca02b20 bump the dev version to help referencing the latest batch of changes 2026-06-18 09:26:58 +02:00
Abe Levitan 6faade0ac1 Merge pull request #77 from cdtools-developers/savenload
Improve saving and loading of in-progress reconstructions
2026-06-17 15:23:30 +02:00
Abe Levitan 57a0c34229 Merge pull request #81 from cdtools-developers/fix_oversampling_pix_size
Fix an issue with the probe pixel size when probe_fourier_crop and oversampling are both used
2026-06-17 15:22:48 +02:00
allevitan 30da2ceeda Merge branch 'fix_oversampling_pix_size' into savenload 2026-06-17 00:56:48 +02:00
allevitan 5caad890b8 Fix a high priority issue with the probe pixel size when probe_fourier_crop and oversampling are both used 2026-06-17 00:56:13 +02:00
allevitan 8bb70748da Add the new save and load style to all other models except for Multislice2DPtycho, which is depricated anyway 2026-06-16 17:15:57 +02:00
allevitan 6af72e1ce0 Update the docs to include the new example for loading and viewing a ptychography reconstruction 2026-06-16 16:13:51 +02:00
allevitan 4d360f1361 Update all referencs in the examples documentation to follow the new pattern 2026-06-16 16:08:17 +02:00
allevitan dd31c39dc4 Add info on loading datasets to the tutorial 2026-06-16 16:03:40 +02:00
levita_a ed268a2c9c Update the saved gold ball ptycho treconstruction so it works with the new saving and loading 2026-06-16 15:48:14 +02:00
allevitan 4eb3a9879c Make the loading code for fancyptycho a bit more robust 2026-06-16 15:26:06 +02:00
allevitan 45949534f8 Remove the datset arg from all remaining examples of model.inspect() in the example code 2026-06-16 14:24:18 +02:00
allevitan 8ced842a58 Merge in master 2026-06-16 14:19:17 +02:00
Abe Levitan 29f0036248 Merge pull request #79 from cdtools-developers/bugfix/saving_loss_metrics
Fix a high priority bug where reconstructions will crash upon saving
2026-04-20 16:06:44 +02:00
levita_a a516f418b9 Fix a high priority bug where reconstructions will crash upon saving, and add test coverage to prevent a repeat 2026-04-20 15:40:55 +02:00
Abe Levitan 65a75b5c7e Merge pull request #70 from cdtools-developers/newpoisson
Switch to a more sensible normalization strategy for loss metrics
2026-04-17 15:12:03 +02:00
levita_a 83b1ed5d27 Add a script to demonstrate loading from a saved reconstruction and add the obj_view_crop and units arguments back 2026-04-13 17:35:47 +02:00
allevitan b9dcb03a93 Remove the need to use dataset for model.inspect() and model.save_results(), and update the examples accordingly. Docs and ipython notebooks not yet updated 2026-04-13 17:10:58 +02:00
allevitanandClaude Sonnet 4.6 6aa5df081b Add from_results_dict / from_results_h5 model loading from saved h5 files
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>
2026-04-13 15:47:07 +02:00
levita_a fcd0b31b2c Fix a bug with the mask implementation for the normalizers conflicting with SimplePtycho, and update the thresholds to accomodate the new normalization with masks and for intensity_MSE 2026-04-13 15:44:52 +02:00
allevitan d8fade9f32 Update the amplitude MSE and intensity MSE loss to act equivalently - currently, the intensity MSE loss was by default a mean, but amplitude was by default a sum. Both functions now have a flag, use_sum=False, which is False by default. This changes the default behavior of amplitude_mse. All models, including the tutorial version of simple_ptycho, are updated accordingly and test coverage was added. 2026-04-13 14:34:23 +02:00
levita_a 3c15b19ba7 Find and fix a bug where the normalization code didn't properly include masks 2026-04-10 16:22:58 +02:00
levita_a 3d10f36739 Fix a bug where the normalizers stopped the loss history from being saved as a numpy scalar, and added test coverage 2026-04-05 22:23:23 +02:00
levita_a 388d1669f3 Final checks to ensure all tests pass with the new scaling 2026-04-05 21:52:14 +02:00
levita_a 8ee8bf9237 Fix bug where fancyptycho test was not being run on GPU 2026-04-03 18:59:09 +02:00
levita_a b6553fd522 Update the example near field ptycho code to use Poisson NLL 2026-04-03 18:48:35 +02:00
allevitanandClaude Sonnet 4.6 3ccdc24d3f Restructure loss coverage in reconstruction tests
- 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>
2026-04-03 18:46:27 +02:00
allevitanandClaude Sonnet 4.6 178e9a4e4e Add loss function coverage to slow reconstruction tests
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>
2026-04-03 18:45:29 +02:00
allevitanandClaude Sonnet 4.6 d644782e94 Update poisson_nll test to match sum-based implementation
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>
2026-04-03 18:44:04 +02:00
allevitanandClaude Sonnet 4.6 fd17ae30ba Update tutorial to use loss instance attribute pattern
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>
2026-04-03 18:44:04 +02:00
allevitanandClaude Sonnet 4.6 8c380a34a6 Add intensity_mse loss option to all models
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>
2026-04-03 18:43:56 +02:00
levita_a d2c09acd44 Get all tests passing by updating the loss thresholds for the new normalizations, and add the new normalization to all models 2026-04-03 18:38:11 +02:00
allevitan 023ab318ee Added some better documentation to the loss functions 2026-04-03 18:38:11 +02:00
allevitan 4dbcffd67b Attempted to update the normalizations for the loss functions in a way which allows for a nice normalization of the Poisson NLL. The slow tests will now likely fail 2026-04-03 18:38:11 +02:00
Abe Levitan 3f028e2fbf Merge pull request #72 from cdtools-developers/feature/betterplots
A bunch of long overdue updates to the plotting system
2026-04-03 18:23:41 +02:00
Abe Levitan 06105d38c7 Merge pull request #76 from cdtools-developers/v0.3.2.dev
Start on 0.3.2.dev
2026-04-03 18:22:19 +02:00
levita_a 3b6e73b48c Start on 0.3.2.dev 2026-04-03 18:20:53 +02:00
allevitan a87e3415d2 Responding to self-review comments 2026-04-03 17:54:59 +02:00
Abe Levitan 40f829b430 Merge pull request #71 from cdtools-developers/bugfix/intensity_loading
Fix issue #68 for loading of datasets with intensities when using OPRP
2026-04-03 16:24:16 +02:00
Abe Levitan d7d5ed8401 Merge pull request #73 from cdtools-developers/v0.3.1
Change version to 0.3.1
v0.3.1
2026-04-03 15:43:45 +02:00
Abe Levitan 48a9a7f8ac Merge pull request #75 from cdtools-developers/readthedocs
Update the docs so it doesn't always think it's v0.2.0
2026-04-03 15:29:16 +02:00
allevitan 05bdee3861 Update the docs so it doesn't always think it's v0.2.0 2026-04-03 15:24:50 +02:00
Abe Levitan e84dc9f76e Merge pull request #74 from cdtools-developers/readthedocs
Add .readthedocs.yaml for ReadTheDocs hosting
2026-04-03 14:32:24 +02:00
allevitanandClaude Sonnet 4.6 7de8448319 Add .readthedocs.yaml for ReadTheDocs hosting
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>
2026-04-03 14:28:01 +02:00
allevitan 4030218fa4 Change version to 0.3.1 2026-03-26 15:11:55 +01:00
allevitan 0bd8df498c Updated the documentation to reflect the changes to the plotting system 2026-03-24 21:39:04 +01:00