From madgraph
Use when the user works with MadGraph (MG5_aMC@NLO) — writing or editing MG5 scripts (`.mg5`), generating Feynman diagrams, running LO event generation, or extracting a cross section from a completed MG run. Trigger keywords include "MadGraph", "mg5_aMC", "MG5_aMC@NLO", ".mg5 script", "proc_card.dat", "run_card.dat", "param_card.dat", "generate p p >", "import model", or requests to produce `.lhe` events for collider physics processes.
How this skill is triggered — by the user, by Claude, or both
Slash command
/madgraph:madgraphThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Helps author a single MG5 script, run LO or fixed-order NLO event generation non-interactively, and read off cross sections (including scale-variation envelopes for NLO).
examples/LO_example.mdexamples/NLO_example.mdreferences/diagrams.mdreferences/install.mdreferences/models.mdreferences/output-and-launch.mdreferences/param-card.mdreferences/run-card.mdreferences/script-syntax.mdreferences/setup.mdreferences/troubleshooting.mdscripts/detect_mg.pyscripts/make_diagrams.pyscripts/run_mg.pyscripts/runs.pyHelps author a single MG5 script, run LO or fixed-order NLO event generation non-interactively, and read off cross sections (including scale-variation envelopes for NLO).
Validated version: MG 3.5.15 LTS. Patch-level 3.5.x should work; see README.md for compatibility caveats on other releases.
Scope:
[noborn=QCD]), fixed-order NLO QCD ([QCD], [real=QCD], [virt=QCD]), SM + arbitrary UFO BSM models, script authoring, non-interactive execution, cross-section extraction from banner (LO) and summary.txt (NLO) including scale envelope.[QED], [QCD QED]) — requires a loop_qcd_qed_sm-style UFO not bundled in LTS; syntax works, model ships separately.fixed_order=OFF with shower=PYTHIA8/HERWIG), multi-jet merging (MLM/FxFx/UNLOPS), MadSpin-at-NLO decay chain insertion, parsing LHE/HepMC event files, detector-level analysis. If the user asks for these, say so and stop — do not improvise. examples/NLO_example.md describes the deferred items explicitly.A single LO run emits 10k–100k lines of output. Keeping that out of the context window is non-negotiable.
mg5_aMC, bin/generate_events, or MG Python modules directly through Bash. Always go through scripts/run_mg.py. The wrapper redirects all stdout/stderr to a log file on disk and emits a ~20-line structured summary.Read, cat, head, or tail the MG log file in full. Log is typically 10k+ lines. To inspect, use Grep with a narrow pattern against the log_path returned by the wrapper, e.g. Grep(pattern="ERROR|Fatal|Traceback", path=log_path, -C=2, head_limit=30).scripts/runs.py, which only reads the small banner and results files.detect_mg.py output for the session. Call it once per conversation; reuse the result.Violating any of the above is treated as a bug — back out and use the wrappers.
.mg5 scriptEvery run is driven by one MG5 script file. This is the single source of truth — the exact bytes MG consumes. It contains import model, define, the process (generate/add process), output (for the first run creating the process directory), launch, any set <key> <value> lines, and the trailing 0 to answer MG's "any more edits?" prompt.
Two script shapes per process:
import model → define → generate → output madevent <work_dir> → launch <work_dir> → set … → 0.outputed directory. Shape: launch <work_dir> → set … → 0. No generate/output.detect_mg.py → pick/write .mg5 script → run_mg.py → runs.py
Run scripts/detect_mg.py. It reports MG root, version, toolchain, and which extensions (pythia8, lhapdf6, delphes) are installed. If MG is not found, point the user at references/install.md (how to install MG) and references/setup.md (how the skill finds it). Then stop.
.mg5 scriptDo not write from scratch. Read examples/LO_example.md — it is organized as:
new and rerun) with <SLOTS> marked explicitly (<MODEL>, <PROCESS>, <WORK_DIR>, <SET_BLOCK>).set presets, common cuts.loop_sm + [noborn=QCD]), BSM/UFO (import + display introspection).Workflow: copy the new (or rerun) template → substitute every <SLOT> → run. Any unsubstituted <…> placeholder is a bug; run_mg.py refuses to execute a script that still contains them.
Copy-paste is the idiom — MG's script language has no native include.
Details on individual pieces: references/script-syntax.md, references/models.md, references/run-card.md, references/param-card.md.
scripts/run_mg.py --script path/to/my_run.mg5 [--timeout 3600]
The wrapper returns a compact JSON summary — the full log stays on disk:
{
"status": "ok",
"order": "LO",
"xsec_pb": 507.3,
"xsec_err_pb": 0.8,
"nevents": 10000,
"run_dir": "mg_work/ttbar/Events/run_02",
"script_archive": "mg_work/ttbar/Events/run_02/inputs/script.mg5",
"log_path": "mg_work/ttbar/mg_run.log",
"log_size_lines": 24813,
"duration_s": 142,
"errors_tail": [],
"warnings_count": 3
}
Single run:
scripts/runs.py --run-dir mg_work/ttbar/Events/run_02
All runs in a work dir, with script-level diff:
scripts/runs.py --work-dir mg_work/ttbar
scripts/runs.py --work-dir mg_work/ttbar --runs run_01,run_02,run_03
scripts/runs.py --work-dir mg_work/ttbar --diff-vs baseline
scripts/runs.py --work-dir mg_work/ttbar --diff-vs both
Returns xsec_pb, xsec_err_pb, nevents, run_tag, seed per run. Multi-run mode also reports per-run set_diff (plus model_changed / process_changed when applicable). Reads only small files — never the .lhe(.gz).
Diff modes (--diff-vs):
| value | meaning | use when |
|---|---|---|
previous (default) | Each run diffed against the one immediately before it (step-by-step delta). | "What did I change in this iteration?" — the common case. |
baseline | Each run diffed against run_01 (cumulative drift from the first). | "How far has my setup drifted from the baseline?" |
both | Include both diff_vs_previous and diff_vs_baseline per run. | Debugging or reviewing an experiment series. |
Output key: each non-baseline run carries diff_vs_previous and/or diff_vs_baseline, each containing {against_run, set_diff, optional model_changed / process_changed}. An empty set_diff means the two scripts were identical for that comparison.
To sweep parameters on an already-generated process:
.mg5 block from examples/LO_example.md into a new file.set nevents, set ebeam1, etc.run_mg.py --script my_run.mg5 — work dir is read from the script's launch <dir> line; MG auto-increments to run_02, run_03, …diff mg_work/ttbar/Events/run_0{1,2}/inputs/script.mg5.Each run's exact script is archived at Events/run_XX/inputs/script.mg5 alongside run_manifest.yaml. The archive is the authoritative record — the user's working copy can be anywhere.
./mg_work/<proc_name>/. MG output trees (hundreds of MB) live here, never in repo root. Add mg_work/ to .gitignore.<work_dir>/Events/run_XX/inputs/script.mg5 (exact script used) + run_manifest.yaml (mg version, source path + sha256, cli args, result). Written by run_mg.py automatically.run_XX directory is created, archive goes to <work_dir>/failed_runs/<timestamp>/ with the script and log..mg5: no enforced location. Users may keep scripts under mg_work/<proc>/scripts/, in a personal repo, or anywhere. The archive covers reproducibility.new block in examples/LO_example.md → diff-edit → run.rerun block in examples/LO_example.md, edit set lines only.references/models.md + the BSM block in examples/LO_example.md. Import the model, then use display particles / display multiparticles / display couplings before writing the process — do not guess particle labels.g g > h): use loop_sm model and append [noborn=QCD] to the process line — still a LO observable. See the loop-induced block in examples/LO_example.md.p p > X [QCD], parton level, no PS matching): requires loop_sm (or another loop-capable model). Use the nlo shortcut or explicit fixed_order=ON shower=OFF in the launch block. See examples/NLO_example.md. Xsec + err + scale envelope come from Events/run_XX/summary.txt (runs.py handles this automatically).scripts/runs.py --work-dir <path> --diff-vs baseline. Each run carries order: LO or order: NLO in its entry.examples/NLO_example.md "Not covered" section, tell the user, stop.set <key> scan:[v1, v2, ...] syntax. See scan:[...] in references/script-syntax.md. One run_mg.py invocation creates multiple run_NN directories (mode: multi_run_scan); follow up with scripts/runs.py --work-dir <path> --diff-vs baseline — each run carries a scan_values field with its actual scan-point coordinates. Does not work for run_card keys (nevents, ebeam, cuts, etc.) — sweep those by hand.errors_tail from the run summary. Then references/troubleshooting.md. Only then Grep log_path with a narrow pattern.references/diagrams.md. Different .mg5 shape (no launch) and uses scripts/make_diagrams.py.references/install.md — installing MG + optional extensions (one-time system setup).references/setup.md — how the skill finds an installed MG (MG5_HOME, detection order), work-dir convention, skill smoke test.references/script-syntax.md — .mg5 script structure: import/define/generate/add process/output/launch/set/0, amplitude/squared-amplitude coupling orders.references/models.md — built-in + UFO models, introspection commands.references/run-card.md — run_card.dat keys accessible via set.references/param-card.md — masses, widths, couplings, compute_widths.references/output-and-launch.md — output modes, launch options, shower/detector notes.references/troubleshooting.md — MG error messages → cause/fix.references/diagrams.md — Feynman-diagram PDFs workflow (load only when user asks for diagrams).examples/LO_example.md — templated .mg5 shapes + value catalog + concrete snippets for non-obvious patterns + one ttbar worked walkthrough. This is where .mg5 starter content lives.examples/NLO_example.md — fixed-order NLO QCD: shape templates, value catalog, LHC13/14 NLO presets, K-factor workflow, tested DY walkthrough, and explicit "Not covered" list (MC@NLO, FxFx, NLO EW, etc.).All scripts are uv run single-file (PEP-723 inline metadata) — no separate venv needed.
scripts/detect_mg.py — locate MG, report version + extensions.scripts/run_mg.py — non-interactive MG driver; log → disk, summary → stdout, archive + manifest per run.scripts/runs.py — read xsec ± err + event count from one run (--run-dir), or compare all runs under a work dir with set-level diff (--work-dir). Reads banner + manifest only; never LHE.scripts/make_diagrams.py — generate Feynman-diagram PDFs. When the user asks for diagrams (not events/xsec), see references/diagrams.md for the specialized .mg5 shape and usage.Provides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.
Fetches up-to-date documentation from Context7 for libraries and frameworks like React, Next.js, Prisma. Use for setup questions, API references, and code examples.
npx claudepluginhub jinheungkim1216/madgraph-skill --plugin madgraph