Recurrence export format

This page specifies the JSON file in which pyAmpliCol exports the leading-color (LC) recurrence programs of an artifact, so that you can evaluate the matrix element in your own code, for example on a GPU, and get the same binary64 bits as pyAmpliCol.

  1. Export a process
  2. The file at a glance
  3. Identity and numbers
  4. Programs and storage
  5. Runs and instructions
    1. Sources
    2. Instructions
    3. Kernel bindings
    4. Reduction
  6. Couplings and model parameters
  7. Evaluating a program
  8. Arithmetic order
  9. Worked example
  10. Optional reference values
  11. Golden vectors
  12. Limits
  13. See also

Export a process

The export reads a leading-color artifact (the generated process directory) in the recurrence execution mode, generated with the JIT backend. One command writes every process, alias, group member and color flow of the artifact to one file:

pyamplicol generate "u u~ > g g" artifacts/uu_gg --model built-in-sm \
  --color-accuracy lc
pyamplicol export-recurrence artifacts/uu_gg -o uu_gg.json

Its options (selecting processes and color flows, changing model parameters, adding reference values, indenting) are listed under export-recurrence on the command-line reference. In Python, a loaded runtime returns the same document for its own process as a dictionary:

from pyamplicol import Runtime

runtime = Runtime.load("artifacts/uu_gg")
export = runtime.export_recurrence()
print(export["schema_version"], [p["colour_id"] for p in export["programs"]])
# 2 ['flow:2,3,4,1', 'flow:2,4,3,1']

runtime.export_recurrence(color_flows=..., reference_momenta=...) selects color flows and adds reference values. Rust code calls NativeRuntime::export_recurrence or export_recurrence_json. The export evaluates no phase-space point unless you ask for reference values, and it is the same before and after evaluations: the number of points and the batch size do not change the program.

The file at a glance

One file holds a header, the model parameters, one program per process and color flow, and the compiled kernels the programs call:

export
├── schema_version, execution_semantics, rusticol_version, artifact_id
├── parameters[]          {name, value}
├── programs[]            one per process and color flow
│   ├── process_key, process, colour_id, legs, caller_legs, crossing
│   ├── momentum_forms[]  signed sums of leg momenta
│   ├── currents[], current_component_count, amplitude_count
│   ├── helicity_outputs[]
│   ├── body[]            the instructions, shared by every run
│   ├── kernel_bindings[]
│   ├── runs[]            {sources[], reduction[]}
│   ├── group_factor, alpha_s
│   └── reference_values  only when requested
└── kernels[]             {sha256, application_base64}

An evaluator reads the header and decodes the kernels once, then for each program computes the momentum forms, executes the body once per run, adds each run’s reduction into the helicity outputs, and applies the group factor.

Identity and numbers

The top-level object has these fields.

Field Type Meaning
schema_version integer 2 for the layout on this page; check it before reading further
execution_semantics string "rusticol-batched-f64-v1": the arithmetic contract of Arithmetic order; check it too
rusticol_version string the version of Rusticol, the Rust runtime of pyAmpliCol, that wrote the file
artifact_id string the identity of the exported artifact
parameters array of {name, value} the model parameters at which every value of the file was resolved; value is complex
programs array the programs, described below
kernels array of {sha256, application_base64} each compiled kernel a program calls, once

Numbers follow four rules:

  • A complex number is an object {"re": ..., "im": ...} of two binary64 values.
  • Read every number so that it round-trips to the same binary64 value, signed zero included.
  • Every number is finite. An export whose resolved values contain an infinity or a NaN (for example from a model parameter) is refused, and the error names the quantity, such as body[12].factor.re of a program.
  • Every index (legs, components, amplitudes, forms, sources, bindings, outputs) starts at 0.

A kernel is a saved SymJIT application: application_base64 is the unmodified .plane.symjit file in standard padded base64, and sha256 is its hash. Its own operations, including its fused multiply-adds, define its arithmetic. A program calls a kernel for a vertex or propagator that has no named Rusticol formula. A file whose programs need none, as in the worked example, has an empty kernels array.

