Torch-native PDF pipeline + origin finder improvements#248
Open
ehrhardtkm wants to merge 6 commits into
Open
Conversation
added 6 commits
June 4, 2026 13:17
Collaborator
|
@ehrhardtkm before I review, it seems like being merged to |
Collaborator
|
Another question I had was from the PR comment was - what's approx speed/improvement given various sizes? Mostly likely it will be either 512x512x192x192 or 256x256x192x192 to be practical, just ballpark numbers. Ref: |
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.
What problem this PR addresses
Follow-on to #177 (the polar transform + PDF pipeline that merged into
nanobeam). This PR brings that work ontodevand lands the changes I've made since.Conceptually unchanged — same
Polar4dstemdatastructure, samePairDistributionFunctionshape, same overall workflow (origin → polar → PDF). The public API should be the same, except for a few minor changes.Changes since #177:
Fully torch-native, dual-backend pipeline. The whole pipeline accepts numpy or torch input on the existing
Dataset, device is inferred from the input, and there are no GPU↔CPU round-trips inside the pipeline. numpy vs tensor input give identical results.Background fitting. Rewritten with an analytic Jacobian that is noticeably faster than the previous implementation. Added a batched
fit_bg_batchedpath for full-dataset use, which the downstream PDF widget (PR3) needs to recompute backgrounds interactively. Also includes some small fixes I picked up while running this on real data.Origin finding. The existing finder's hardcoded margin requirement caused it to error out on smaller detectors, so I made it the margin dynamic and added a 2D-quadratic subpixel refinement (renamed to
find_origin_angular_grid). I also added a secondary option,find_origin_angular_descent, a margin-free, COM-anchored descent finder. It's slower but I've found it slightly more reliable on noisier data. Both are dispatched fromPolar4dstem.from_data(origin_method="grid"|"descent").Tests in
tests/diffraction/test_polar.pyare parametrized over both origin finders and add coverage for the new code paths.Out of scope (follow-on PRs to shortly follow):
What should the reviewer(s) do
Merge after review. Reviewing commit-by-commit is likely easier than the unified diff — each commit is a single conceptual change.