Using FeynKit from Python
FeynKit is a Symbolica community module. Use a combined Symbolica distribution built with feynkit-py; a standalone FeynKit wheel is not produced by this repository. The host integration guide gives the registration and packaging steps. Do not assume that an arbitrary published Symbolica wheel already includes this module.
python -c "import symbolica.community.hepkit as fk; print(fk.__name__)"With that host installed, run the following from the GammaLoop repository root. It uses the same small normalized model as the Rust quickstart and needs neither UFO import nor an external integral-evaluation backend.
import symbolica.community.hepkit as fk
model = fk.Model("crates/feynkit-model/tests/fixtures/scalars_2p_3p.json")
result = model.process(["scalar_0"], ["scalar_0", "scalar_0"]).generate_diagrams(loops=0, max_vertices=3)
assert result.diagrams
diagram = result.diagrams[0]
diagram.validate()
assert diagram.loop_count == 0
restored = fk.FeynmanDiagram.from_json(model, diagram.to_json())
assert restored.name == diagram.name
print(diagram.to_dot())
cff = diagram.integrate_energy(method="cff")
print(cff.to_expression())For a loop diagram, diagram.integrate_energy(method="cff") and diagram.integrate_energy(method="ltd") construct the two energy representations, CffRepresentation and LtdRepresentation. Display either object to explore its terms, or call to_expression() for Symbolica algebra. They share one expression normalization; the interface guide documents the energy factors, contour convention and separate spatial measure. The numerical showcase compares both representations in the same convention. For method selection in shared code, use diagram.integrate_energy(method="cff") or diagram.integrate_energy(method="ltd"); literal overloads preserve the concrete return type in editors and type checkers.
model.process(incoming, outgoing) binds external states and particle/vertex restrictions to the model. Use particle_veto, vertex_allow, and vertex_veto at construction, or process.with_filters(...) to create a restricted copy. Omitted filters are preserved; None clears a filter, while vertex_allow=[] allows no interactions. Use process.generate_diagrams() for a GenerationResult, process.generate_amplitude() for an Amplitude, and process.generate_cross_section() for sewn diagrams and their cuts. All three accept loop order (loops=0 by default), coupling orders, symmetrization, topology filters, and execution settings as keywords. These settings belong to each call. Particle names, PDG codes, and particles obtained from that model can select external states.
In notebooks, displaying a Process draws the external states around a central blob. process.render() returns a displayable DiagramView and accepts typed settings, for example process.render(config=fk.RenderSettings(node_radius=5)). Use help(fk.RenderSettings) to discover the options. Retain the view and display it so the notebook browser can measure its labels. Once measurement completes, view.measured().to_svg() exports the schematic as text. Scripts can explicitly request a local browser with view.measured(browser="chromium").to_svg(); strict measured() raises while labels are pending. Alternative final states are drawn separately.
Default view.snapshot(), view.to_svg() and view.to_html() export complete static output without launching a browser. They reuse completed measurements, otherwise use optional typst-py outlining when available, otherwise estimated STIX MathML label bounds. Estimates leave measurement pending. Installing anywidget adds live notebook measurement; earlier snapshots remain immutable.
Model members display their defining data and expressions, rather than only their names:
Particle masses and physical electric charges are symbolic expressions. The particle charge includes its sign and is inferred from photon interaction vertices:
from symbolica.community import hepkit as hep
qed_model = hep.Model.qed()
electron = qed_model.particle("e-")
mass, charge = electron.mass, electron.electric_charge
e = -electron.electric_charge
assert charge == -e
assert electron.charge == -1 # dimensionless charge in units of eThe charge accessor uses the normalization of minimal photon–fermion or photon–scalar vertices, without assuming parameter names. A neutral particle has zero electric charge even in a model without photon interactions.
model.vertex_rules[0] # ordered legs, color/Lorentz structures, and coupling terms
model.particle("scalar_0") # quantum numbers, mass, width, and antiparticle
print(model.vertex_rules[0]) # a complete plain-text summaryThe same rich and plain-text printers cover model.parameters, model.couplings, model.lorentz_structures, model.propagators, model.functions, and model.form_factors. For a collection in marimo, use mo.vstack(model.vertex_rules); in a terminal, iterate and print the members or use pprint on the list.
Numerators are Spenso
TensorExpression values, subclasses of Symbolica’s Expression with an ordered tensor interface; CFF expressions are ordinary Expression values. Algebraic methods such as expand_num() and collect_factors() preserve the tensor type. Inherited Symbolica methods remain available directly. Use to_expression() to explicitly discard the tensor interface and select ordinary expression behavior. The FeynKit module must share symbolica.core with Spenso, Idenso, and other community modules; independently linking a second Symbolica extension breaks that ownership contract.Exact particle quantum numbers
Particle.charge is a Symbolica expression backed by Rust’s Rational. JSON stores exact integers and fractions as strings, such as "-1" and "2/3". For string inputs, Model.from_json accepts integers and fractions. When reading a JSON file, UfoLoader.load also accepts exact decimal and exponent spellings such as "0.5" and "1e-3".
from symbolica import E, S
from symbolica.community import hepkit as fk
charm = fk.Model.standard_model().particle("c")
assert charm.charge == E("2/3")
assert charm.y_charge == E("1/3")
assert charm.y_charge_right == E("4/3")
assert charm.weak_isospin == E("1/2")
assert charm.weak_isospin_right == E("0")
assert charm.mass == S("UFO::MC")Hypercharge follows , as in the PDG electroweak review. For fermions, y_charge and weak_isospin refer to the left-handed component; y_charge_right and weak_isospin_right refer to the right-handed component. Charge conjugation exchanges chirality and reverses the charges: the positron has left/right hypercharges and weak-isospin components . None means missing metadata, an absent chiral field, or a state without a definite hypercharge. In particular, the SM has no right-handed neutrino field, and the neutral real Higgs and Goldstone fields are not hypercharge eigenstates. Weak isospin is derived from the model’s charges, without a PDG-code lookup.
The UFO adapter preserves Y, YRight, and the optional charge_exact attribute. Integers and fraction strings in those attributes stay exact. Finite integer-valued floats are accepted. For a fractional float of magnitude below 4096, the loader uses a fraction with denominator at most only if it rounds back to exactly the input float. This recovers 2/3 from the usual UFO expression charge = 2/3. Supply other fractions as exact strings.
For serialized model JSON, fractional numeric literals use the same recovery rule. Integer-valued floating-point literals must have magnitude at most . Integer JSON tokens in the signed or unsigned 64-bit range and exact fraction strings retain their values. Export writes the charge as an exact string.
mass returns exact zero for the UFO ZERO parameter and a symbol for every other mass parameter, including parameters whose current value is zero. The shipped SM values match restrict_default.json: electron, muon, and charm masses and their Yukawa inputs are zero, and the CKM matrix is identity. These are parameter-card choices; the complete particle and vertex content is retained. The disk JSON, fixture, and embedded model share the same Feynman-gauge propagators, Goldstone flags, and Lorentz structures.
Try the interactive first-diagram showcase or choose a component from the notebook gallery.
Continue with model inspection and generation, the tensor selector example, or notebook rendering. The complete signature and docstring inventory is in the Python API reference.