Programs and storage

Each element of programs is one color flow of one process.

Field Type Meaning
process_key string the process ID in the artifact
process string its expression, such as u u~ > g g
colour_id string the stable color-flow ID, such as flow:2,3,4,1; IDs are per process
representative_process_key, representative_colour_id string the stored program that implements this entry; equal to the entry’s own for a stored program
external_count integer the number of legs
legs array of leg the legs in program order; the momentum forms refer to these
caller_legs array of leg the legs in the order of the momenta you pass
crossing array or null maps program legs to caller legs; null when the two orders agree
momentum_forms array of arrays of {leg, coefficient} the momenta the program uses, as signed sums of leg momenta
currents array the currents and where they live in the arena (informative)
current_component_count integer the size of the current arena, in complex components
amplitude_count integer the number of complex amplitudes
scales, factors arrays of complex the resolved parameter values and constant factors of the program (informative: every instruction carries its own values)
helicity_outputs array of {id, helicities} the output axis: a stable ID such as h:-1,+1,-1,+1 and the helicity of every leg
body array of instructions executed once per run
kernel_bindings array how kernel rows feed and read the kernels
runs array of {sources, reduction} one execution of the body each
group_factor {numerator, denominator} an exact rational factor of a process-group member, applied at the end
alpha_s object or null the strong coupling, see Couplings and model parameters
reference_values object, optional values of the runtime at given points, see Optional reference values

A leg is {pdg, name, role}: its PDG code, its particle name and "initial" or "final".

Aliases and group members. The command writes a full program only for each stored representative. An alias or a process-group member gets a short entry: its own process_key, process, colour_id, the two representative_ fields, caller_legs, crossing, group_factor, helicity_outputs and, if requested, reference_values, plus program_reference, an object {process_key, colour_id} naming the full program. Take every other field from that program, and keep the entry’s own crossing, group factor and helicity outputs. A representative is included even when --process selects only a member. The Python call returns full programs.

Crossing. Each element of crossing is {program_leg, caller_leg, sign}: the momentum of program leg \(\ell\) is sign times the momentum of caller leg caller_leg. Apply it before the momentum forms. Momenta follow the usual convention: GeV, [E, px, py, pz] per leg, metric \((+,-,-,-)\).

Momentum forms. A form is an ordered list of terms {leg, coefficient} referring to program legs. The forms treat every leg as outgoing: an incoming leg enters with coefficient \(-1\), so the source of an incoming leg reads a momentum of negative energy. The forms already include the leg permutation of the selected color flow.

Currents. The arena holds current_component_count complex components and amplitude_count complex amplitudes. Instructions address components by their offset in the arena, not by current. The scheduler reuses storage after a current’s last use, so the ranges of different currents can overlap. The arena also holds scratch components at its end, which appear in no entry of currents. The entries describe the plan and are not needed to evaluate it.

Field Type Meaning
semantic_id integer the current’s identity in the plan
current, component_count integers its first component in the arena and its number of components
physical_type string or null the source family for a source current; null when the stored plan does not name it
initial_state string "source" (written by a source), "zero" (a clear covers it) or "first_instruction" (its first write sets it)
stage integer its dependency stage: 0 for a source, \(k - 1\) for a current built from \(k\) external legs
first_use, last_use integers the first and last dependency stage at which it is live, inclusive; the final closure counts as one stage past the largest

Runs and instructions

The body is stored once per program; each element of runs executes it with its own sources and then adds its own reduction terms. A program that replays one color flow has one run; a program that evaluates all flows in one pass has one run per computed helicity configuration. Runs may share one arena and execute in sequence, or be concatenated into one stream in their order: the clears and initializing writes of the body define everything a run reads.

Sources

A source instruction names an element of its run’s sources by index.

