mg7 run_card.toml: editable RunCard representation + scriptable launch/install#23
mg7 run_card.toml: editable RunCard representation + scriptable launch/install#23oliviermattelaer wants to merge 20 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>
| run_card_path = os.path.join("Cards", "grid_run_card.toml") | ||
| try: | ||
| from madgraph.various.banner import RunCardMG7 | ||
| run_card = RunCardMG7(run_card_path) |
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>
…8ffcc # Conflicts: # madgraph/iolibs/template_files/mg7/run_card.toml
Add scan support to the mg7 mode, reusing the existing MadEvent machinery. - run_card.toml: a parameter can be scanned with a quoted "scan:[...]" (or correlated "scanN:[...]") value -- valid TOML, detected via ConfigFile's scan_set and expanded by banner.RunCardIterator. The card editor accepts 'set beam.e_cm scan:[...]' (allow_scan) and writes it back quoted. - param_card.dat: the usual scan:/scan$N: syntax, via ParamCardIterator. - madevent.run_generation() detects a scan in either card (scanning both at once is refused), runs a full generation per point, and writes the summary Events/scan_<run>.txt using the iterators' write_summary. - The summary reports the cross-section (pb) +- MC error and event count per point, plus the mean value of every observable declared in [histograms] (MadgraphProcess.get_result / _histogram_mean). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
I'm critical of the last two commits (1d23fe8 and 65ae188)
|
65ae188 to
645ca29
Compare
|
I have drop them ! Thanks |
Persist the model reference into SubProcesses/model.txt at output time so the runtime can compute widths set to 'auto'. At generation, detect "DECAY <pdg> auto" entries and fill them via `mg5_aMC compute_widths`, writing the result back into the card. Because this runs in run_single(), it applies to a single generation and is recomputed at each scan point; for a param_card scan the computed width is passed to store_entry so it is recorded in the scan summary. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add misc.hash_model_files (md5 over the model's *.py source). The mg7 exporter now writes this hash on a second line of SubProcesses/model.txt, and compute_auto_widths verifies it against the model on disk before computing 'auto' widths, warning if the model changed since output. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
When a param_card has 'auto' widths, the interactive card editor's
do_update('dependent') delegates the computation to the mother interface,
which for mg7 (MG7Cmd) had no do_compute_widths, crashing with
AttributeError. Add one that reuses the runtime compute_auto_widths helper
(mg5_aMC subprocess + the model stored at output) on the param_card path
the editor passes, returning {} so the caller's small-width loop is a
no-op. Scan cards return before this path and are handled per-point at
generation.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks! I had a look at the rest. I think it can be merged |
|
Thanks I have added the auto-width functionality (relying on madevent for three-body decay). Note that this branch also has issue for tt~jj with top decay (added to the hall of fame) |
|
The top decay error seems to be there in all branches, so that's an independent issue. I'll have a look at that |
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