Skip to content

mg7 run_card.toml: editable RunCard representation + scriptable launch/install#23

Draft
oliviermattelaer wants to merge 12 commits into
mainfrom
claude/jolly-dhawan-48ffcc
Draft

mg7 run_card.toml: editable RunCard representation + scriptable launch/install#23
oliviermattelaer wants to merge 12 commits into
mainfrom
claude/jolly-dhawan-48ffcc

Conversation

@oliviermattelaer

Copy link
Copy Markdown
Contributor

Summary

Give the default (mg7/madnis) generation mode a proper, editable run_card.toml, matching how the legacy run_card.dat works, and make the surrounding launch/install flow script-friendly.

Organised as four commits:

  1. RunCard-style representation of run_card.toml — new banner.RunCardMG7 (typed params, allowed values, comments, user_set, nested card["section"]["key"] access; free-form [multiparticles]/[cuts]/[histograms]). The card is generated from a placeholder template with process-dependent defaults (create_default_for_process + input/.default_run_card_mg7.toml) instead of copied verbatim, and the runtime consumes the class.
  2. Interactive card editing via set — wire the TOML card into the "edit a card?" question so set edits it like run_card.dat, plus conveniences: set <section>.<key>, cut editing, energy units (→ GeV), arithmetic (+ - * / **), param_card mass refs (mz, mh, …), and shortcuts (no_parton_cut, lhc/lep, fixed_scale).
  3. Non-interactive madspace install — route the installer's prompts through MG5's cmd.ask (falling back to input()), add -f/PYTHONPATH/DEVNULL propagation, and drive generate_events from the scripted card commands after launch so a command-file run no longer hangs on the installer.
  4. Find cmake from HEPTools — before the source build, discover a cmake ≥3.15 (MADGRAPH_CMAKE/CMAKE → system → heptools_install_dir via env/MG5 config → default <MG5>/HEPTools) and put it on the build PATH.

Testing

  • TestRunCardMG7 unit tests (12) + existing banner tests pass via ./tests/test_manager.py.
  • End-to-end output mg7 for p p > t t~ (hadronic defaults) and e+ e- > mu+ mu- (leptonic defaults, jet cuts dropped); produced run_card.toml is valid TOML and process-adjusted.
  • Interactive set/units/shortcuts verified by driving the real ask_edit_card_static flow.
  • Installer prompt force/pipe behaviour and cmake discovery (env var + ~/.mg5 config) verified.

Notes

  • Drafted for review; not yet exercised through a full first-time madspace source build.
  • Parameters are addressed as set <section>.<key> because TOML keys are only unique within a section.

🤖 Generated with Claude Code

oliviermattelaer and others added 8 commits July 1, 2026 02:39
Introduce banner.RunCardMG7, a typed representation of the TOML run_card
used by the default (mg7/madnis) generation mode, built on the existing
ConfigFile/RunCard machinery (typed params, allowed values, comments,
user_set tracking, set()).

- Section-aware flat storage with nested card["section"]["key"] access;
  free-form [multiparticles]/[cuts]/[histograms] kept as nested dicts.
- read()/write() overridden for TOML; write() renders from a placeholder
  template (template_files/mg7/run_card.toml, now converted to %(section.key)s
  placeholders + $multiparticles/$cuts/$histograms markers).
- create_default_for_process() fills process-dependent defaults (beam,
  multiparticles, cuts), then reads input/default_run_card_mg7.toml, mirroring
  the LO run_card logic. New hidden site-default input/.default_run_card_mg7.toml
  is copied at config time.
- RunCard.__new__ dispatches TOML input to RunCardMG7.
- The mg7 exporter (export_cpp.ProcessExporterMG7 / madmatrix) now generates
  Cards/run_card.toml (and run_card_default.toml) from the template with those
  defaults instead of copying the file verbatim.
- The runtime (madevent.py load_cards, gridpack.py) consumes the class.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Wire the TOML run_card into the "Do you want to edit a card?" question so the
set command edits it just like the legacy run_card.dat, and add madevent-style
conveniences.

- common_run_interface: get_path recognizes *_card.toml; update_dependent skips
  its beam-dependent block when the run_card has no lpp1 (i.e. for RunCardMG7),
  so the generic editor works with the TOML card.
- mg7 ask_edit_cards: point run_default at run_card_default.toml (enables
  "set <param> default") and drop the reload no-op so edits persist.
- set command support (handled in RunCardMG7 + the mg7 do_set hook):
    * set <section>.<key> value for the fixed parameters;
    * cut editing: set <group>-<obs>.<min|max> value;
    * energy units (eV/keV/MeV/GeV/TeV/PeV) converted to GeV for energies/cuts;
    * arithmetic (+ - * / **) and param_card mass references (mz, mh, mt, ...);
    * shortcuts: no_parton_cut, lhc/lep/ilc/lcc, fixed_scale.
  Integer/float k/M suffixes keep working (same ConfigFile.format_variable).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The one-off madspace installer used raw input(), so a scripted run
