Appendix F — Contributing¶
How to extend HELIX, fix bugs, build the Windows distribution, and add to this manual.
Repository layout¶
linac_gen/
├── core/ # ReferenceParticle, Beam, Lattice, Simulation
├── elements/ # Drift, Quadrupole, Solenoid, Dipole, ...
├── tracking/ # Tracker, EnvelopeSolver, Sacherer ODE
├── pic/ # CIC/TSC deposition, FFT Poisson, C++ kernels
├── distributions/ # Gaussian, KV, Waterbag, Parabolic, Uniform, Thermal
├── matching/ # Levenberg-Marquardt matcher, variables, constraints
├── errors/ # ErrorStudy, ErrorDef, BeamErrorDef
├── diagnostics/ # DiagnosticRecorder, moments, eigenemittance
├── analysis/ # Aperture profile, magnetic stripping, IBS, phase advance
├── io/ # TraceWin parser/writer, FieldMap reader, .dst, .h5
└── csrc/ # C++ pybind11 kernels (compiled to _pic_kernels.so)
gui/linac_gen_gui/ # PyQt6 GUI
tests/ # pytest suite
examples/ # Runnable Python scripts + sample .dat lattices
docs/ # This manual + physics.md + fieldmap_guide.md
Adding a new element¶
- Create
linac_gen/elements/my_element.py. - Inherit from one of the four base classes:
TransferMapElement,ThinKickElement,FieldMapElement,PassiveElement. - Add Misalignment + FieldError mixins as appropriate.
- Implement
transfer_matrix()(linear) ortrack()(custom). - Add a unit test in
tests/elements/test_my_element.py. - Wire into the parser if it has a TraceWin counterpart
(
linac_gen/io/tracewin_parser.py). - Add a manual chapter (copy a stub from
03_elements/).
Adding a new distribution¶
- Create
linac_gen/distributions/my_dist.py. - Implement
generate(config: BeamConfig, seed) -> ndarray (N, 6). - Register in
linac_gen/distributions/factory.py:_DIST_MAP. - Add to
BeamConfig.distributionvalid-values list. - Add a unit test.
Adding a new diagnostic¶
- Add the field to
DiagnosticRecorder.__init__(). - Append to it inside
DiagnosticRecorder.record(). - Add a manual section in
09_diagnostics/. - Add a Results-tab tile if relevant
(
gui/linac_gen_gui/interphase/tabs/results_tab.py).
Test conventions¶
pytest tests/runs the full suite (~3 minutes).pytest tests/ -m "not slow"skips long-running integration tests.pytest tests/ -m physicsruns only physics benchmarks.- New tests should reuse fixtures from
tests/conftest.pywhere possible. - For new elements / physics: include both a unit test (single element / single physics scenario) AND an integration test (full lattice, end-to-end behaviour).
Building the Windows distribution¶
The Linac_Gen_build/ tree (including BUILD.md, the PyInstaller
spec and the dist\HELIX\HELIX.exe output) lives on the dedicated
Windows build machine — it is not part of this repository. Per
Linac_Gen_build/BUILD.md on that machine:
Always pass --clean for a full rebuild. Output goes to
dist\HELIX\HELIX.exe.
To smoke-test the result:
Expected output:
Adding to this manual¶
- The chapter you want to add either exists as a stub or is covered by an existing chapter.
- To add real content, just rewrite the stub. The build script
(
make_stubs.py) only writes if the existing file is < 1500 bytes — your real content is preserved on re-runs. - Add code blocks as
``python; they're auto-tested byverify_snippets.py`. - Add figures via
regen_plots.py: - Run
mkdocs buildto verify no broken links.
Coding conventions¶
- Line length: 100 chars (configured in
pyproject.toml). - Style: ruff + black.
- Type hints: use them on public APIs;
mypychecks. - Docstrings: NumPy-style for public functions; module-level docstring with physics references where applicable.
- No unnecessary comments — well-named identifiers explain what; comments explain why.
Git workflow¶
- Branch off
main. - Conventional-commit prefixes:
feat:/fix:/docs:/test:/refactor:. - CI runs one workflow (
.github/workflows/docs.yml): a strictmkdocs buildof this manual (plus a non-blocking snippet check). A PR must pass it. - ruff, mypy and pytest are local conventions — run them before pushing; they are not (yet) enforced by CI.