Field Type Meaning
current, component_count integers where the wavefunction is written
family string "scalar", "weyl", "dirac", "vector" or "spin2"
orientation string "particle", "antiparticle" or "self_conjugate", of the outgoing leg
leg integer the program leg it represents (informative)
momentum_form integer the form that gives its momentum
helicity, chirality integers already crossed
mass complex the wavefunctions use mass.re only
factor complex multiplies every component
embedding array empty for an ordinary source; otherwise {component, source_component, factor} entries that place the wavefunction’s components

The wavefunction is the versioned Rusticol formula of its family: a scalar is 1; a Weyl source is the two-component massless spinor of an outgoing quark (particle) or antiquark (antiparticle); a Dirac source the four-component spinor of mass mass.re; a vector source the polarization vector of a massless or massive vector boson; a spin-2 source its polarization tensor. The formulas are in Rusticol’s wavefunction source and their adapter in the source executor.

Instructions

Every instruction is an object with a kind. In the table, \(c_k\) is component \(k\) of the current arena, \(a_m\) amplitude \(m\), \(f\) the instruction’s factor, and products are the complex products of Arithmetic order. mode is "set" (overwrite) or "add" (accumulate).

kind Fields Operation
clear current, component_count write \(+0\) to the components of the range
clear_amplitude amplitude write \(+0\) to the amplitude
source source evaluate the indexed source of the run and write \(f \cdot \psi_k\) to its components
vertex vertex, current, mode, left, right, left_momentum, right_momentum, coupling, factor evaluate the named vertex on the two parent currents and momentum forms, multiply by \(g \cdot f\) with \(g\) the coupling, set or add
propagator propagator, current, component_count, momentum_form, factor apply the named propagator in place, with \(f\)
scale current, component_count, factor \(c_k \leftarrow f \cdot c_k\) in place
copy current, source, component_count, factor write \(c_{s+k} \cdot f\), with \(s\) the source, to the destination range; a zero factor writes \(+0\)
scatter current, source, component_count, mode, factor set or add the scaled scratch range, with the shortcuts of Arithmetic order
closure amplitude, left, right, component_factors, factor add the component-wise product of two currents to the amplitude
kernel binding, destination, amplitude, left, right, left_momentum, right_momentum, mode, factor evaluate a kernel through its binding, see Kernel bindings

left, right and current are first components in the arena; a null operand is absent. The named vertices and propagators are versioned Rusticol formulas, listed in the intrinsic executor. A vertex computes its base result from the parents first and multiplies it by \(g \cdot f\) afterwards. Fanout is explicit: a vertex or kernel writes its result into scratch components, and scatter instructions then distribute it.

Kernel bindings

Each program’s kernel_bindings stores every distinct binding once.

Field Type Meaning
id integer the binding a kernel instruction names
sha256 string the kernel in kernels
inputs array of projections the kernel’s real inputs, in the application’s input order
outputs array of projections where its real outputs go, in output order, real and imaginary part of each complex output in turn
direct boolean store the outputs unscaled

A projection is relative to the operands of the kernel instruction that uses the binding. Its kind is one of:

kind Fields Reads or writes
parent parent (0 or 1), component, imaginary a component of left (0) or right (1), real or imaginary part
destination component, imaginary, amplitude a component of destination: of the current arena, or of the amplitudes when amplitude is true
momentum operand (0 or 1), component Lorentz component 0 to 3 of left_momentum or right_momentum
literal value a resolved real value
factor imaginary the real or imaginary part of the instruction’s factor

To execute a kernel instruction, read all inputs before writing any output (outputs may alias inputs), evaluate the application, and for each complex output \(o\) write \(o\) (when direct is true) or \(o \cdot f\) (otherwise), set or added according to mode. The amplitude field of the instruction says whether destination is an amplitude or a current component. Rusticol sets direct only on finalization rows (those in the place of a propagator) whose factor is exactly \((1, +0)\) and whose outputs overlap neither the inputs nor each other; such rows use "set".

Reduction

