Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/acceptancetest_mg7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,17 @@ jobs:
done
gh run cancel "$RUN_ID" --repo "$REPO" || true

# ---- acceptancetest_mg7_precision_check ----
# The default precision denom64 (FPTYPE=v) and [run] precision_check: a
# fraction of the events evaluated again with an all64 (FPTYPE=d) build,
# the two built side by side; the check reproduces the |M|^2 of the run.
# Needs the madspace + LHAPDF(NNPDF23) stack.
- name: "acceptancetest_mg7_precision_check"
if: ${{ !cancelled() }}
run: |
cd $GITHUB_WORKSPACE
./tests/test_manager.py test_precision_check_mg7 test_precision_check_reproduces_the_run_mg7 -pA -t0 -l INFO

acceptancetest_mg7_madtrex:
needs: build_madspace
# MadtRex (madtrex/, 'install madtrex'): built on top of the cached madspace
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ jobs:
if: ${{ !cancelled() }}
run: |
cd $GITHUB_WORKSPACE
./tests/test_manager.py test_default_switch test_history_recording test_interference_syntax test_mg7_systematics_summary test_reweight_card_input test_tutorials TestNoFileOutsideOutputDir CheckDisplayWithoutProcessTest DisplayInertCouplingOrderTest NeglectedMassAdviceTest RequiredSChannelErrorTest TestHepToolsInstallTarget test_display_processes TestDelphesFusion TestLhapdfInfoPatch TestSharedPdfsetsDir test_generate_propagator_only_polarisation test_propagator_polarisation_round_trip test_dynamical_scale_choice_ht TestAutomaticGauge TestAutomaticGaugeOutput TestProcessGauge TestProcessGaugeOutput TestProcCardOneGauge TestGaugeHelpers test_save_and_load_processes_are_refused -e TestOneImplementation -e TestRealRunNumbers -t0
./tests/test_manager.py test_default_switch test_history_recording test_interference_syntax test_mg7_systematics_summary TestPrecisionDefault TestSummarize TestFlavorTable test_reweight_card_input test_tutorials TestNoFileOutsideOutputDir CheckDisplayWithoutProcessTest DisplayInertCouplingOrderTest NeglectedMassAdviceTest RequiredSChannelErrorTest TestHepToolsInstallTarget test_display_processes TestDelphesFusion TestLhapdfInfoPatch TestSharedPdfsetsDir test_generate_propagator_only_polarisation test_propagator_polarisation_round_trip test_dynamical_scale_choice_ht TestAutomaticGauge TestAutomaticGaugeOutput TestProcessGauge TestProcessGaugeOutput TestProcCardOneGauge TestGaugeHelpers test_save_and_load_processes_are_refused -e TestOneImplementation -e TestRealRunNumbers -t0

- name: "unittest_iolibs_uncovered"
if: ${{ !cancelled() }}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/gridpacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Matrix elements
.. code-block:: bash

cd SubProcesses
make -j8 BACKEND=simd_128 FPTYPE=m USEBUILDDIR=1
make -j8 BACKEND=simd_128 FPTYPE=v USEBUILDDIR=1

``BACKEND`` is the ``cpu_mode`` in ``Cards/grid_run_card.toml`` for a ``cpu`` device, and
``cuda`` or ``hip`` for a GPU. ``FPTYPE`` follows the ``precision`` of the card:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/madspace/examples/flow-training.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The mapping, cuts, matrix element, PDF and scale are exactly the same building b
mapping = ms.PhaseSpaceMapping(masses, E_CM, mode="propagator", cuts=cuts)

proc_dir = "PROC_ggttg"
me_path = os.path.join(proc_dir, "lib", "libmadmatrix_sm_P0_gg_ttxg_scalar_m.so")
me_path = os.path.join(proc_dir, "lib", "libmadmatrix_sm_P0_gg_ttxg_scalar_v.so")
param_card = os.path.join(proc_dir, "Cards", "param_card.dat")

ctx = ms.default_context()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/madspace/examples/integrator-madnis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ random numbers are now PyTorch tensors, since MadNIS trains with PyTorch:
mapping = ms.PhaseSpaceMapping(masses, E_CM, mode="propagator", cuts=cuts)

proc_dir = "PROC_ggttg"
me_path = os.path.join(proc_dir, "lib", "libmadmatrix_sm_P0_gg_ttxg_scalar_m.so")
me_path = os.path.join(proc_dir, "lib", "libmadmatrix_sm_P0_gg_ttxg_scalar_v.so")
param_card = os.path.join(proc_dir, "Cards", "param_card.dat")

ctx = ms.default_context()
Expand Down
2 changes: 1 addition & 1 deletion docs/source/madspace/examples/integrator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ examples, generated with ``output mg7 PROC_ggttg`` and ``make BACKEND=scalar`` b
.. code-block:: python

proc_dir = "PROC_ggttg"
me_path = os.path.join(proc_dir, "lib", "libmadmatrix_sm_P0_gg_ttxg_scalar_m.so")
me_path = os.path.join(proc_dir, "lib", "libmadmatrix_sm_P0_gg_ttxg_scalar_v.so")
param_card = os.path.join(proc_dir, "Cards", "param_card.dat")

ctx = ms.default_context()
Expand Down
4 changes: 2 additions & 2 deletions docs/source/madspace/examples/matrix-element.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Loading the matrix element
import madspace as ms

proc_dir = "PROC_ggttg"
me_path = os.path.join(proc_dir, "lib", "libmadmatrix_sm_P0_gg_ttxg_scalar_m.so")
me_path = os.path.join(proc_dir, "lib", "libmadmatrix_sm_P0_gg_ttxg_scalar_v.so")
param_card = os.path.join(proc_dir, "Cards", "param_card.dat")

ctx = ms.default_context()
Expand All @@ -47,7 +47,7 @@ Loading the matrix element
The library name also appears, alongside every other subprocess of the process, in
``PROC_ggttg/SubProcesses/subprocesses.json``, as ``me_path`` with a ``{device}`` placeholder
for the backend and an ``{fptype}`` placeholder for the floating-point precision the library
was compiled with (``FPTYPE``, ``m`` by default). The model name (``sm``) is part of the
was compiled with (``FPTYPE``, ``v`` by default). The model name (``sm``) is part of the
library name too.

:py:meth:`Context.load_matrix_element <madspace.Context.load_matrix_element>` returns a
Expand Down
20 changes: 17 additions & 3 deletions docs/source/run_card.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,25 @@ fixed parameters. Their entries are described below.
``auto`` picks ``simd_512``, then ``simd_256`` on x86. On ARM it picks ``scalar``,
because the vectorized mode is currently slower there.

``precision`` (``"color32"``)
``precision`` (``"denom64"``)
Floating-point precision of the matrix elements. ``all64`` and ``all32`` use double and
single precision throughout. ``color32`` evaluates the color algebra in single precision
and everything else in double precision. ``denom64`` keeps the momenta and propagator
denominators in double precision and uses single precision elsewhere.
and everything else in double precision. ``denom64``, the default, keeps the momenta and
propagator denominators in double precision and uses single precision elsewhere.

``precision_check`` (``0``)
Fraction of the events evaluated again with the matrix elements in ``all64``, to check
the precision of a run in any other precision. Off by default, because the run then
also builds an ``all64`` CPU library of each subprocess (``[run] validation``
reweights the whole sample through MadtRex instead). Once the events are written, the
two are compared at the momenta of events drawn at random from the output (at most
1000 of them, hidden entry ``precision_check_max_events``). With
``r = |M|^2 / |M|^2_all64 - 1`` per event, the mean of ``r`` (the relative change of the
cross section, since unweighted events already follow ``|M|^2``), the mean and the
maximum of ``|r|`` are logged and written to ``Events/<run>/precision_check.json``; the
run warns when an event deviates by more than ``1e-3`` (hidden entry
``precision_check_threshold``) or is not finite, in which case ``all64`` or ``color32``
is the safer choice for that process.


