Models

A model gives pyAmpliCol its particles, parameters, vertices and propagators. You choose it once per generation; pyAmpliCol compiles it, checks that it can serve it, and bakes the compiled model into the artifact (the generated process directory). This page shows which model to choose, how to restrict and parametrize it, and how to reuse its compiled form. Writing the process itself is on Processes.

Model source choices

Source Select it with Use it for Runs Python code when loaded
Built-in Standard Model built-in-sm the fastest tree-level Standard Model workflows no
Built-in scalar HEFT built-in-sm-heft the Standard Model plus effective Higgs-gluon vertices no
Shipped UFO model its name: sm, scalars, scalar_gravity, loop_sm, loop_qcd_qed_sm, loop_qcd_qed_sm_Gmu UFO models with their restriction cards; the three loop_* models for one-loop requests no
JSON model a path to a .json file a portable form of an external model no
UFO directory a path to the directory a model of your own yes
Compiled model a path to a .pyAmplicol-model.json file reusing a compiled model no
Prepared model a path to a .pyamplicol-model file reusing a compiled model together with its compiled kernels no

The same choice is written three ways. In a run card:

[model]
source = "built-in-sm"

On the command line, --model built-in-sm (with --restriction NAME). In Python, a ModelSource:

from pyamplicol import ModelSource

sm = ModelSource.built_in_sm()
heft = ModelSource.built_in_sm_heft(restriction="no_b_mass")
loop_sm = ModelSource.from_path("loop_sm", restriction="no_widths")
json_sm = ModelSource.from_path("models/json/sm/sm.json")

A shipped model is found by its bare name only when no file or directory of that name exists next to the run card; an existing path always wins.

A tree-level request is generated by default in the recurrence execution mode, which needs compiled kernels of the model: machine code for its vertices and currents, built for one evaluator backend. The built-in models ship with them. For any other model, generate in the compiled mode (--execution-mode compiled) or from a prepared model.

Built-in Standard Model

built-in-sm is a Standard Model written into pyAmpliCol. It ships with compiled kernels for the recurrence, on-the-fly and eager execution modes, so a tree-level generation starts without compiling the model (Execution modes and backends).

At tree level it agrees with the UFO sm under its no_masses restriction: the top quark is the only massive quark and the only fermion with a Yukawa coupling.

  • The electroweak and Higgs sectors are complete: photon, Z and W exchange between quark lines when the coupling orders allow it, the neutrino exchange of e+ e- > w+ w-, the \(HHVV\) and four-Higgs contact vertices, and every Higgs attached to a top-quark line (t t~ > t t~, t w- > t w- d d~).
  • Charged-current processes such as u d~ > c s~ are served. In an inclusive p or j request, a jet subprocess that changes quark flavor is kept only when the request implies a W.
  • A massive top line that ends on a massless b quark (single top, b b~ > w+ w-, t~ > b~ w-) is served in every tree-level execution mode.
  • A process whose Born amplitudes have several coupling orders, such as u u~ > d d~ with max_coupling_orders = { QCD = 2, QED = 2 }, is served with the interference between the orders, as with the UFO sm.

For such a mixed-order process the model reads \(\alpha_s\) from normalization.alpha_s_me_check and \(\alpha\) from normalization.alpha_ew at run time; changing one rescales each squared coupling order by its own power. The recurrence, compiled and on-the-fly modes split the result by squared order (evaluate_orders); the eager mode does not (Evaluating matrix elements). Without named coupling orders, the default policy keeps one order (QCD only for u u~ > d d~).

Built-in scalar HEFT model

built-in-sm-heft is the built-in Standard Model plus the scalar effective vertices of a Higgs boson with two, three and four gluons. Its effective coupling order is HIG:

pyamplicol model inspect built-in-sm-heft
pyamplicol generate 'g g > H g g' artifacts/gg_hgg --model built-in-sm-heft \
  --coupling-order-policy explicit --max-coupling-order HIG=1 \
  --color-accuracy full --execution-mode recurrence

The shipped example card builtin_sm_heft.toml holds the same request. The model takes the parameter defaults of the shipped sm (with \(m_H = 125\) GeV). The effective coupling GH is derived from the strong coupling, the vacuum expectation value and the masses MH and MT: change those inputs, not GH. The effective vertices keep their full momentum dependence.

Restrictions. The model always applies a restriction card of the shipped sm: restrict_default.json unless restriction names another one (no_b_mass, no_masses, zeromass_ckm, …). For example, a massless b quark for the five-flavor scheme:

[model]
source = "built-in-sm-heft"
restriction = "no_b_mass"

The shipped compiled kernels cover the default restriction. With another restriction, the compiled execution mode works directly; the recurrence, on-the-fly and eager modes need a prepared model of that restriction:

pyamplicol model compile built-in-sm-heft models/heft-no-b-mass.pyamplicol-model \
  --restriction no_b_mass --backend jit
pyamplicol generate 'g g > h g' artifacts/heft_no_b_mass \
  --model models/heft-no-b-mass.pyamplicol-model --execution-mode recurrence

The names builtin_sm_heft, sm-heft and sm_heft select the same model.

What is served. A Higgs between the effective vertex and the rest of a tree leads to color structures with closed gluon traces. The execution modes serve them as follows; every value agrees with MadGraph’s heft model with its split orders.

Higgs between Examples Served by
fusing gluons and color singlets g g > z z, g g > h h every mode
a colorless pair and gluons z z > g g, h h > g g g every mode
an external Higgs, or a gluon of a quark line g g > H g g, u u~ > H g, t t~ > h g every mode
a part of the tree with only gluons and the rest g g > t t~ and t g > t g g with \(\mathrm{HIG} \ge 1\); u u~ > z g g; g g > g g with \(\mathrm{HIG} = 2\) recurrence, on-the-fly and compiled; eager only in simple cases (Eager)
gluons of two quark lines d d~ > t t~ g, u u~ > d d~ t t~ recurrence, on-the-fly and compiled; not eager, not as the Born of a one-loop request

Leading-color flows of these processes carry their traces in the flow ID, for example flow:3,4|1,2 (open line 3–4, trace of gluons 1 and 2). Where a mode does not serve a structure, the request is refused with a SingletExchangeColourError that names the modes that serve it. Color correlations of these processes are served wherever the compiled mode serves them (Spin and color correlations).

Coupling orders. HIG counts like a QED coupling in the model’s hierarchy, as in MadGraph’s heft, and the default policy allows at most one effective vertex per amplitude. A default t g > t g g is therefore its QCD tree, and a default t t~ > h g keeps its Yukawa diagrams next to the effective vertex. max_coupling_orders = { HIG = 0 } removes the effective vertex (Processes).

Trusted external HEFT UFOs

A scalar-HEFT UFO model of your own goes through the ordinary UFO path. Inspect it before generating: pyAmpliCol accepts the supported families of scalar contact vertices with one or two structure constants and refuses other Lorentz, color or form-factor structures when it loads the model. Prefer built-in-sm-heft for portable work.

Shipped UFO models

The UFO models sm, scalars and scalar_gravity, MadGraph’s one-loop model loop_sm, and the QCD+QED models loop_qcd_qed_sm and loop_qcd_qed_sm_Gmu are shipped with pyAmpliCol, each with all its restriction cards. Select one by its name:

pyamplicol generate 'u u~ > z g' artifacts/uu_zg_ufo \
  --model sm --restriction no_widths --execution-mode compiled

The three loop_* models carry the counterterms that one-loop requests need: One-loop QCD with loop_sm and One-loop QCD+QED (electroweak) are their recipes. What a model needs for one-loop requests, and the [loop.preparation] table that adapts one, are on One-loop matrix elements.

Serialized JSON model

A JSON model is a UFO model written out as data. It runs no code when it is loaded and moves between machines as one file, so it is the recommended form of an external model. The shipped examples contain JSON forms of sm, scalars and scalar_gravity; copy them into a working directory:

pyamplicol examples copy ./pyamplicol-examples --force
cd pyamplicol-examples
pyamplicol model inspect models/json/sm/sm.json
[model]
source = "models/json/sm/sm.json"
restriction = "default"

The copied workspace also holds the UFO directories under models/ufo/. python python/copy_packaged_models.py DIR copies only the models into an empty directory.

Trusted UFO model

A UFO model is Python code, and loading it runs that code. Load only UFO models from a source you trust; for automated or shared workflows, use a JSON or compiled model, which runs nothing.

A UFO directory uses the same field, with a restriction as in MadGraph:

[model]
source = "/path/to/MyUFO"
restriction = "default"

In a run card or on the command line, restriction is a name: default reads restrict_default.dat (or .json) of the model’s directory, no_widths reads restrict_no_widths.dat, and so on. Without restriction, the model’s default card applies when it has one; none (or full) applies no card. ModelSource.from_path also takes a path to a card, relative to the model directory; it must be a restrict_<name> file of the model’s own directory, and restrict_full or restrict_none means no restriction.