(./bin/mg5_aMC <file>, piped stdin, or -f) would hang on its prompts.

- madspace/install.py: route ask_yes_no/ask_string/the compile-option and
  build-type menus through MG5's cmd.ask when madgraph is importable (falling
  back to input()), so non-interactive runs take the defaults without blocking;
  add a -f/--force flag.
- mg7 madevent.py: launch the installer with madgraph on PYTHONPATH (so it can
  import cmd.ask), pass -f and stdin=DEVNULL when the parent run is
  non-interactive, so it never consumes the run's scripted card commands.
- do_launch (mg7): when MG5 runs non-interactively, drive bin/generate_events
  from the card-editing lines that follow `launch`, piping them on stdin. This
  makes the subprocess non-interactive (installer takes defaults) and delivers
  the scripted `set` commands to the run_card editor.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…missing

The source build (scikit-build-core) needs cmake >= 3.15 on PATH and fails with
CMakeNotFoundError when the system has none (or too old a version).

Discover a suitable cmake before the build and put it on the build env's PATH,
checking in order: a MADGRAPH_CMAKE/CMAKE override, the system cmake (skipped if
too old), then a cmake installed through MadGraph's HEPTools installer
(<heptools>/cmake/bin/cmake). The HEPTools location is a configurable MG5 option
(heptools_install_dir) that may point outside MG5DIR, so it is resolved from:
MADGRAPH_HEPTOOLS_DIR (exported by do_launch), then the MG5 configuration files
(~/.mg5, XDG, <MG5>/input/mg5_configuration.txt) for direct invocations, then
the default <MG5>/HEPTools. If no cmake is found, print a hint pointing at
'install cmake' / MADGRAPH_CMAKE instead of failing deep inside pip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Ensure the interactive editor always has the TOML run_card loaded as a
RunCardMG7, independently of whether the generic AskforEditCard.get_path
recognised run_card.toml. Previously, if init_run left self.run_card as {}
(older common_run_interface not recognising the .toml card, an unexpected
me_dir, ...), every "set <param> ..." was rejected with "invalid set command".

Override init_run in the mg7 ask_edit_cards patch to load
Cards/run_card.toml directly when self.run_card is not already a RunCardMG7.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
run_card_path = os.path.join("Cards", "grid_run_card.toml")
try:
from madgraph.various.banner import RunCardMG7
run_card = RunCardMG7(run_card_path)

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.

This never happens because madgraph is not added to the path. Do we want to keep it or just always use the tomllib one to be completely independent of the main MG code?

@Qubitol Qubitol added this to the Alpha release milestone Jul 1, 2026
@oliviermattelaer oliviermattelaer mentioned this pull request Jul 1, 2026
6 tasks
oliviermattelaer and others added 3 commits July 1, 2026 18:07
If the PDF set named in the run_card is not available, download it on the fly
using MG5's install_lhapdf_pdfset_static, instead of crashing in init_beam.

- do_launch resolves the PDF data directory following: $LHAPDF_DATA_PATH, then
  the configured lhapdf data dir (e.g. lhapdf6 in HEPTools), then a local
  writable directory; it also forwards the lhapdf-config path as
  MADGRAPH_LHAPDF_CONFIG so the run can fetch sets.
- madevent.ensure_pdf_set() downloads the set into that directory (only when
  missing) and points PDF_PATH at it so madspace can load it. This runs for the
  final pdf choice, after any card editing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add RunCardMG7.from_LO(runcardlo) which reproduces, as far as possible, a legacy
LO run_card in the TOML run_card, for cross-checking the same setup in both and
for a retro-compatible mode.

Ports the directly-mappable / convertible settings (see the analysis in
madgraph/various/RunCardLO_to_MG7_mapping.md):
- beams: ebeam1/2 -> e_cm, lpp -> leptonic;
- pdf: pdlabel/lhaid -> pdf (known labels/ids);
- scales: fixed_ren_scale, scale -> ren_scale, dsqrt_q2fact1/2 -> fact_scale1/2,
  fixed_fac_scale, dynamical_scale_choice (int -> string);
- generation: nevents -> events, gridpack, bwcutoff, SDE_strategy,
  maxjetflavor -> jet multiparticle, use_syst -> systematics;
- cuts: pt/eta/deltaR/mass/sqrt_s for jet/bottom/lepton/photon/missing.

Everything that has no MG7 equivalent (merging, bias, polarization, heavy ion,
HT/energy/ordered/per-pdg cuts, helicity, ...) is collected and returned (and
warned) as a "could not transfer" list, so the conversion is transparent.

Includes the pre-implementation feasibility analysis and a unit test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
-f/--force only forced non-interactive prompting; -y/--yes already does that.
Their only real difference was the install mode (-f always source, -y from
saved/bin). Make --bin/--source take precedence over --yes when choosing the
mode, remove -f/--force, and have the mg7 auto-installer request a
non-interactive source build with defaults via "--source --yes".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.

3 participants