Skip to content

Beam Caching - #65

Open
bhardwaj-gopika wants to merge 17 commits into
mainfrom
beam_caching
Open

bhardwaj-gopika wants to merge 17 commits into
mainfrom
beam_caching

Conversation

@bhardwaj-gopika

@bhardwaj-gopika bhardwaj-gopika commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Adds infrastructure for storing reference beam distributions at handoff planes under virtual_accelerator/beams/, backed by Git LFS.

Enforcement checks:

  • Pytest test (virtual_accelerator/tests/test_beam_sidecars.py) — parametrized over every .h5 under beams/. Asserts each has a matching .json sidecar containing all required fields. Runs in CI, so PRs cannot merge with missing or malformed sidecars.
  • Pre-commit hook (beam-h5-has-sidecar in .pre-commit-config.yaml, powered by scripts/check_beam_sidecars.py) — fires on staged .h5 files under beams/ and blocks the commit if any lack a sidecar.

Both operate on filenames, so LFS storage vs plain-git storage of the .h5 is irrelevant to the check.

@bhardwaj-gopika
bhardwaj-gopika marked this pull request as ready for review September 16, 2026 16:36
@bhardwaj-gopika
bhardwaj-gopika requested review from pluflou and roussel-ryan and a lite review from Copilot September 16, 2026 16:36

Copilot AI 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.

🟡 Changes recommended

Moderate issues remain in sidecar enforcement, documented metadata validation, and default-beam integration coverage.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds Git LFS-backed FACET2 beam distributions with JSON sidecars, validation checks, CI support, and related model API updates.

Changes:

  • Adds cached beam datasets and metadata.
  • Adds pytest and pre-commit sidecar enforcement.
  • Updates FACET2 defaults, scalar access, documentation, and CI LFS checkout.
File summaries
File Summary
virtual_accelerator/tests/test_surrogates.py Updates scalar reads.
virtual_accelerator/tests/test_static_model.py Updates scalar reads.
virtual_accelerator/tests/test_staged_model.py Updates scalar reads.
virtual_accelerator/tests/test_facet.py Updates scalar reads.
virtual_accelerator/tests/test_cu_hxr.py Updates scalar reads.
virtual_accelerator/tests/test_beam_sidecars.py Validates beam sidecars; does not enforce all documented required fields (moderate, 2 votes).
virtual_accelerator/tests/_bmad_model_test_utils.py Updates model helper reads.
virtual_accelerator/models/facet2.py Uses the cached default beam and new scalar API; default-beam integration coverage is missing (moderate, 1 vote).
virtual_accelerator/beams/2024-10-22_facet2_oneBunch/PR10241_100000.json Adds beam metadata.
virtual_accelerator/beams/2024-10-22_facet2_oneBunch/PR10241_100000.h5 Adds an LFS beam distribution.
virtual_accelerator/beams/2024-10-22_facet2_oneBunch/PR10241_10000.json Adds beam metadata.
virtual_accelerator/beams/2024-10-22_facet2_oneBunch/PR10241_10000.h5 Adds an LFS beam distribution.
virtual_accelerator/beams/2024-10-22_facet2_oneBunch/L0AFEND_100000.json Adds handoff beam metadata.
virtual_accelerator/beams/2024-10-22_facet2_oneBunch/L0AFEND_100000.h5 Adds the default LFS beam distribution.
scripts/check_beam_sidecars.py Implements sidecar checking but inspects only the working tree rather than the Git index (moderate, 3 votes).
README.md Documents beam storage and sidecar metadata requirements.
.pre-commit-config.yaml Registers the sidecar hook, but its path filter can bypass sidecar deletion or renaming (moderate, 1 vote).
.gitignore Allows beam HDF5 files.
.github/workflows/tests.yml Enables Git LFS checkout.
.github/workflows/test-core.yml Enables Git LFS checkout.
.github/workflows/test-bmad.yml Enables Git LFS checkout.
.gitattributes Configures HDF5 files for Git LFS.
Review details

Suppressed comments (2)

.pre-commit-config.yaml:34

  • This path filter only runs the hook when an .h5 pathname is staged. Staging deletion or renaming of foo.json while leaving foo.h5 unchanged therefore bypasses the hook and can commit a beam with no sidecar. Include sidecar changes in the trigger and normalize those inputs to their corresponding .h5 file, or have the hook scan all affected beam pairs.
        files: ^virtual_accelerator/beams/.*\.h5$

virtual_accelerator/models/facet2.py:170

  • This new default is used only when track_beam=True, start_element="L0AFEND", and no custom_beam_path is supplied, but the FACET tracking tests always pass TEST_BEAM_PATH (for example virtual_accelerator/tests/test_facet.py:60-94). A bad path or incompatible LFS beam can therefore reach users without CI detecting it; add an integration test that exercises the default-beam branch.
        default_beam_relpath="../beams/2024-10-22_facet2_oneBunch/L0AFEND_100000.h5",
  • Files reviewed: 21/25 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/check_beam_sidecars.py Outdated
Comment thread virtual_accelerator/tests/test_beam_sidecars.py

@roussel-ryan roussel-ryan 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.

Looks pretty good. A couple of comments,

  • we will need a top level API similar to the model registry API to get the particle beams easily, potentially with some kind of search function to look for beams at given locations and for certain machines
  • we should only have a single, large particle distribution for each location / time / operating mode, downsampling should be done by ParticleGroup.resample
  • can we just do .meta.json instead of h5.meta.json for the filenames? If there is a good reason to keep it as is then I'm willing to accept it, otherwise it would be good to key things just by the base file name

"date_generated": "2024-10-22",
"mode": "nominal_one_bunch",
"source": "FACET2-S2E 2024-10-22 one-bunch scenario; exact upstream file not confirmed",
"notes": "Default beam for the FACET-II Bmad model (resolved by virtual_accelerator.beams.get_beam). Mean z and energy computed with pmd_beamphysics.ParticleGroup: z=4.128 m, energy=68.62 MeV. Generator unclear from filename; the FACET2-S2E 2024-10-22_Impact_OneBunch run stops at PR10241 upstream of L0AF, so this file is likely a downstream track (Bmad or otherwise), not the raw IMPACT output."

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.

does this note need updating since you checked the source?

Comment thread virtual_accelerator/beams/__init__.py Outdated
element: str,
mode: str,
):
"""Return every cached beam matching ``(beamline, element, mode)``.

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.

can we add full dosctrings for all user facing methods/functions?

"TCY10490": "KLYS:LI10:51",
}

if track_beam and custom_beam_path is None and start_element == "L0AFEND":

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.

@roussel-ryan do we also need to update the logic in the bmad factory or are those beams handled differently?

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.

yes we will need to update the logic in the factory methods, that can come in a later PR

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.

We should remove the changes to this file in the meantime

@pluflou pluflou 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.

Looks good overall. I just would suggest full/clear docstrings for all user-facing methods/functions.

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.

this file and its corresponding sidecar should be removed in favor of the larger particle file

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.

4 participants