Skip to content

New MAD-X Parser#1295

Merged
ax3l merged 54 commits into
BLAST-ImpactX:developmentfrom
ax3l:new-madx-parser
Apr 19, 2026
Merged

New MAD-X Parser#1295
ax3l merged 54 commits into
BLAST-ImpactX:developmentfrom
ax3l:new-madx-parser

Conversation

@ax3l
Copy link
Copy Markdown
Member

@ax3l ax3l commented Feb 5, 2026

Summary

This PR overhauls two files:

  • MADXParser.py: a tokenizer and parser that tries to truthfully reimplement the MAD-X C parser, ultimately returning a flattened MAD-X lattice. This file is best written with a powerful LLM (mostly Claude 4.6 was used). It is covered by unit tests for central MAD-X input language features and should not require much updates in the future.
  • madx_to_impactx.py: the actual translator from MAD-X element to ImpactX element(s). This file we need to be able to maintain "by hand" as we add new elements and handle physics translation corner-cases.

To Do

@ax3l ax3l requested review from cemitch99 and egstern February 5, 2026 23:15
@ax3l ax3l added changes input scripts / defaults Changes the syntax or meaning of input scripts and/or defaults component: python Python bindings labels Feb 5, 2026
@ax3l ax3l added this to the Advanced Methods (SciDAC-5) milestone Feb 5, 2026
@ax3l ax3l force-pushed the new-madx-parser branch from 324f69a to 6713e2a Compare March 25, 2026 18:02
Comment thread src/python/impactx/MADXParser.py Fixed
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 25, 2026

Merging this PR will not alter performance

✅ 37 untouched benchmarks


Comparing ax3l:new-madx-parser (a1ac04c) with development (de02c77)

Open in CodSpeed

@ax3l
Copy link
Copy Markdown
Member Author

ax3l commented Apr 8, 2026

@cemitch99 I added the warning to load_file to make sure people know its status:
https://impactx--1295.org.readthedocs.build/en/1295/usage/python.html#impactx.elements.KnownElementsList.load_file

@ax3l ax3l force-pushed the new-madx-parser branch from 4cf6d0a to 49db4b4 Compare April 8, 2026 06:54
@ax3l
Copy link
Copy Markdown
Member Author

ax3l commented Apr 9, 2026

Discussed today: will also add a runtime warning when load_file is used.

@ax3l ax3l added the component: lattice file parser parsing and loading of lattice file formats label Apr 10, 2026
@ax3l
Copy link
Copy Markdown
Member Author

ax3l commented Apr 10, 2026

@cemitch99 I added runtime warnings when load_file is used:

...
examples/chicane/run_chicane_madx.py:28: RuntimeWarning: Our MAD-X parser is under active development and provided as a preview. Please check any loaded MAD-X beams very carefully. Please report your experience and bugs on our issue tracker: https://github.com/BLAST-ImpactX/impactx/issues
ref = sim.particle_container().ref_particle().load_file("chicane.madx")

...

examples/chicane/run_chicane_madx.py:45: RuntimeWarning: Our MAD-X and PALS parsers are under active development and provided as a preview. Please check any loaded lattice files very carefully. Please report your experience and bugs on our issue tracker: https://github.com/BLAST-ImpactX/impactx/issues
sim.lattice.load_file("chicane.madx", nslice=25)
...

@ax3l ax3l force-pushed the new-madx-parser branch from ed55b08 to 1c3bd66 Compare April 10, 2026 05:51
@ax3l ax3l requested a review from cemitch99 April 16, 2026 21:51
@ax3l
Copy link
Copy Markdown
Member Author

ax3l commented Apr 19, 2026

Discussed in last two week's developer meeting: approved & ready for merge :)

Will remove the one little merge conflict in run_solenoid.py that came up.

@ax3l ax3l enabled auto-merge (squash) April 19, 2026 06:54
@ax3l ax3l disabled auto-merge April 19, 2026 06:56
@ax3l ax3l force-pushed the new-madx-parser branch 2 times, most recently from 351b443 to 0f97793 Compare April 19, 2026 10:03
@ax3l ax3l mentioned this pull request Apr 19, 2026
@ax3l ax3l force-pushed the new-madx-parser branch from 0f97793 to 6250f6e Compare April 19, 2026 10:29
Comment thread src/python/impactx/madx_to_impactx.py Fixed
@ax3l ax3l force-pushed the new-madx-parser branch from 6250f6e to 8ca165d Compare April 19, 2026 11:04
@ax3l ax3l force-pushed the new-madx-parser branch from 8ca165d to c04c169 Compare April 19, 2026 16:18
ax3l added 3 commits April 19, 2026 09:54
E.g., the FNAL booster files
ion_proton et al.

  - Official MAD-X PARTICLE= species are covered explicitly: positron, electron, proton,
    antiproton, posmuon, negmuon, ion.
  - Fixed the muon mass calculation.
  - Matched ION to the MAD-X source behavior, with an inline comment.
  - read_beam() now passes explicit MAD-X MASS and CHARGE through, so unknown community
    particle names can still work if the beam is fully specified.
@ax3l ax3l force-pushed the new-madx-parser branch from 5729be6 to a1ac04c Compare April 19, 2026 17:18
@ax3l ax3l merged commit 7683eb2 into BLAST-ImpactX:development Apr 19, 2026
18 checks passed
@ax3l ax3l deleted the new-madx-parser branch April 19, 2026 20:12
@ax3l
Copy link
Copy Markdown
Member Author

ax3l commented Apr 20, 2026

The pyi stub generator shows some bug after this merge, I'll fix that upstream in the next day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes input scripts / defaults Changes the syntax or meaning of input scripts and/or defaults component: lattice file parser parsing and loading of lattice file formats component: python Python bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAD-X Reader: RBEND MAD-X: Call, FILENAME Support MAD-X input reader: constants, elements, lines, segments

3 participants