Each element of a run’s reduction adds one squared amplitude to one output.

Field Type Meaning
helicity_output integer the index in helicity_outputs
amplitude integer the amplitude to square
amplitude_scale complex a phase or multiplicity of a replayed amplitude
apply_amplitude_scale boolean multiply by amplitude_scale first, even when it is \((1, 0)\)
weight binary64 the term’s weight: the coefficients of the color flow and of the helicity configuration, the averages over initial spins and colors, the symmetry factor and, for built-in models, the coupling constants

The terms keep the runtime’s order. Outputs without terms keep their initial zero: structural zeros stay on the helicity axis.

Couplings and model parameters

Every value in the file is resolved at the model parameters listed in parameters: couplings, factors, masses and literals. An evaluator never evaluates a model expression. To export at other values, pass --model-parameters FILE, or load the runtime with model_parameters= (the same mapping as on Evaluating matrix elements), and export again.

Where the coupling constants sit depends on the model:

  • Built-in models: the vertex couplings are normalized constants without \(g_s\) or \(e\). The coupling constants are in every reduction weight, which is proportional to \(\alpha_s^{p}\,\alpha^{q}\) through the parameters normalization.alpha_s_me_check and normalization.alpha_ew; the body does not depend on them.
  • UFO models: the vertex couplings and the literal inputs of kernels are the model’s resolved couplings, \(g_s\) included, and the weights hold no coupling constant.

alpha_s identifies the strong coupling, when the runtime knows it:

Field Type Meaning
parameter string the parameter’s name: the model’s declaration of \(\alpha_s\), its SLHA input SMINPUTS[3], the name given by the provider, or normalization.alpha_s_me_check for a built-in model
value complex its value in this export
squared_amplitude_power integer or null the power \(p\) of \(\alpha_s\) of the squared amplitude, for a process of one QCD order; null when the orders are mixed

When \(\alpha_s\) enters only through \(g_s\), a tree-level result of one QCD order is proportional to \(\alpha_s^{p}\), and squared_amplitude_power lets you rescale it to another value of \(\alpha_s\). Any other parameter change needs a new export.

Evaluating a program

For one program and one phase-space point \(p_j\) (caller leg \(j\)), an evaluator performs these steps.

  1. Check schema_version and execution_semantics. For an entry with program_reference, take the referenced program and replace its crossing, group_factor and helicity_outputs by the entry’s own.
  2. Cross the momenta. With a crossing element \((\ell \to j, s)\), the momentum of program leg \(\ell\) is \(q_\ell = s\, p_j\); without crossing, \(q_\ell = p_\ell\).
  3. Evaluate each momentum form \(F\) with terms \((\ell_1, c_1), (\ell_2, c_2), \dots\) component by component, from positive zero, in term order:

    \[P_F^\mu = \Bigl(\bigl((+0) + q_{\ell_1}^\mu c_1\bigr) + q_{\ell_2}^\mu c_2\Bigr) + \cdots\]
  4. Allocate the arena (\(c_0, \dots\), current_component_count complex values) and the amplitudes (\(a_0, \dots\), amplitude_count values), and set every helicity output \(R_h\) to \(+0\).
  5. For each run, in order: execute every instruction of body, top to bottom, with the run’s sources; then, for each term of the run’s reduction, in order, take \(a = a_m\), multiply it by the amplitude_scale \(\sigma\) when apply_amplitude_scale is true, and add

    \[R_h \leftarrow R_h + \mathrm{fma}\bigl(\mathrm{Re}\,a,\ \mathrm{Re}\,a,\ (\mathrm{Im}\,a)^2\bigr)\, w ,\]

    with \(w\) the weight and \(\mathrm{fma}(x, y, z) = xy + z\) rounded once.

  6. After all runs, if the group_factor \(n/d\) has \(n \neq d\), set \(R_h \leftarrow (R_h\, n)/d\), converting \(n\) and \(d\) to binary64 first; never multiply by a precomputed ratio.
  7. \(R_h\) is the leading-color value of this color flow and helicity configuration. The LC matrix element of the process is the sum over its color flows (its programs) and helicity outputs:

    \[\lvert \mathcal{M} \rvert^2_{\mathrm{LC}} = \sum_{\text{flows}} \sum_h R_h .\]

