Skip to content

Conversation

@a4894z
Copy link
Collaborator

@a4894z a4894z commented May 28, 2025

Features/fixes

The previous attempt at merging dict learn and multislice was hopeless, so I've rewritten the dict learn update rules to be compatible with multislice and OPRs

Related issues (optional)

See the previous pull request "#34"

Mentions

Ming Du

Checklist

Have you...

  • Formatted your code properly adhering to PEP-8? Considering using RUFF to format your code automatically.
    doubt it

  • Resolved all merge conflicts with the main branch?

not sure yet

  • Checked the diffs between your branch and the main branch to ensure that your changes are not introducing any regressions or unnecessary/irrelevant changes?

I think so

this should fix it (for Nopr = 1), for Nopr>1, not sure
@a4894z a4894z requested review from Copilot and mdw771 May 28, 2025 18:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR rewrites the dictionary learning update rules to support multislice objects and OPRs (for a single probe), and refactors sparse-code–based probe initialization and generation.

  • Reimplemented compute_updates in the PIE reconstructor to handle multiple slices and integrate sparse code updates.
  • Refactored probe data structure to derive and register sparse-code–based weights instead of initial weights.
  • Updated step‐weight calculations and tensor assignments for sparse‐dictionary probes.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/ptychi/reconstructors/pie.py Overhauled compute_updates for multislice and sparse‐code probe updates; added slice loops
src/ptychi/data_structures/probe.py Renamed get_initial_weightsget_sparse_code_weights; revised generate tensor handling
Comments suppressed due to low confidence (1)

src/ptychi/reconstructors/pie.py:95

  • [nitpick] The variable unique_probes now holds data for all slices rather than a single slice; consider renaming it to shifted_probes_per_slice or similar for clarity.
unique_probes = self.forward_model.intermediate_variables.shifted_unique_probes

Comment on lines 260 to 269
#from PySide6.QtWidgets import QApplication
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from mpl_toolkits.axes_grid1 import make_axes_locatable
#mpl.use('Agg')
#mpl.use('TKAgg')
#mpl.use('WebAgg')
mpl.use('QTAgg')
mpl.rcParams['agg.path.chunksize'] = 10000
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

Move heavy imports and plotting code out of the inner update loop; consider extracting debug visualization into a separate utility or removing before merge.

Suggested change
#from PySide6.QtWidgets import QApplication
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from mpl_toolkits.axes_grid1 import make_axes_locatable
#mpl.use('Agg')
#mpl.use('TKAgg')
#mpl.use('WebAgg')
mpl.use('QTAgg')
mpl.rcParams['agg.path.chunksize'] = 10000
# Debug visualization (if needed)
self._debug_visualize(sparse_code_probe)

Copilot uses AI. Check for mistakes.
Comment on lines 505 to 506
# is this the correct way to retain the originally initialized grad?
self.tensor.data.data = torch.stack([probe.real, probe.imag], dim=-1)
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

Directly manipulating .data is deprecated. Use APIs like with torch.no_grad(): self.tensor.copy_(...) or self.tensor.data = probe.view_as(self.tensor) to preserve autograd correctness.

Suggested change
# is this the correct way to retain the originally initialized grad?
self.tensor.data.data = torch.stack([probe.real, probe.imag], dim=-1)
# Safely update self.tensor without breaking autograd
with torch.no_grad():
self.tensor.copy_(torch.stack([probe.real, probe.imag], dim=-1))

Copilot uses AI. Check for mistakes.
@mdw771 mdw771 force-pushed the multisliceRPIE_v2 branch from b07b953 to 511cad7 Compare June 6, 2025 20:48
@mdw771 mdw771 force-pushed the multisliceRPIE_v2 branch from 5add0c1 to e838253 Compare June 13, 2025 15:51
@mdw771 mdw771 merged commit 81fe826 into main Jun 13, 2025
4 checks passed
@a4894z a4894z deleted the multisliceRPIE_v2 branch June 15, 2025 20:57
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