``cpu_thread_pool_size`` (``-1``), ``gpu_thread_pool_size`` (``1``), ``combine_thread_pool_size`` (``-1``)
Expand Down
8 changes: 4 additions & 4 deletions docs/source/standalone.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In a ``P1_*`` directory, ``make`` builds the process library and ``check_sa.exe`
Two variables select the build; they are part of the library name, so several
builds coexist::

make BACKEND=auto FPTYPE=m # the defaults
make BACKEND=auto FPTYPE=v # the defaults
make BACKEND=simd_256 FPTYPE=d -j8

``BACKEND``
Expand All @@ -30,9 +30,9 @@ builds coexist::
on Apple silicon). The resolved choice is written to ``.resolved-backend``.

``FPTYPE``
``d`` (double precision everywhere), ``f`` (single), ``m`` (the default:
amplitudes in double precision, colour algebra in single precision), ``v``
(single-precision amplitudes with double-precision momenta and denominators),
``d`` (double precision everywhere), ``f`` (single), ``m`` (amplitudes in
double precision, colour algebra in single precision), ``v`` (the default:
single-precision amplitudes with double-precision momenta and denominators),
``e`` (double-word expansion). Compare them with ``check precision``.

The flags are ``-O3 -std=c++20 -ffast-math`` (``OPTFLAGS`` for the optimisation
Expand Down
18 changes: 17 additions & 1 deletion madgraph/iolibs/template_files/madmatrix/backend/cpu/SigmaKin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,23 @@ namespace madmatrix
// dedup. A row that far below the largest cannot bias the helicity sum
// whichever way it is paired, while a genuine parity violation shows up
// at the relative level. One verdict for every crossing.
// FP32 amplitudes (FPTYPE=f and the default v) round at ~1e-7 per
// operation: an FP64 tolerance there switches the dedup off (all ncomb
// rows evaluated, the mirrored half outside the hel-recycling table: v
// ran 1.7x slower than d on g g > t t~ g g). Measured on the scan
// points (simd_128, FP32), the mirror rows of C-symmetric processes
// differ by up to 7e-7 of the largest |M|^2 and 1.3e-5 of the pair
// (g g > t t~ g g (g), u u~ > t t~ g g), a genuine parity violation by
// O(1) on both (0.7 for u u~ > e+ e-, u u~ > z g g). A pair is flagged
// only above both FP32 tolerances (1e-5): the cut against the largest
// |M|^2 stays ~15x above the roundoff (as the verdict latches, one
// harder point of the run must not switch the dedup off).
{
#if defined MADMATRIX_FPTYPE_FLOAT
const fptype csymRel = (fptype)1e-5, csymAbs = (fptype)1e-5;
#else
const fptype csymRel = (fptype)1e-6, csymAbs = (fptype)1e-12;
#endif
fptype mmax = (fptype)0.;
for( int h = 0; h < ncomb; h++ )
for( int ie = 0; ie < neppV; ++ie )
Expand All @@ -1331,7 +1347,7 @@ namespace madmatrix
if( d < (fptype)0. ) d = -d;
const fptype aa = a < (fptype)0. ? -a : a;
const fptype bb = b < (fptype)0. ? -b : b;
if( d > (fptype)1e-6 * ( aa + bb ) && d > (fptype)1e-12 * mmax )
if( d > csymRel * ( aa + bb ) && d > csymAbs * mmax )
cCsymBad = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,23 @@ namespace madmatrix
// dedup. A row that far below the largest cannot bias the helicity sum
// whichever way it is paired, while a genuine parity violation shows up
// at the relative level. One verdict for every crossing.
// FP32 amplitudes (FPTYPE=f and the default v) round at ~1e-7 per
// operation: an FP64 tolerance there switches the dedup off (all ncomb
// rows evaluated, the mirrored half outside the hel-recycling table: v
// ran 1.7x slower than d on g g > t t~ g g). Measured on the scan
// points (simd_128, FP32), the mirror rows of C-symmetric processes
// differ by up to 7e-7 of the largest |M|^2 and 1.3e-5 of the pair
// (g g > t t~ g g (g), u u~ > t t~ g g), a genuine parity violation by
// O(1) on both (0.7 for u u~ > e+ e-, u u~ > z g g). A pair is flagged
// only above both FP32 tolerances (1e-5): the cut against the largest
// |M|^2 stays ~15x above the roundoff (as the verdict latches, one
// harder point of the run must not switch the dedup off).
{
#if defined MADMATRIX_FPTYPE_FLOAT
const fptype csymRel = (fptype)1e-5, csymAbs = (fptype)1e-5;
#else
const fptype csymRel = (fptype)1e-6, csymAbs = (fptype)1e-12;
#endif
fptype mmax = (fptype)0.;
for( int h = 0; h < ncomb; h++ )
for( int ie = 0; ie < neppV; ++ie )
Expand All @@ -1432,7 +1448,7 @@ namespace madmatrix
if( d < (fptype)0. ) d = -d;
const fptype aa = a < (fptype)0. ? -a : a;
const fptype bb = b < (fptype)0. ? -b : b;
if( d > (fptype)1e-6 * ( aa + bb ) && d > (fptype)1e-12 * mmax )
if( d > csymRel * ( aa + bb ) && d > csymAbs * mmax )
cCsymBad = true;
}
}
Expand Down
12 changes: 8 additions & 4 deletions madgraph/iolibs/template_files/madmatrix/madmatrix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ endif

# Set the default FPTYPE (floating point type) choice
ifeq ($(FPTYPE),)
override FPTYPE = m
# default denom64, consistent with precision='denom64' in run_card.toml
override FPTYPE = v
endif

# Set the default HELINL (inline helicities?) choice
Expand Down Expand Up @@ -69,10 +70,13 @@ endif

#=== Configure MADMATRIX_BUILDDIR

# Build directory: build.<BACKEND> by default (USEBUILDDIR=1), or current directory if USEBUILDDIR=0
# Build directory: build.<BACKEND>_<FPTYPE> by default (USEBUILDDIR=1), or current directory if USEBUILDDIR=0
# NB: using '=' (not ':=') ensures BACKEND is evaluated lazily after the potential 'auto' resolution
# NB: FPTYPE is part of the name, as it is of the library names: several FPTYPEs of one
# backend coexist (an mg7 run with [run] precision_check builds its FPTYPE and FPTYPE=d),
# and a change of FPTYPE needs no 'make clean'
ifeq ($(USEBUILDDIR),1)
override MADMATRIX_BUILDDIR = build.$(BACKEND)
override MADMATRIX_BUILDDIR = build.$(BACKEND)_$(FPTYPE)
else
override MADMATRIX_BUILDDIR = .
endif
Expand Down Expand Up @@ -758,7 +762,7 @@ override TAG = $(BACKEND)_$(FPTYPE)_inl$(HELINL)
# Export TAG (so that there is no need to check/define it again in src/Makefile)
export TAG

# Build directory for object files: build.<BACKEND> by default, or current directory if USEBUILDDIR=0
# Build directory for object files: build.<BACKEND>_<FPTYPE> by default, or current directory if USEBUILDDIR=0
override BUILDDIR = $(MADMATRIX_BUILDDIR)

###override INCDIR = ../../include
Expand Down
4 changes: 2 additions & 2 deletions madgraph/iolibs/template_files/madmatrix/madmatrix_src.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ endif
# Use the build lockfile "full" tag exported from the subprocess Makefile
###$(info TAG=$(TAG))

# Build directory for object files: current directory by default, or build.<BACKEND> if USEBUILDDIR==1
# Build directory for object files: current directory by default, or build.<BACKEND>_<FPTYPE> if USEBUILDDIR==1
###$(info Current directory is $(shell pwd))
override BUILDDIR = $(MADMATRIX_BUILDDIR)

Expand Down Expand Up @@ -106,7 +106,7 @@ $(BUILDDIR)/.build.$(TAG):
#-------------------------------------------------------------------------------

# Generic target and build rules: objects from C++ or CUDA/HIP compilation.
# Plain .o suffix — the BUILDDIR (e.g. build.simd_256/) provides backend separation.
# Plain .o suffix — the BUILDDIR (e.g. build.simd_256_v/) provides backend and FPTYPE separation.
# Use USEBUILDDIR=1 to build for multiple backends simultaneously without cleaning.
ifeq ($(GPUCC),)
$(BUILDDIR)/%%.o : %%.cc *.h $(BUILDDIR)/.build.$(TAG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ override standalone_objects = $(BUILDDIR)/RamboSamplingKernels.o \
$(BUILDDIR)/CommonRandomNumberKernel.o \
$(BUILDDIR)/check_sa.o

# force relink when changing to before compiled backend
# force relink when changing to a before compiled backend or FPTYPE (each has its own
# build directory, whose objects can then be older than check_sa.exe)
CHECK_SA_BACKEND_MARKER = .check_sa_backend
check_sa.exe: $(CHECK_SA_BACKEND_MARKER)
$(CHECK_SA_BACKEND_MARKER): FORCE
@if [ ! -f $(CHECK_SA_BACKEND_MARKER) ] || [ "$$(cat $(CHECK_SA_BACKEND_MARKER) 2>/dev/null)" != "$(BACKEND)" ]; then \
echo $(BACKEND) > $(CHECK_SA_BACKEND_MARKER); \
@if [ ! -f $(CHECK_SA_BACKEND_MARKER) ] || [ "$$(cat $(CHECK_SA_BACKEND_MARKER) 2>/dev/null)" != "$(BACKEND)_$(FPTYPE)" ]; then \
echo $(BACKEND)_$(FPTYPE) > $(CHECK_SA_BACKEND_MARKER); \
fi
.PHONY: FORCE
FORCE:
Expand Down
11 changes: 7 additions & 4 deletions madgraph/iolibs/template_files/mg7/madtrex_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def default_output_path(events_path: str) -> str:
# reweighting doesn't need MadGraph's card machinery. MadGraph always writes
# every entry out, so these only matter for hand-written cards.
_RUN_CARD_DEFAULTS = {
"run": {"device": ["cpu"], "cpu_mode": "auto", "precision": "color32"},
"run": {"device": ["cpu"], "cpu_mode": "auto", "precision": "denom64"},
"beam": {
"leptonic": False,
"pdf1": "NNPDF40_lo_as_01180",
Expand Down Expand Up @@ -531,7 +531,7 @@ def _generation_param_card(process_directory: str, events_path: str, param_card:

def _check_stored_matrix_elements(events_path: str, init_meta, process_directory: str,
param_card: str, devices: list[str], fptype: str,
sample: int = 32, rel_tol: float = 1e-6,
sample: int = 32, rel_tol: float | None = None,
card_label: str = "") -> None:
"""Re-evaluates the original matrix element (helicity-summed, with
param_card, at fptype) for a sample of the events of events_path whose
Expand All @@ -541,8 +541,11 @@ def _check_stored_matrix_elements(events_path: str, init_meta, process_directory
changing nothing normalised by the stored ones gives the ratio of the
two as its weight over the event weight. rel_tol leaves room for an MLM
run's stored matrix elements, which are the first evaluation rescaled to
the event's alpha_s rather than evaluated again (about 1e-7 apart at the
mixed fptype)."""
the event's alpha_s rather than evaluated again: about 1e-7 apart with
FP64 amplitudes (fptype d, m, e), a few 1e-6 with FP32 ones (f, v); the
default rel_tol is 1e-6, resp. 1e-5."""
if rel_tol is None:
rel_tol = 1e-5 if fptype in ("f", "v") else 1e-6
if not events_path.endswith(".npy"):
return
import numpy as np # only here: LHE events need no numpy
Expand Down
2 changes: 1 addition & 1 deletion madgraph/iolibs/template_files/mg7/param_reweight_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

# Hard-set for now (see the module docstring); should become a modifiable
# global default once MadtRex/madevent.py grow one of their own.
DEFAULT_FPTYPE = "m"
DEFAULT_FPTYPE = "v"

# Recognized "change <NAME> <value>" preamble Driver options (see
# DriverOptions) besides the shared "change helicity", lowercase, matched
Expand Down
3 changes: 3 additions & 0 deletions madgraph/iolibs/template_files/mg7/run_card.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ cpu_mode = %(run.cpu_mode)s
madspace_cpu_mode = %(run.madspace_cpu_mode)s
# matrix element precision; options: all64, all32, color32, denom64
precision = %(run.precision)s
# fraction of the events evaluated again in all64 to check the precision (0: no check);
# builds the matrix elements a second time, in all64
precision_check = %(run.precision_check)s
# after the generation, reweight the events to the matrix elements compiled at
# this FPTYPE and report how many significant digits they share with the
# generated weights (no weights are written); d (all64) is the suggested
Expand Down
Loading
Loading