A batch of points runs the same steps for every point; points do not interact.

Arithmetic order

The format is bit exact: an evaluator that follows these rules reproduces pyAmpliCol’s binary64 values to the last bit. Do not reassociate sums, and do not let the compiler contract products and sums into fused multiply-adds (no fast-math). The only fused operation outside kernels is the one in the reduction.

A product of complex numbers is the ordinary one, with four products, one subtraction and one addition, each rounded:

\[x \cdot y = \bigl(x_r y_r - x_i y_i ,\ x_r y_i + x_i y_r\bigr) .\]

The grouping of products is part of the format:

Instruction Arithmetic
source \(c_k \leftarrow f \cdot \psi_k\); with an embedding, \(c_{k} \leftarrow \phi \cdot \psi_{k'}\) with the entry’s factor \(\phi\), or \(+0\) when source_component is null
vertex \(\sigma = g \cdot f\) first, then each output \(V_k \cdot \sigma\)
scale \(f \cdot c_k\)
copy \(c_{s+k} \cdot f\); when both parts of \(f\) are zero, \(+0\)
closure for each component \(k\) in order: \(a_m \leftarrow a_m + (l_k \cdot r_k) \cdot (\kappa_k \cdot f)\), with \(\kappa_k\) the \(k\)-th of component_factors; one addition to the amplitude per component
kernel \(o \cdot f\), or \(o\) unchanged when direct
reduction \(a \cdot \sigma\), then the fused multiply-add of step 5, then the product by \(w\), then the addition

A scatter keeps the runtime’s shortcuts, which differ from the ordinary product for signed zeros. With \(v\) the scratch value and \(f = (f_r, f_i)\):

Factor Result
\(f_i = 0\), \(f_r = 1\) \(v\)
\(f_i = 0\), \(f_r = -1\) \((-v_r, -v_i)\)
\(f_i = 0\), other \(f_r\) \((v_r f_r,\ v_i f_r)\)
\(f_i \neq 0\), \(f_r = 0\) \((-v_i f_i,\ v_r f_i)\)
otherwise \(v \cdot f\)

The result is then set or added according to mode. Each named vertex, propagator and wavefunction has a fixed operation order, given by its source; a change of that order changes execution_semantics.

The arithmetic consists of binary64 additions, subtractions, multiplications, divisions, square roots, sign changes and the reduction’s fused multiply-add. These are correctly rounded on every IEEE-754 platform, and no transcendental function is involved, so the bits do not depend on the platform. Kernels follow the operations of their saved application.

Worked example

The file uu_gg.json exported in Export a process holds the process u u~ > g g of the built-in Standard Model at leading color. It has two color flows and uses only named formulas. Each of the two programs has one run, 16 helicity outputs, 4 amplitudes and 44 instructions: 4 clear_amplitude, 6 source, 10 clear, 14 vertex, 6 propagator and 4 closure. An evaluator for it needs these named formulas:

Kind Name or family
sources weyl (massless quarks), vector with zero mass (gluons)
vertices rusticol.recurrence-intrinsic.weyl-vector-to-weyl-b.v1, rusticol.recurrence-intrinsic.color-ordered-three-vector-full.v1
propagators rusticol.recurrence-intrinsic.weyl-propagator-a.v1, rusticol.recurrence-intrinsic.vector-propagator-feynman.v1

The vertex couplings are \(1/\sqrt{2}\) and \(i/\sqrt{2}\), and every reduction weight is \(\tfrac{27}{72}\,(4\pi\alpha_s)^2 = 0.8245462300846093\) at \(\alpha_s = 0.118\). At the point

u   [500,    0,    0,  500]
u~  [500,    0,    0, -500]
g   [500,  300,  240,  320]
g   [500, -300, -240, -320]

the evaluation gives:

Color flow Helicities \((h_u, h_{\bar u}, h_g, h_g)\) \(R_h\)
flow:2,3,4,1 \((-,+,-,+)\) and \((+,-,+,-)\) 0.12170302356048836 each
flow:2,3,4,1 \((-,+,+,-)\) and \((+,-,-,+)\) 0.00586433367543103 each
flow:2,4,3,1 \((-,+,-,+)\) and \((+,-,+,-)\) 2.525713365496061 each
flow:2,4,3,1 \((-,+,+,-)\) and \((+,-,-,+)\) 0.1217030235604884 each
sum over flows and helicities   5.549967492584938

The other twelve outputs of each flow are 0 or below \(10^{-31}\). The sum is the value the runtime returns:

from pyamplicol import Runtime

runtime = Runtime.load("artifacts/uu_gg")
point = [[500, 0, 0, 500], [500, 0, 0, -500],
         [500, 300, 240, 320], [500, -300, -240, -320]]
print(runtime.evaluate([point])[0].real)
# 5.549967492584938

For your own process and points, ask the export for reference values and compare bit for bit.

Optional reference values

--reference-points FILE adds the runtime’s binary64 values at given points to each selected program, so that an implementation can be checked without pyAmpliCol. The file holds either one batch for every process,

[[[500, 0, 0, 500], [500, 0, 0, -500],
  [500, 300, 240, 320], [500, -300, -240, -320]]]

shaped [point][leg][E, px, py, pz] in caller leg order, or an object that maps each exported process_key to its own batch. A batch must not be empty. In Python, pass reference_momenta=batch to runtime.export_recurrence(). Each selected program or member entry then carries:

Field Type Meaning
momenta array the points, as given
helicity_ids array of strings the IDs of the entry’s helicity_outputs, in order
values array of arrays \(R_h\) for each point and helicity output, [point][helicity]

The values come from the batched path that this format describes; a single point is evaluated twice internally to take that path, and one copy is kept. An ordinary evaluation of one point can differ in the last bits. The field is absent from an export without reference points.

Golden vectors

The golden-vector file pins the arithmetic of the current execution_semantics instruction by instruction. It gives shared initial arenas and momentum forms at five points, then cases with their inputs and the expected bits of every arena slot they change. The cases cover every vertex and propagator, every source family and orientation (massless and massive, positive and negative energy, the axis and rest branches, an embedded source), scale, copy, every scatter shortcut in both modes, closure, the kernel projections and output adapter, momentum forms with and without crossing, reductions and group factors. Each binary64 value is its IEEE-754 bit pattern in 16 hexadecimal digits. Kernel cases use identity kernels (identity-N copies \(N\) complex inputs to \(N\) outputs, identity-N-to-M copies the first \(M\)), so they pin the projections and the adapter, not a saved application.

Replay every case through your implementation and compare the bits. The vectors are samples with full mantissas that cover every branch: they make an undetected change of formula unlikely, but they are not a proof. How the file is kept in step with the code is described in Recurrence export: tests and golden vectors.

Limits

  • Only leading color is exported. An artifact at NLC or full color is refused (recurrence export requires LC colour accuracy); regenerate it with --color-accuracy lc.
  • Only the recurrence execution mode is exported; compiled, on-the-fly and eager artifacts, contracted color and one-loop artifacts are refused.
  • Only portable executors are exported: an artifact generated with the C++ or assembly backend is refused with a request to regenerate it with the JIT backend.
  • A color-flow ID that a selected process lacks is refused with an error that lists the process’s flow IDs. IDs are per process: on an artifact with several processes, combine --color-flow with --process.
  • Kernels are SymJIT applications: an evaluator of a UFO-model export must run them, through SymJIT or an implementation of their operations.
  • The file holds the values of one parameter point; see Couplings and model parameters.

See also