Conversation
…iles 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>
…ults(), and update the examples accordingly. Docs and ipython notebooks not yet updated
…dd the obj_view_crop and units arguments back
…in the example code
…e new saving and loading
…ptychography reconstruction
…lice2DPtycho, which is depricated anyway
…r_crop and oversampling are both used
allevitan
marked this pull request as ready for review
June 17, 2026 13:13
Collaborator
Author
|
I think this is useful enough and close enough to be merged into master - loading obj_view_crop is not critical, Multislice2DPtycho is depricated anyway, and the additional models don't have any test coverage yet. Adding that coverage is it's own, separate project |
allevitan
commented
Jun 17, 2026
allevitan
left a comment
Collaborator
Author
There was a problem hiding this comment.
Reviewed all the changes from yesterday. I hate to merge into master so quickly, but the vast majority of this work comes from >1 month ago, self-reviewed yesterday with the final, primarily cosmetic, changes to update all the documentations and scripts. I will merge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR will implement a better system for loading reconstructions from the saved results files as .h5
This touches a lot of outstanding needs:
To-dos: