Skip to content

Mg/update DTEx252 - #533

Open
mirjagranfors wants to merge 6 commits into
developfrom
mg/updateDTEx252
Open

mirjagranfors wants to merge 6 commits into
developfrom
mg/updateDTEx252

Conversation

@mirjagranfors

@mirjagranfors mirjagranfors commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Updating tutorial for the phase mask.

Since training one of the CNNs takes about 2 days on my computer, and the entire notebook therefore takes about 4 days to run, I have added the option to use the weights and phase mask from my training.

For the figure in the paper, I want the comparison between the cases with and without the phase mask to be as fair as possible. Therefore, I have made the examples for calculating the metrics and showing the results in 3D use the exact same number of particles, particle positions, and noise. However, I am not sure whether it is a good idea to add this as a separate notebook (which is what I did in this PR) or if there is a better way to do it.

@Pwhsky Pwhsky self-assigned this Oct 1, 2026
@Pwhsky
Pwhsky self-requested a review October 1, 2026 10:35

@Pwhsky Pwhsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@edudc edudc left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one blocking issue in the figures notebook. The rest are suggestions and non-blocking issues with plotting and evaluation.
Otherwise code runs fine (didn't rerun the whole training).

"\n",
" rng_state = torch.get_rng_state()\n",
" np_state = np.random.get_state()\n",
" cuda_state = torch.cuda.get_rng_state(device)\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): The notebook selects CPU when CUDA is unavailable, but resolve_paired_sample() then calls torch.cuda.get_rng_state(device) unconditionally. You should guard both of the CUDA random state calls for CPU.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: added a use_cuda flag and both torch.cuda.get_rng_state and set_rng_state calls are now only run when CUDA is used.

Comment thread tutorials/2-examples/DTEx252_phase_mask_optimization.ipynb
Comment thread tutorials/2-examples/DTEx252_phase_mask_optimization.ipynb
Comment thread tutorials/2-examples/DTEx252B_phase_mask_optimization_figures.ipynb Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The phase-mask and baseline sections repeat most of the training/validation loop, evaluation and plotting, with few things changed. Maybe a train_model(...) and evaluate_model(...) helper could keep the notebooks smaller and more readable. Just an idea for future notebooks, I don't think a refactor is needed here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. I'll keep it in mind for future tutorials.

@mirjagranfors
mirjagranfors requested a review from edudc October 9, 2026 08:54

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants