Skip to content

Make denom64 (FPTYPE=v) the default precision, add an mg7 precision check - #497

Merged
oliviermattelaer merged 9 commits into
mainfrom
claude/v-mode-default-stability-d62294
Nov 22, 2026
Merged

oliviermattelaer merged 9 commits into
mainfrom
claude/v-mode-default-stability-d62294

Conversation

@oliviermattelaer

Copy link
Copy Markdown
Contributor

What

  • v (denom64) is the default precision: madmatrix.mk (FPTYPE = v), the mg7 run card (precision = "denom64"), the madevent+madmatrix floating_type, the MadtRex reweighting fallbacks and the docs. MadSpin's density libraries (madmatrix/density.py) stay pinned to m.
  • Object directory is build.<BACKEND>_<FPTYPE> (was build.<BACKEND>). Two FPTYPEs of one backend can now coexist; before, changing [run] precision between two mg7 runs of one output failed with "Cannot build for tag". The .hrflags lookup and the check_sa.exe relink marker follow. Existing outputs keep the old makefile and need regenerating.
  • [run] precision_check (default 0.01, 0 disables), new madgraph/mg7/precision_check.py. A run in a precision other than all64 also builds an FPTYPE=d library of each MadMatrix subprocess (same CPU backend). After the events are written, it evaluates a sample of them (1%, at most 1000; hidden precision_check_max_events) with both libraries at the same momenta, flavour, alpha_s and good helicities, through UMAMI/ctypes, each FPTYPE in its own process. The mean, |M|²-weighted and max relative deviations are logged and written to Events/<run>/precision_check.json, with a warning above precision_check_threshold (1e-3) or on non-finite values. Disabled for all64, gridpack-only runs, cluster jobs and the dummy ME.

Validation (local, macOS arm64)

  • The check's own v evaluation reproduces the |M|² madspace computed during the run bit for bit (lhe_npy incl. mirrored flavours, compact_npy): test_precision_check_reproduces_the_run_mg7.
  • p p > e+ e- j: mean 2e-6, max 1e-5. p p > t t~ j: max 2e-6.
  • Unitary-gauge e+ e- > w+ w- at 100 TeV: 8/200 events above 1e-3 (max 6.7%), warning emitted; |M|²-weighted deviation 3e-7. The automatic FD gauge avoids this.
  • mg7 acceptance tests of acceptancetest_mg7.yml: 86/98 pass; the rest are local environment issues (NLO widths fall back to LO without fastjet/loop libs; simd_consistency imported another madspace build).
  • 52 standalone madmatrix/crossing acceptance tests from acceptancetest.yml: all pass.
  • Unit suite: the local reds are identical to a clean main checkout.

CI impact (what this draft is for)

  • The precision check adds one FPTYPE=d build per mg7 run, about the cost of the v build (p p > t t~ j j, 4 jobs: v 10 s, d 8 s locally). Expect the most effect on check_xsec_processes and acceptancetest_mg7_bundle_2. If too costly there, those jobs can set precision_check = 0.
  • v on CUDA/HIP has never run in GPU CI: the GPU workflows need to be dispatched on this branch.

New tests are registered in unittest.yml (unittest_interface_uncovered) and acceptancetest_mg7.yml (acceptancetest_mg7_bundle_4).

🤖 Generated with Claude Code

oliviermattelaer and others added 2 commits November 19, 2026 23:18
…heck

- madmatrix.mk, the mg7 run card (precision = "denom64"), the madevent
  floating_type and the MadtRex fallbacks now default to v (momenta and
  propagator denominators in FP64, amplitudes and colour in FP32).
  MadSpin's density libraries stay pinned to m.
- The object directory is build.<BACKEND>_<FPTYPE>: two FPTYPEs of one
  backend can coexist, and changing [run] precision between two runs of
  one output no longer fails with "Cannot build for tag".
- [run] precision_check (default 0.01): an mg7 run in a precision other
  than all64 also builds an FPTYPE=d library of each MadMatrix
  subprocess and, once the events are written, evaluates a sample of them
  in both precisions (UMAMI through ctypes, one process per FPTYPE).
  Mean, |M|^2-weighted and max relative deviation are logged and written
  to Events/<run>/precision_check.json; it warns above
  precision_check_threshold (1e-3) or on non-finite values.
- Tests: unit tests for the defaults, the statistics and the event to
  library/flavour mapping; acceptance tests for a real run, the side by
  side builds, a precision change without make clean, and that the check
  reproduces the |M|^2 madspace computed in the run. Registered in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The C-parity scan in the cpu and simd SigmaKin.cc compared mirror helicity
rows with an FP64 tolerance (1e-6 relative, 1e-12 of the largest |M|^2).
With FP32 amplitudes (FPTYPE=f and the new default v) rounding noise
exceeds it, the verdict latched "not C-symmetric" and the dedup was off:
every helicity row evaluated, the mirrored half outside the hel-recycling
table. On g g > t t~ g g (simd_128, 1 thread) v ran at 39.7 us/event
against 23.4 for d.

Under MGONGPU_FPTYPE_FLOAT the test now uses 1e-4 relative and 1e-6 of the
largest |M|^2: v 13.0 us/event, f 12.2, |M|^2 identical to v with the
helicity choice of the d build (v vs d max 8.7e-6). d and m keep the FP64
tolerance. u u~ > e+ e- is still refused the dedup under v; the gpu
backend has no such scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oliviermattelaer

Copy link
Copy Markdown
Contributor Author

C-parity tolerance fix for FP32 builds (6412ea6)

Timing d against v showed v was slower than d. The C-parity helicity check in backend/{cpu,simd}/SigmaKin.cc compared mirror helicity rows with an FP64 tolerance (1e-6 relative, 1e-12 of the largest |M|²). FP32 rounding noise is larger than that, so v and f builds never deduplicated: every helicity row was evaluated, and the mirrored half fell outside the hel-recycling table. When the amplitudes are FP32 (MGONGPU_FPTYPE_FLOAT), the check now uses 1e-4 relative and 1e-6 of the largest |M|². d and m keep the FP64 tolerance. The GPU backend has no such check.

g g > t t~ g g, simd_128, 1 thread, 100k points, each build with its own helicity choice:

Build µs/event C-parity dedup max deviation from d
d 23.4 on –
m 22.7 on 9e-8
v 13.0 (39.7 before) on (was off) 8.7e-6
f 12.2 on 9.7e-4
  • The scalar backend's v build now also keeps the dedup.
  • u u~ > e+ e- (parity-violating through the Z) is still refused under v, same as d.
  • Locally, the 12 hel-recycling, helicity-choice and precision-check acceptance tests from the mg7 CI pass.
  • Caveat: a genuine parity violation below 1e-4 relative would now be deduplicated. That is about the precision of v itself.

End-to-end timing (M5 Pro, 18 cores, 100k events, default card)

Run all64 denom64 + check denom64, no check
p p > e+ e- j 13.6 s 17.1 s 13.3 s
p p > t t~ j j 475 s 548 s 496 s

Measured before the C-parity fix. The check costs the extra all64 build (3–5 s) plus about 1 s of evaluation. On ttjj, MadNIS training takes 450–520 s of each run and varies from run to run, so most of the spread there is noise. Check result on ttjj: mean deviation 6e-7, max 2.8e-5, nothing above 1e-3.

CI status at 6412ea6

84 pass, 1 fail.

  • acceptancetest_mg7_madtrex, test_madtrex_reweights_mlm_events_with_their_stored_matrix_elements: this PR causes it. _check_stored_matrix_elements in madtrex_driver.py warns when the stored |M|² differ from re-evaluated ones by more than rel_tol = 1e-6. That tolerance was sized for the old m default ("about 1e-7 apart at the mixed fptype"). Under v the MLM events differ by up to 1.76e-6 (2 of 32 sampled), so the test catches a false warning. This job passed on d2aa138; the dedup changes the FP32 summation order. Fix: a tolerance that depends on fptype, about 1e-5 when the amplitudes are FP32.

  • CI duration of the mg7 acceptance jobs, PR against the last four main runs:

    • bundle_1: 27–28 min against 16–19 min, on both PR runs. This is probably the extra all64 compile for the precision check in every launch.
    • bundle_2: 34 min, then 50 min, against 26–34 min. That's inconsistent between the two PR runs, so probably runner noise.
    • The xsec jobs are within noise (ttx2j 9.6 min against 9.1 min).

    If the bundle_1 cost matters, the acceptance tests could set precision_check = 0 except for the dedicated test.

  • The GPU CI (v on CUDA/HIP) has not been dispatched.

🤖 Generated with Claude Code

_check_stored_matrix_elements warned when the stored matrix elements
differ from re-evaluated ones by more than 1e-6, sized for the old color32
default (about 1e-7 apart). With FP32 amplitudes (denom64, the new
default, and all32) an MLM run's stored |M|^2 (rescaled to the event's
alpha_s) and the re-evaluation differ by a few 1e-6 (1.76e-6 on CI), so
test_madtrex_reweights_mlm_events_with_their_stored_matrix_elements saw a
false warning. The default tolerance is now 1e-5 for f/v, 1e-6 otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The madspace examples load libmadmatrix_sm_P0_gg_ttxg_scalar_m.so after a
plain 'make BACKEND=scalar', which builds FPTYPE=v now: the docs examples
CI could not load the library. Same in the gridpack build example, whose
FPTYPE has to match the card's precision (denom64 by default).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oliviermattelaer oliviermattelaer added this to the Feature freeze milestone Nov 20, 2026
…-stability-d62294

# Conflicts:
#	madgraph/iolibs/template_files/mg7/madtrex_driver.py
#	madgraph/iolibs/template_files/mg7/run_card.toml
#	madgraph/various/banner.py
@stloufra

Copy link
Copy Markdown
Contributor

Given you want to compile the d and v at the same time, would not it be better to do the helicity choice in FP64 given the last bug? Also, with the compilation, 2x is quite costly thing on GPU (even though it does not really work with GPU rn), especially after #491. Maybe the check can be always done against the "higher" fptype with CPU madmatrix BACKEND=auto (we do not care for speed for the initial check and the reweighting to higher precision that much).

Some other points:
GPU runs skip the check. The loop variable fptype overwrites the run’s FPTYPE with d - the check sees all64 and never runs.
The statistics don’t measure cross-section bias (docstring) - it is the signed mean of (v−d)/d, not the mean of |rel|.
The “weighted” number counts |M|² twice, because unweighted events already follow |M|^2.
Building twice is expensive for higher multiplicities e.g. g g > t tx g g g . What about opt-in?
Is the LHE sample random? - It takes the first N events (what if they come from the same channel)?

Claude also says:
The JSON breaks on bad values e.g. inf.
Unweighted events already follow dσ ∝ PDF·|M|², so the relative cross-section change is the signed mean of r = v/d − 1 over the sample. The "|M|²-weighted" number Σ|v−d|/Σ|d| applies |M|² a second time.

Addresses the review of #497:
- [run] precision_check defaults to 0: the check compiles every
  subprocess a second time (all64); [run] validation (MadtRex) is the
  whole-sample alternative.
- A GPU-only run never ran the check: the build loop reused 'fptype', and
  its last build is the scalar all64 one of the helicity choice, so the
  check saw 'd'. New test test_a_gpu_only_run_checks_its_own_precision.
- Statistics: cross_section_bias is the signed mean of r = v/d - 1 (the
  unweighted events already follow |M|^2); the |M|^2-weighted number,
  which applied |M|^2 twice, is gone. Mean and max of |r| stay.
- LHE output: the events are drawn at random from the whole file
  (reservoir sampling over the raw text, only the kept ones parsed), not
  the first N.
- precision_check.json is strict JSON: non-finite values as strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oliviermattelaer

Copy link
Copy Markdown
Contributor Author

Thanks Frank, all fair points. Addressed in bb90202:

  • Cost / opt-in: agreed. precision_check now defaults to 0, so a default run compiles only once. For a full-sample check there is now [run] validation (MadtRex, from main), which the docs point to.
  • GPU runs skipped the check: confirmed and fixed. The build loop reused fptype, and on a GPU-only run its last build is the scalar d library used for the helicity choice, so the check saw d and turned itself off. The loop variables are renamed, and test_a_gpu_only_run_checks_its_own_precision covers it (it fails on the old code).
  • Statistics: you're right on both. The summary now reports cross_section_bias, the signed mean of r = v/d − 1, since unweighted events already follow |M|². The "|M|²-weighted" number is removed. Mean and max of |r| and the count above threshold stay, to flag unstable regions.
  • LHE sample: now drawn at random from the whole file (reservoir sampling over the raw event text; only the kept events are parsed, seeded by the run seed), instead of the first N.
  • JSON with inf: non-finite values are written as "inf"/"nan" strings, and the file is written with allow_nan=False.

On the helicity choice in FP64: the bug behind it was the C-parity tolerance (6412ea6). The FP64 tolerance rejected FP32 noise, so v turned the dedup off. With the float-aware tolerance, the v build picks the same helicity rows and flags as d on gg→ttgg, and the |M|² matches v evaluated with d's choice. Always choosing in FP64 would bring back the d build on every run. But when the check is on, the d library exists anyway, so choosing on it in that case is cheap. Happy to do that as a follow-up if you think it's worth it.

On comparing against the auto CPU backend: on a GPU-only run the check uses scalar, which reuses the scalar d library already built for the helicity choice, so it adds one build instead of two. On a CPU run it uses the run's own backend.

🤖 Generated with Claude Code

madmatrix.mk: keep the FPTYPE=v default in main's shorter comment style.
launch_plugin.py: take main's deletion (dead cudacpp code, #498).
SigmaKin.cc (cpu, simd): the FP32 C-parity tolerance tests
MADMATRIX_FPTYPE_FLOAT, as main renamed the MGONGPU macros; the old name
no longer exists and would have silently restored the FP64 tolerance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oliviermattelaer
oliviermattelaer marked this pull request as ready for review November 21, 2026 22:05
oliviermattelaer and others added 2 commits November 22, 2026 05:40
- summarize: the mean |r| averages the same events as the cross-section
  bias (finite, non-zero reference); one non-finite event no longer makes
  it inf, it still shows in non_finite, above_threshold and the max.
- compile_precision_check: count the missing libraries by me_path, as the
  main build loop does, for the PCH decision.
- run_card.rst: name [run] validation instead of pointing to an entry
  that is not documented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The FP32 C-parity scan used 1e-4 relative and 1e-6 of the largest |M|^2.
Measured on the scan points (simd_128), the mirror rows of C-symmetric
processes differ by up to 7e-7 of the largest |M|^2 (g g > t t~ g g in f),
1.5x below that cut, so the relative test never acted and one harder point
of a run could latch the dedup off. A genuine parity violation is O(1) on
both measures (0.7 for u u~ > e+ e-, u u~ > z g g).

Both FP32 tolerances are now 1e-5: a pair is flagged only above both, the
cut against the largest |M|^2 ~15x above the roundoff. g g > t t~ g g and
u u~ > t t~ g g (v, f) keep the dedup, u u~ > e+ e- is refused it (simd
and scalar). FP64 builds keep 1e-6 / 1e-12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oliviermattelaer
oliviermattelaer merged commit 5ee4caf into main Nov 22, 2026
93 of 101 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants