Skip to content

refactor: consume ptychoml.stitch + dedup pixel-size formula#38

Merged
Garrett Bischof (gwbischof) merged 1 commit into
mainfrom
h1/reuse-ptychoml-stitch-pixelsize
Jun 5, 2026
Merged

refactor: consume ptychoml.stitch + dedup pixel-size formula#38
Garrett Bischof (gwbischof) merged 1 commit into
mainfrom
h1/reuse-ptychoml-stitch-pixelsize

Conversation

@gwbischof

Copy link
Copy Markdown
Collaborator

First holoptycho PR of the #37 decomposition (H1). A zero-behavior-change refactor that reuses generic ptychography code from ptychoml instead of duplicating it.

Changes

  • Stitching → ptychoml.stitch. Delete holoptycho/mosaic_stitch.py; import stitch_batch_into from ptychoml.stitch. The algorithms were lifted verbatim into ptychoml in NSLS2/ptychoml#10 (proven bit-identical on random inputs), so live mosaic output is unchanged.
  • Pixel-size formula → ptychoml.compute_sample_pixel_size. Replace the inline λ·z / (N·ccd) far-field formula in streaming_recon.py (gpu_setup) and live_compare_viewer.py with the shared helper — same math.
  • AGENTS.md: repoint stitch references to ptychoml.stitch and document the reuse boundary (generic numpy helpers live in ptychoml; holoptycho keeps the Holoscan operators).

Testing

Correctness of the moved/reused code is owned by ptychoml's tests (stitch placement + the pixel-size formula) — not re-tested here. On the holoptycho side the existing suite already exercises the new wiring:

  • test_streaming_recon.py::TestInitConfig constructs StreamingPtychoRecon (exercises the new ptychoml import) and TestGpuSetup runs gpu_setup (exercises the compute_sample_pixel_size calls).
  • test_smoke.py imports vit_inference (exercises the ptychoml.stitch import) and streaming_recon.
pixi run pytest tests/test_streaming_recon.py tests/test_smoke.py
# all pass; the two vit_inference/ptycho_holo smoke imports fail locally only
# because module-load needs a reachable TILED_BASE_URL (pre-existing, unrelated).

Depends on

NSLS2/ptychoml#10 (merged). pixi.lock is bumped to that ptychoml main commit.

Reuse generic ptychography code from ptychoml instead of duplicating it
(no behavior change):

- Delete holoptycho/mosaic_stitch.py; import stitch_batch_into from
  ptychoml.stitch (NSLS2/ptychoml#10 lifted the algorithms verbatim, so
  output is bit-identical).
- Replace the inline far-field pixel-size formula in streaming_recon.py
  (gpu_setup) and live_compare_viewer.py with
  ptychoml.compute_sample_pixel_size — same math.
- AGENTS.md: point stitch references at ptychoml.stitch and note the
  reuse boundary.

Correctness of the moved/reused code is covered by ptychoml's tests; the
existing holoptycho smoke + streaming_recon tests exercise the new import
paths and the gpu_setup pixel-size call. First holoptycho PR (H1) of the
#37 decomposition.

Co-authored-by: Himanshu Goel <4122621+himanshugoel2797@users.noreply.github.com>
@gwbischof Garrett Bischof (gwbischof) merged commit 9b89df2 into main Jun 5, 2026
5 checks passed
Garrett Bischof (gwbischof) added a commit that referenced this pull request Jun 8, 2026
ptychoml renamed PtychoViTInference's 'data_is_shifted' parameter to
'fftshift' (None = auto-detect DC via detect_dc_at_corner). holoptycho main
still called PtychoViTInference(data_is_shifted=...), which raises TypeError
against the pinned ptychoml (the bump in #38 crossed the rename) — the ViT op
would crash on its first batch. Smoke tests missed it: the vit_inference
import dies earlier on TILED_BASE_URL, and CI envs skip holoscan entirely.

Rename PtychoViTInferenceOp's param data_is_shifted -> fftshift and pass
fftshift= to the session; drop data_is_shifted=True in ptycho_holo.py and let
it default to None (auto-detect), matching PR #37's end-to-end DC handling
that pairs with this PR's preprocess_diffraction(fftshift=fftshift_dp=None).

Adds tests/test_vit_session_contract.py to pin the holoptycho<->ptychoml call
contract so a future rename fails in CI instead of on the beamline.

Co-authored-by: Himanshu Goel <4122621+himanshugoel2797@users.noreply.github.com>
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.

1 participant