mg7 run_card.toml: editable RunCard representation + scriptable launch/install#23
Draft
oliviermattelaer wants to merge 12 commits into
Draft
mg7 run_card.toml: editable RunCard representation + scriptable launch/install#23oliviermattelaer wants to merge 12 commits into
oliviermattelaer wants to merge 12 commits into
Conversation
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>
theoheimel
reviewed
Jul 1, 2026
| run_card_path = os.path.join("Cards", "grid_run_card.toml") | ||
| try: | ||
| from madgraph.various.banner import RunCardMG7 | ||
| run_card = RunCardMG7(run_card_path) |
Contributor
There was a problem hiding this comment.
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?
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>
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.
Summary
Give the default (mg7/madnis) generation mode a proper, editable
run_card.toml, matching how the legacyrun_card.datworks, and make the surrounding launch/install flow script-friendly.Organised as four commits:
run_card.toml— newbanner.RunCardMG7(typed params, allowed values, comments,user_set, nestedcard["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.set— wire the TOML card into the "edit a card?" question sosetedits it likerun_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).cmd.ask(falling back toinput()), add-f/PYTHONPATH/DEVNULL propagation, and drivegenerate_eventsfrom the scripted card commands afterlaunchso a command-file run no longer hangs on the installer.MADGRAPH_CMAKE/CMAKE→ system →heptools_install_dirvia env/MG5 config → default<MG5>/HEPTools) and put it on the build PATH.Testing
TestRunCardMG7unit tests (12) + existing banner tests pass via./tests/test_manager.py.output mg7forp p > t t~(hadronic defaults) ande+ e- > mu+ mu-(leptonic defaults, jet cuts dropped); producedrun_card.tomlis valid TOML and process-adjusted.set/units/shortcuts verified by driving the realask_edit_card_staticflow.~/.mg5config) verified.Notes
set <section>.<key>because TOML keys are only unique within a section.🤖 Generated with Claude Code