From a model to finalized diagrams
Begin with a normalized JSON model, as in the quickstarts. Model validation resolves particle, parameter, interaction, propagator, and Lorentz-structure references to stable IDs. A diagram retains the same model so particle and interaction IDs remain meaningful after generation.
Import a UFO model
Raw UFO import is an optional adapter around Python’s ufo-model-loader>=1.0.1. Install that package in the interpreter used by the Symbolica host, then point the loader at your UFO directory:
from symbolica.community.hepkit import UfoLoader
loaded = UfoLoader(restriction_name="massless").load("models/sm")
model = loaded.modelThe directory and restriction are model-specific inputs. Rust callers enable feynkit/ufo and call UfoLoader with their own attached interpreter; the adapter does not initialize Python or replace its logging and standard streams.
Inspect and configure before generating
Model exposes particles, parameters, couplings, vertex rules, Lorentz structures, propagators, functions, and form factors through collections and lookups. particle.antiparticle resolves the paired record in the same model. ParameterCard changes external inputs; derived expression evaluation is an explicit boundary. Python callers can pass an evaluator to with_parameter_card() or use recompute_with(). The evaluator receives EvaluationRequest and returns EvaluatedValues; incomplete results raise ModelError without publishing a partially updated model.
Python accepts generation settings directly as keyword arguments. Exact coupling orders use integers; pairs specify inclusive bounds, with None for an unbounded coupling maximum. Filter objects specify which subgraphs to reject. Python permits self-loops, rejects zero-flow edges, and follows GammaLoop’s defaults for subgraph rejection: non-vacuum processes filter self-energies, tadpoles and zero-momentum snails. Vacuum processes leave those filters off and require one factorized loop topology. Cross sections default to one cut blob, no spectators, and symmetrized final states.
The default maximum_bridges=... retains tree-level exchange channels and requires one-particle irreducibility for each diagram with loops. This decision uses the individual diagram’s loop count, including when requesting a mixed range such as loops=(0, 1). External legs do not count as bridges. An explicit integer, including maximum_bridges=0, limits bridges at every loop order; maximum_bridges=None disables the restriction. One-particle-reducible loop corrections are therefore opt-in when assembling a complete scattering amplitude. Rust exposes the same loop-only policy as GenerationFilter::LoopOneParticleIrreducible. Numerator comparison is disabled by default; pass NumeratorGrouping explicitly to enable it. Diagrams still contain their vertex, propagator and aggregate numerators. As in the current GammaLoop --only-diagrams path, generation does not construct an evaluable integrand. Numerator validation first checks identical factored expressions; it expands only when needed to compare differing representations.
For process-dependent filters and grouping, ... in the signature means automatic defaults. Pass an options object to customize a filter, or None to disable it. The same distinction applies to factorized-loop, cut-blob and spectator ranges.
import symbolica.community.hepkit as fk
result = model.process(['g'], ['g'], particle_veto=['c', 't', 's', 'u', 'd']).generate_diagrams(loops=1, coupling_orders={'QCD': 2, 'QED': 0}, zero_snails=fk.SnailFilterOptions(veto_attached_to_massless=True), threads=4)Reuse keyword settings with a Python dictionary and **kwargs; each call constructs a fresh Rust configuration. A process can also be configured independently of generation:
import symbolica.community.hepkit as fk
process = model.process(["e-", "e+"], ["mu-", "mu+"])
result = process.generate_diagrams(loops=1, max_vertices=6, maximum_bridges=None)The same process can produce a symbolic amplitude or sewn cross-section diagrams:
process = model.process(["e-", "e+"], ["a", "a"])
amplitude = process.generate_amplitude()
squared = amplitude.squared().sum_spins(average_initial=True)
forward = process.generate_cross_section(loops=1)generate_cross_section returns a GenerationResult containing sewn forward diagrams and cut metadata; phase-space integration is a later operation. Its loop order counts loops in the forward graph, so a two-particle tree cut requires one loop. generate_amplitude rejects empty or cancelled generation rather than presenting an incomplete coherent sum. Neither method changes the process; loop order and symmetrization belong to each call.
Here model must provide those particles. Allowed interactions and particle vetoes are process restrictions, validated at construction. process.with_filters(...) returns a copy with changed restrictions; omitted fields are kept and None clears them. An empty vertex_allow=[] permits no interactions. Loop ranges, vertex bounds, coupling orders, and numerator grouping are specified for each generation call. An empty result can therefore mean the chosen constraints admit no graph. This is a completed GenerationResult with zero retained diagrams, not a configuration error. Inspect the generation report and relax a specific constraint before enlarging the search indiscriminately.
All three Process generation methods check Python signals while they run. Ctrl-C or a notebook interrupt stops generation and raises KeyboardInterrupt; exceptions from custom Python signal handlers also propagate. Cancelling an explicit CancellationToken instead returns an incomplete result, preserving that API’s existing partial-result behavior.
Observe progress and prune partial topologies
Both generation methods default to progress="auto". In Marimo, they check marimo.running_in_notebook() and maintain one status display showing the current stage, processed counts, and elapsed time. Known totals use a progress bar; unknown or empty totals use a spinner. Counts reset for each stage. The display closes on completion, cancellation, or error. Outside a running notebook, automatic progress stays quiet and does not import Marimo. Pass progress=None to disable it.
For custom reporting, pass progress=callback. The callback receives an immutable GenerationProgress with stage, completed, and total. Counts restart at each stage; total is None means the amount of work is unknown, so show a spinner instead of a percentage. Topology enumeration counts discovered unique graphs, not every explored branch. Later stages count processed inputs, which may be rejected. complete reports the final retained count; cancelled marks a partial result. The stages are topologies, topology_filters, interactions, interaction_filters, numerators, selection, grouping_preparation, grouping_samples, grouping_comparison, grouping, and the terminal stage. The first three grouping phases count input diagrams while preparing symbolic numerators, evaluating numerical samples, and comparing them. The final grouping phase merges and finalizes the retained diagram groups.
Native workers publish snapshots; Python callbacks run on the thread that called generation, so Marimo keeps its cell context. Updates within a stage are coalesced to about 150 ms; stage transitions and completion are delivered promptly. The automatic display explicitly flushes these updates so Marimo’s own refresh throttle cannot hide a stage transition. Browser kernels invoke callbacks on their calling thread; flushing output alone does not yield execution to the browser for painting.
result = model.process(["e-", "e+"], ["mu-", "mu+"]).generate_diagrams(loops=1, maximum_bridges=None)Use filter=callback for live pruning during enumeration. It receives a Symbolica Graph snapshot and completed_vertices: the first N vertices have all their incident edges fixed, while later vertices may still gain edges. Returning False rejects that search branch, without cancelling the run. Reject only conditions that cannot become acceptable as the partial graph grows; a numerator or UV-degree test requires a finished FeynmanDiagram.
def no_self_edges(topology, completed_vertices):
return all(source != target for source, target, directed, pdg in topology.edges())
result = model.process(["e-", "e+"], ["mu-", "mu+"]).generate_diagrams(loops=1, allow_self_loops=True, maximum_bridges=None, filter=no_self_edges)This example illustrates the callback contract; for this particular condition, prefer the built-in allow_self_loops=False option to avoid Python callback overhead.
Node data is a Symbolica integer: 0 for an interaction vertex, -(index+1) for an incoming external leg, and +(index+1) for an outgoing leg, using the generator’s external-leg index. Edge data is the base particle’s PDG code; directed edges distinguish particle flow from antiparticle flow. These snapshots can be retained or modified without changing generation. Keep the filter cheap: it runs synchronously for enumeration candidates, and the current Symbolica API requires building each Python snapshot through Graph.add_node and Graph.add_edge. No FeynKit topology wrapper or independent graph algorithms are involved. Exceptions from either callback cancel generation and propagate unchanged.
Assemble and square amplitudes
Amplitude owns a coherent collection of finalized diagrams, aligning external tensor ports by physical leg identity. It retains the source diagrams and individual weighted terms. The operator includes each diagram’s overall factor and numerator prefactor exactly once; the diagnostic automorphism order is not a second symmetry factor.
from symbolica.community.hepkit import Amplitude
amplitude = Amplitude(generated.diagrams)
operator = amplitude.expression()
adjoint = amplitude.conjugate().expression()
squared = amplitude.squared()
unpolarized = squared.sum_spins(average_initial=True).sum_colors(average_initial=True)
tensor = unpolarized.expression().simplify_algebra(gamma=True, color=True, epsilon=True)
tensor = tensor.contract(collect_chains=False, collect_traces=False)These expressions are amputated and unintegrated. External wavefunctions remain open spin/color ports until explicitly summed. legs exposes each physical particle, incoming/outgoing state, momentum, and bare tensor index. terms exposes individual TensorExpression operators. Conjugation uses Idenso’s physical-leg Dirac adjoint and color conjugation. Model-declared real parameters and physical momenta are real; additional assumptions can be supplied with real=[...]. Other scalar symbols, including complex couplings, retain their conjugation. Named model couplings are expanded into their analytic parameter expressions before conjugation.
Model real names, explicit real=[...] expressions and the selected dimension are matched exactly, including names ending in underscores. Such names do not act as substitution wildcards. An unrelated symbolic dimension remains conjugated unless it is selected as the dimension or explicitly declared real.
Squaring includes all interferences. Ket and bra indices remain separate, as do their loop integration variables. sum_spins([0, 1], average_initial=True) closes selected legs; omitting the labels selects all remaining legs. An explicitly repeated sum raises an error, preventing repeated averaging. Vector references={leg: momentum} and Dirac spin_vectors={leg: spin} use the existing completeness API. Omitting a massless vector reference chooses the covariant sum, which requires a gauge-invariant amplitude and the corresponding Ward identity. At most one colored massless vector leg, such as a gluon, may omit its reference across all sums of a square; otherwise sum_spins raises AmplitudeError because unphysical contributions require external ghosts. Multiple QED photons may use covariant sums under their Ward identities. This color-based guard does not establish gauge invariance for a custom model or an incomplete amplitude. Color sums close the actual dual representations of the open ports.
The Lorentz dimension defaults to four and can be set with dimension=D; bispinor spaces retain dimension four. Denominators follow the diagram’s quadratic convention, without widths or an imaginary prescription. Flux, identical-final-state factors, loop measures, and phase-space integration are not supplied by SquaredAmplitude. Already-sewn forward diagrams are rejected: their inverse-process right side must not receive a second amplitude conjugation. GammaLoop’s CFF/subtraction/sampling pipeline continues to own those diagrams separately.
Analyze interaction regions with Linnet
Finalized diagrams use GammaLoop’s half-edge conventions. Amplitude external states are dangling half-edges, incoming at a sink and outgoing at a source. Cross-section initial states are sewn paired edges; their is_external metadata still identifies external momentum carriers. Every item in diagram.vertices is an interaction. A missing edge endpoint is None, and external names, indices, and states belong to the edge.
Graph analysis calls Rust Linnet directly and needs no Python linnet installation. Filters receive FeynKit DiagramVertex, DiagramEdge, and DiagramHalfEdge objects. Select native diagram IDs with diagram.subgraph(nodes=..., edges=..., half_edges=...), or use diagram.filter(...) to obtain a FeynKit Subgraph:
region = diagram.filter(edge=lambda edge: not edge.is_external)
numerator = region.numerator_expression()
components = region.connected_components()
boundary = region.boundary()
basis = region.momentum_basis()
routed = basis.route_expression(numerator)Subgraph inherits FeynmanDiagram and retains shared ownership of its original diagram. Its inherited operations use the selected region: denominators, momentum-basis enumeration, parent-compatible and contracted routing, superficial divergence, CFF construction, UV expansion, and tensor reduction. These methods have no subgraph argument. Numerator without excludes edges and their incident vertex factors, using the shared GammaLoop traversal. region.original accesses the full original diagram. Partial tensor reduction requires an explicit projector; a boundary momentum is never implicitly integrated. Overall factors, numerator prefactors, and projectors remain separate.
Nested region.subgraph(...) and region.filter(...) intersect with the current region. Set operations &, |, ^, -, and ~ preserve the original diagram owner. Cycles are FeynKit Subgraph objects. CutPartition exposes source_side, target_side, boundary_left, and boundary_right regions. TraversalTree returns physics vertices in discovery order and supports parent, child, ancestor, and fundamental-cycle queries. All result regions retain the immutable physics owner. Structural cycles include sewn initial-state carriers, while the physical loop_count excludes those carriers when constructing a momentum basis.
For optional interoperability, install the matching Python linnet extension. diagram.to_graph() returns its canonical Graph with physics payloads, and diagram.subgraph(selection) imports graph-bound Linnet selections. Exported half-edge indices may differ from native IDs; the exported half-edge’s data contains its native ID. region.to_graph() returns the complete analysis graph; region.linnet_selection supplies its corresponding canonical selection for direct Linnet algorithms. Importing a canonical selection checks the graph owner and topology revision. A structural edit to the analysis graph invalidates those canonical selections, while existing physics views retain their immutable topology and remain usable.
Call region.excise() to obtain an independent FeynmanDiagram. Excision retains selected vertices and their complete interaction slots, preserving selected paired edges and opening other incident halves into external boundary legs. It remaps local edge, vertex, half-edge, tensor, and momentum identities consistently. A proper extraction starts with unit global factors, numerator prefactor, projector, and symmetry factor, and does not inherit whole-graph physical cuts or add external wavefunctions. A full selection gives an independent exact copy, including the original factors and routing. Serialization and operations requiring a complete topology, such as integral-family construction, require explicit excision first.
diagram.cuts contains generated physical cuts with reusable left.subgraph and right.subgraph physics views, coupling orders, side loop counts, crossing edges, and momentum signatures. diagram.topology_threshold_candidates records the distinct process-independent partitions. Linnet’s all_bonds and all_cuts describe structural cuts, without assigning physical final-state validity.
Inspect the propagator denominator
Each edge exposes its model particle and its instantiated momentum and denominator:
edge = diagram.internal_edges[0]
mass = edge.particle.mass
width_parameter = edge.particle.width_parameter
momentum = edge.momentum_expression(dimension=4, in_lmb=True)
signature = edge.momentum_signature()
denominator = edge.denominator_expression(dimension=4, in_lmb=True)The momentum is a rank-one Spenso vector; the signature exposes integer loops and external coefficients. Both methods accept lmb=basis for an alternative routing from the same diagram. edge.propagator returns the model’s propagator template for an internal physical line, or None when unavailable. Its expressions contain model placeholders; the edge expression methods supply diagram factors. External and dummy lines have no propagator denominator and raise DiagramError. Use power=2, for example, for a squared edge denominator.
denominator = diagram.denominator_expression()
integrand = diagram.numerator_expression() / denominatorThe denominator is a scalar Spenso TensorExpression using GammaLoop’s denom(edge, momentum, mass_squared, quadratic) annotation. The quadratic is , with the shared symbolic dimension by default; pass dimension=4 for a fixed dimension. edge_powers maps edge IDs to signed powers, including zero. Momentum labels match the numerator, masses remain symbolic model parameters, and the UFO ZERO mass becomes zero. The default region excludes external carriers and dummy edges; an explicit selection includes every paired edge, matching GammaLoop. Widths and an imaginary prescription are excluded. Custom UFO denominator formulas are not instantiated. A selection without internal propagators returns one. The ratio above still requires the diagram’s separate overall factor and any unapplied projector or numerator prefactor when assembling a complete integrand.
Use in_lmb=True on both expressions to replace edge momenta by the diagram’s stored loop and external momentum coordinates. Python already exposes the routing as LoopMomentumBasis; obtain the stored basis with diagram.loop_momentum_basis, or select another basis from diagram.loop_momentum_bases().
numerator = diagram.numerator_expression(in_lmb=True)
denominator = diagram.denominator_expression(in_lmb=True)
basis = diagram.loop_momentum_bases()[0]
numerator = diagram.numerator_expression(lmb=basis)
denominator = diagram.denominator_expression(lmb=basis)Supplying lmb enables routing and takes precedence over in_lmb. The basis must belong to the same diagram instance; bases for a subgraph or contracted region are accepted. Region selection, ignored numerator regions, denominator dimensions, and propagator powers are applied before routing. Both methods return TensorExpression.
basis.route_expression(expression) also preserves TensorExpression inputs and their ordered interfaces, including when routing cancels the tensor to zero. Plain Symbolica expressions and scalar constants return a plain Expression.
Pass loop_momenta and external_momenta to name the independent basis vectors using Spenso TensorName.vector objects. Loop names follow basis.loop_edges; external names follow basis.external_edges with basis.dependent_externals omitted. Each supplied list must cover its independent coordinates. Omitted lists retain the canonical indexed K or P calls. The same naming applies to vectors already expressed in the basis, preserving indexed and compact vector syntax.
from symbolica.community.tensor import TensorName
# For a one-loop, two-point graph:
K = TensorName.vector("example::K")
P = TensorName.vector("example::P")
routed = basis.route_expression(numerator, loop_momenta=[K], external_momenta=[P])kinematics.apply(expression) follows the same convention: scalar-product substitution preserves a tensor’s ordered ports, even when an on-shell relation makes it zero. Tensor methods can therefore be chained directly on the result. Contraction and momentum-conservation rewrites remain explicit operations; apply only substitutes the scalar products declared in the kinematics context.
For the local massive Taylor expansion, diagram.uv_expansion(mUV, edge_powers=powers) and region.uv_counterterm(mUV, edge_powers=powers) accept the same signed power map. Omitted internal edges have power one; entries outside the selected internal edges are ignored. Powers change the integrand, while the selected region and its loop integration measure stay fixed. When a prepared numerator contains an extra inverse propagator, move that factor into edge_powers before UV expansion. For example, multiply a longitudinal massless-vector numerator by and assign power two to that edge; this preserves the original integrand and gives both denominator factors the shared auxiliary-mass expansion.
Inspect superficial UV power counting
degree = diagram.superficial_degree_of_divergence()
degree_in_six_dimensions = diagram.superficial_degree_of_divergence(dimension=6)The local superficial degree adds the loop integration measures, momentum powers in the stored vertex and internal-edge numerators, and minus two for each quadratic propagator denominator. External legs, projectors, and global prefactors do not enter this count. Zero denotes a logarithmic superficial divergence, a positive value a power divergence, and a negative value superficial convergence. This local bound scales all momenta at each vertex together; it does not account for tensor cancellations or rule out UV subdivergences.
Cancel reversed fermion loops before integration
The host notebook hep/odd_photons.py uses typed particles and interaction rules to generate the one-, three- and five-photon electron loops. Keep the one-point topology by relaxing the bridge and tadpole filters explicitly:
electron, photon = (model.particle(name) for name in ("e-", "a"))
vertices = [
vertex for vertex in model.vertex_rules
if sorted(vertex.particles) == sorted([electron.name, electron.antiname, photon.name])
]
photon_count = 3
result = model.process([photon], [photon] * (photon_count - 1), vertex_allow=vertices).generate_diagrams(loops=1, max_vertices=photon_count, maximum_bridges=None, allow_self_loops=True, allow_zero_flow_edges=True, self_energy=None, tadpoles=None, zero_snails=None, numerator_grouping=None)Contract the external Lorentz slots with independent symbolic probe vectors, promote their Lorentz dimension to , and use Idenso to trace the compact graph-edge momenta. Apply diagram.momentum_basis().route_expression afterwards to expand scalar products into the loop basis. Keep overall_factor_expression(evaluate=True) and numerator_prefactor_expression() in every numerator. Add the probes to the diagram family’s external-vector list, retaining its generated denominators, so an IntegralMapping transports both loop-momentum and loop-probe scalar products.
With generic off-shell momenta, find_mapping identifies the unique reversed partner of each triangle or pentagon. Verify its denominator permutation and unit propagator powers, then add the mapped weighted numerators. Their exact zero proves the full tensor identity without IBP or master integrals. The one-photon numerator instead remains nonzero and odd in the loop momentum; the shared vacuum tensor reducer integrates it to zero.
The notebook pairs the families before tracing and evaluates a selected pair. The companion regression checks both triangles and all 24 pentagons, retaining symbolic dimension and electron mass throughout. These vector-current examples do not fix general gamma-five or Majorana conventions. The corrected shared Graphica automorphism count reserves the endpoint-exchange factor for undirected self-loops; directed fermion loops retain their orientation. The Symbolica Community host selects that owner, while standalone adoption awaits its registry publication. The nonzero Higgs-fermion tadpole regression checks normalization, which a zero Furry amplitude cannot establish.
For a nonzero example, the tadpole mass-insertion notebook differentiates the generated massive top-quark Higgs tadpole integrand with respect to its propagator mass. Hold the Yukawa coupling and scale fixed, use IntegralFamily.rewrite_numerator to identify the raised propagator powers, and reduce powers one through three with native IBPFamily.reduce_laporta. Keep the dimension symbolic until combining the pole with its coefficients, then evaluate the finite coefficient using shared OneLOop. The notebook also compares against numerical differentiation of the full finite tadpole. It does not impose a tadpole renormalization condition. HTML export and the live default plus twelve mass/scale states pass, including zeros of the finite tadpole and its derivative; the scaled finite-difference error stays below .
Carry a generated triangle through its finite amplitude
The host notebook hep/higgs_gluons.py starts from the model’s top-quark interactions for . Select typed VertexRule objects by their particle content instead of relying on model-specific vertex numbers:
top, higgs, gluon = (model.particle(name) for name in ("t", "H", "g"))
allowed_particles = [
sorted([top.antiname, top.name, higgs.name]),
sorted([top.antiname, top.name, gluon.name]),
]
vertices = [v for v in model.vertex_rules if sorted(v.particles) in allowed_particles]
result = model.process([higgs], [gluon, gluon], vertex_allow=vertices).generate_diagrams(loops=1, max_vertices=3, maximum_bridges=0, numerator_grouping=None)Keep both orientations and each diagram’s complete weight. Promote Lorentz slots to a dimension symbol before tracing, then give TensorReducer the loop vector and both independent external directions. IntegralFamily.rewrite_numerator produces scalar integral targets for native IBPFamily.reduce_laporta; OneLOop supplies their Laurent coefficients. Reduction and master evaluation are distinct steps. Substituting before the Laurent expansion would lose the finite rational from the dimension-dependent bubble coefficient.
Use the generated tree Yukawa vertex to fix the phase. The FeynCalc example chooses PreFactor -> -1, which reverses the native convention. Shared physical gluon spin and color sums, two-body phase space and decay flux then form the width, with one explicit for identical gluons. Above the quark-pair threshold, square the complex amplitude with its conjugate. The companion regression checks this single-flavor leading-order calculation; additional flavors must be summed coherently before forming a rate.
Generate local counterterm insertions
The QED renormalization notebook derives one-loop counterterm couplings by expanding the bare factors , , , and with . The local operator basis remains a model input. Add these normalized rules with a bookkeeping coupling order CT, then use the existing typed generation interface:
counterterms = ct_model.process([ct_electron], [ct_electron], vertex_allow=ct_vertices).generate_diagrams(loops=0, max_vertices=1, coupling_orders={"QED": 2, "CT": 1}, maximum_bridges=None, self_energy=None, tadpoles=None, zero_snails=None, numerator_grouping=None)The loop count describes topology; the CT order describes perturbative bookkeeping. A two-point insertion adds no topological loop, so choose an explicit vertex bound. Trace the generated numerators with the same projectors and native factors as the loop diagrams, extract coefficients linear in the unknown counterterms, and let Symbolica solve the matching system. The auxiliary mass rule derives from , which supplies at first order.
The notebook compares the massive full UV expansion with the massless reference’s direct massification prescription and verifies the MS/MSbar measure conversion against shared OneLOop masters. No separate generator, Dirac algebra, IBP solver or master evaluator is introduced for counterterms. Automatic import of NLO-UFO counterterm metadata remains separate.
The QCD renormalization notebook extends this construction to eight quark, gluon and ghost insertions. Use Particle.color_sum to close two-point color slots and preserve the generated external ordering factors separately for fermions and ghosts. Copy the original quark-gluon rule’s full color/Lorentz coupling matrix before dressing it with . The distinct ghost fields give an auxiliary-mass coefficient , whereas the identical gluons give . The generated coefficients determine the linear system and verify both MS and MSbar subtraction. The notebook exposes the gauge, flavor count, color count and subtraction scheme as live controls. Its direct massive infrared-rearrangement path adds an auxiliary mass only to massless denominators and keeps each longitudinal gluon’s extra propagator power explicit. After the external Taylor expansion and vacuum tensor reduction, use Symbolica partial fractions to separate tadpoles at the physical and auxiliary masses. Reconstructing the scalar integrand before native IBP guards against dropping either contribution. The physical pole constants agree between the two prescriptions, while the auxiliary gluon mass constant changes. The separate massless QCD notebook sets the quark mass to zero before this massification step. It uses Marimo’s app.embed() to access the shared calculation and exposes the seven remaining counterterms in its own controls. This composition keeps the symbolic workflow in one notebook while giving each physical case a focused presentation.
Keep finite terms in an off-shell self-energy
The host notebook hep/electron_self_energy.py generates the massive electron self-energy with a symbolic covariant-gauge photon numerator. Two trace projectors extract the coefficients of and without imposing an on-shell equation. Rewrite these coefficients in the generated family’s denominator coordinates before native IBP reduction. The longitudinal photon contributes an additional inverse photon denominator, so the target powers must retain that factor.
Keep each diagram’s native weight. Its generated tree vertex establishes the external ordering convention, which is then explicitly converted to the amputated inverse-propagator insertion. The two residual masters are the massive tadpole and massive-massless bubble; use their OneLOop Laurent coefficients and keep symbolic until the series expansion. This retains the finite rational terms from multiplying UV poles.
The notebook compares the result with independent parameter quadrature as momentum, mass, scale and gauge change. It splits at the physical branch cut, checks Landau gauge and the on-shell gauge-independent mass combination, and evaluates the symbolic zero-momentum limit separately from the generic projector. The companion regression checks exact-dimensional identities, limits and sixty numerical points. The finite answer is unrenormalized. The QED notebook above demonstrates generated counterterm matching separately from scalar-integral reduction.
Use finalized output
Generation performs topology expansion, interaction assignment, filters, canonicalization, fermion flow, numerator and projector construction, routing, zero detection, and grouping. The returned diagrams retain vertex/edge numerator fragments, the aggregate numerator, external projector, and separate scalar prefactors. Keep group multiplicities and prefactors when forming a complete expression; a diagram’s numerator alone is not the whole amplitude.
Named coefficients such as UFO::GC_11 stay in generated numerators. For analytic work, expand them using the model that owns the diagram:
analytic_numerator = model.expand_couplings(diagram.numerator_expression())This returns a new expression and preserves the stored named coefficients. Serialize with to_json() or to_dot() and restore with FeynmanDiagram.from_json(model, text) or from_dot(model, text). For a document containing multiple digraphs, FeynmanDiagram.from_dot_set(model, text) returns a list in document order. It accepts compact physics DOT and annotated exports; exports preserve each diagram’s momentum basis and physical cuts. An invalid graph fails the whole import.
In a DOT numerator, Q(0,cind(0)) selects the time component of edge 0′s momentum. FeynKit resolves Q to gammalooprs::Q and cind to spenso::cind. Parameters and couplings from the diagram’s model, along with the spacetime dimension dim (gammalooprs::dim) and color count Nc (spenso::Nc), also have short names. For example, with the Standard Model loaded, num="GC_11*Q(0,cind(0))" uses the model coupling UFO::GC_11. Use an explicit namespace such as example::GC_11 to supply your own symbol with the same name. Diagram JSON expressions use the same notation.
Recognized function heads cover graph momenta and propagators (Q, Q3, K, P, denom), external wavefunctions (u, ubar, v, vbar, ϵ, ϵbar), attachment indices (edge, vertex, hedge), Spenso tensor, slot, and representation constructors (g, dot, chain, trace, ♭, δ, aind, uind, dind, sind, open_index, index_scope, cind, find, mink, lor, euc, bis, spf, cof, coad), Dirac and Lorentz heads (gamma, gammaconj, gammaadj, gamma0, gamma5, projp, projm, charge_conjugation, sigma, epsilon), and color heads (t, f, d, gram, cas, idx). In g*g(i,j), the first g is a scalar and the function call selects the metric; write custom::f(x) when a user function shares a reserved head such as f or d. Symbolica mathematical functions keep their usual meaning, so cos(...) is always the cosine function; write spenso::cos for the color sextet representation.
In Python, pass the same string to model.parse_expression to obtain a Symbolica Expression. Other unknown names use the calling module’s Symbolica namespace, just as they do with E(...).
weight = model.parse_expression("GC_11*Q(0,cind(0))")
analytic_weight = model.expand_couplings(weight)The model fingerprint and structural validation protect the interpretation of stored IDs. Model serialization keeps UFO implicit and preserves all other Symbolica namespaces, so custom gauge symbols and tensor functions retain their identities through Model.to_json() and Model.from_json(). Distinct namespaces also remain distinct in the model fingerprint.
diagram.integrate_energy(method="cff") returns orientations, surfaces, generation statistics, and symbolic denominators. Rust generate() creates a fresh arena; generate_into() accepts a shared one. Resolve only the surface IDs referenced by an expression through its associated arena.The API map identifies the owning crate for each stage. For executable source examples, see the Rust generation program and the Python UFO program.