Before generating, check that the model is supported:

pyamplicol model inspect /path/to/MyUFO --restriction default

The inspection lists the model’s particles, coupling orders and run-time parameters, and every unsupported feature with its diagnostic code, before any process is built. UFO model coverage lists every feature that is accepted, accepted under conditions, or refused.

Parameter restrictions and runtime cards

A model has two kinds of parameter values. The restriction card fixes values at compilation: the compiled model, and every artifact generated from it, is specialized to them. The remaining external parameters (masses, widths, \(\alpha_s\), …) stay run-time parameters, which you can change for each evaluation.

What restriction simplification specializes

With simplify = true, the default, compilation turns every external parameter that is zero on the restriction card into an exact zero, removes every coupling that vanishes at the card’s values, and drops the vertices left without a coupling. This is what makes a restricted model fast, and it is safe as long as the removed couplings stay zero:

  • At the card’s values and at every run-time value that keeps each removed coupling zero, the artifact is exact.
  • A run-time change that would revive a removed coupling is refused. For example, a coupling proportional to \(m_t - 173\) removed at \(m_t = 173\) GeV makes the artifact refuse any other top mass.
  • The complex-mass scheme of one-loop requests changes parameter values itself; every removed coupling is then decided again, exactly, and a coupling that would revive refuses the request with cms-revived-coupling. On the shipped models this affects only loop_sm with its card test.

The remedy in both refused cases is simplify = false (--no-simplify) for that model, or a restriction card under which the coupling vanishes for every value you need.

Parameter cards

A parameter card is a flat JSON mapping from a parameter name to a value: a finite real number, or [real, imaginary] (real only for a one-loop artifact). A compiled model writes the card of all its run-time parameters at their default values (see Typed model API); a card you pass may contain any subset:

{
  "aS": 0.118,
  "MT": 172.5
}

The command line applies a card with pyamplicol evaluate ARTIFACT --model-parameters CARD; Python passes the mapping to Runtime.load(..., model_parameters=...) or set_model_parameters. An update is applied as a whole or not at all: an unknown, fixed, invalid or non-finite value refuses the whole card. Evaluating matrix elements covers run-time parameters, and the changes an artifact refuses, in full.

Model commands

pyamplicol model has three subcommands. None of them generates a process.

Command What it does
model inspect SOURCE compiles the model (or reads it from the cache) and shows its particles, orders, run-time parameters and diagnostics
model compile SOURCE OUTPUT writes a compiled model, or a prepared model when OUTPUT ends in .pyamplicol-model
model processes REQUEST lists the concrete processes a generation of REQUEST would store (Processes)

A compiled model is written with the suffix .pyAmplicol-model.json, which model compile and CompiledModel.write add when the output path has neither it nor .compiled-model.json, in any letter case:

pyamplicol model compile models/json/sm/sm.json models/sm.pyAmplicol-model.json

It holds the normalized model, ready to generate from without reading the source again. Its options are in Command-line options.

Prepared models

A prepared model (a file ending in .pyamplicol-model) holds a compiled model together with compiled local kernels for one evaluator backend. The recurrence, on-the-fly and eager execution modes generate from it without compiling each kernel again:

pyamplicol model compile models/json/sm/sm.json models/sm-jit-o2.pyamplicol-model \
  --backend jit --jit-optimization-level 2
pyamplicol generate 'd d~ > z g g g' artifacts/dd_z3g \
  --model models/sm-jit-o2.pyamplicol-model --execution-mode recurrence

Each artifact copies the kernels it uses, so the prepared model is not needed at run time. The built-in models come with their prepared kernels; you prepare one yourself for an external model, or for built-in-sm-heft with a non-default restriction. Kernels prepared with the JIT backend at optimization level 2 move between 64-bit Linux and macOS hosts; C++ and assembly kernels, and JIT kernels at other levels, are tied to the machine type they were built for (Process artifacts and portability).

Typed model API

ModelSource.compile() returns a CompiledModel, which generate accepts as model= and which several generations can share:

from pyamplicol import ModelSource, RunConfig, generate
from pyamplicol.config import EvaluatorConfig

compiled = ModelSource.from_path("models/json/sm/sm.json").compile()
print(compiled.name, compiled.capabilities.supported_color_accuracies)
# sm ('lc', 'nlc', 'full')
compiled.write("models/sm.pyAmplicol-model.json")
compiled.write_parameter_card("data/sm_parameters.json")

in_compiled_mode = RunConfig(action="generate",
                             evaluator=EvaluatorConfig(execution_mode="compiled"))
generate("d d~ > z g", "artifacts/dd_zg_json", model=compiled,
         config=in_compiled_mode, mode="replace")

compiled.supported says whether the model passed its checks, compiled.info holds its metadata, and compiled.parameters its parameters. A written compiled model is read back with ModelSource.from_path. For a prepared model, pass prepared_output= (the .pyamplicol-model path) and evaluator= (an EvaluatorConfig naming the backend) to compile.

A compiled model is identified by its source, its restriction, the compile options and the code of pyAmpliCol that compiled it. A compiled model written by another build of pyAmpliCol, or a prepared model whose format numbers differ from those of the installed pyAmpliCol, is refused: compile it again from its source.

Model caches

Compiling a UFO or JSON model takes several seconds or more, so pyAmpliCol keeps compiled models in a cache and reuses them. A cache entry is found by the contents of the model source and its restriction card, the compile options and the code of pyAmpliCol: editing any of them, or upgrading pyAmpliCol, compiles the model once more.

Setting Run card Command line Default
model cache on or off model.cache --model-cache, --no-model-cache on
cache directory model.cache_dir --model-cache-dir DIR see below
one-loop preparation cache model.loop_preparation_cache --loop-preparation-cache, --no-loop-preparation-cache on

The cache directory is model.cache_dir when set, otherwise $PYAMPLICOL_CACHE_DIR/models, otherwise the user’s cache directory: ~/.cache/pyamplicol/models on Linux, ~/Library/Caches/pyamplicol/models on macOS. Paths in a run card are relative to the card.

The one-loop preparation cache

Before a one-loop generation builds any amplitude, it prepares the model for the request: the restriction card, the parameters, the counterterms and the couplings, in exact arithmetic. This takes a while on the QCD+QED models. The result is kept in the loop-preparations subdirectory of the model cache, one file per model and simplification, so the next one-loop generation with the same model reads it.

  • Switches. The cache is used only when model.cache, model.loop_preparation_cache and the environment variable PYAMPLICOL_LOOP_PREPARATION_CACHE all allow it. Any of them set to off wins: PYAMPLICOL_LOOP_PREPARATION_CACHE=0 (or false, no, off) disables it without editing a card. A true value changes nothing; any other value is refused.
  • Freshness. An entry is found by the model as the generation sees it (model files, restriction card, loop declaration, [loop.preparation], mass scheme), the simplification and the code identity of pyAmpliCol and its dependencies. Changing any of them writes a new entry; a stale, damaged or foreign entry is ignored and rebuilt, never an error.
  • What it changes. Only time: the artifact is byte-identical with the cache off, empty or filled. Concurrent generations may share it. A cache directory that cannot be written leaves the generation uncached, with one warning.
  • Cleaning. Nothing is deleted automatically. Deleting the loop-preparations directory, or any file in it, is always safe.

A dry run (pyamplicol generate --dry-run, Generator.plan) also fills the one-loop preparation cache, but only when the compiled model is already in the model cache: a dry run never compiles a model. Run pyamplicol model inspect on the model first to prepare ahead.

Limits

  • Model features outside the supported set (Majorana fermions, spin 3/2, color sextets, \(\epsilon\) color tensors, color groups other than SU(3), unknown form factors, and others) are refused when the model is loaded, with a diagnostic code. Massive spin 2 is experimental. The full list is on UFO model coverage.
  • At a finite width of a colored particle a tree amplitude is not gauge invariant. pyAmpliCol always uses the complete triple-gluon vertex, as MadGraph does, so its values agree with MadGraph’s at any width and do not depend on the order of the legs.
  • Mixed-order processes of the built-in models need \(\alpha_s \ge 2^{-51}\,\alpha\) (about \(3.4 \times 10^{-18}\) at the default \(\alpha\)): a smaller normalization.alpha_s_me_check, zero included, is refused and leaves the runtime unchanged. For the purely electroweak limit, generate with QCD = 0.
  • In the compiled mode at leading color, a coupling component that one of the color-flow runtimes does not use cannot be set: the update is refused (model-parameter override ... is not used by process ...).
  • Compiled models and artifacts written by another build of pyAmpliCol, and prepared models whose format numbers differ, are refused; compile or generate them again (Process artifacts and portability).

See also