FeynmanDiagram
symbolica.community.hepkit Class
FeynmanDiagram()A generated or imported Feynman diagram, with particles, momenta and Feynman rules.
Obtain diagrams from Model.process(...).generate_diagrams().diagrams; use from_json or from_dot to restore a saved diagram with its model. There is no direct Python constructor. internal_edges are propagators, whereas external_edges carry the scattering or decay states.
Use numerator_expression() for symbolic algebra, integral_family() for loop-integral preparation, and render() for an SVG. Graph selections from subgraph and filter retain the original routing and identities. Routing changes return new diagrams. A diagram alone does not perform loop integration or supply a cross section.
Examples
Generate a one-loop scalar scattering diagram, inspect its propagators, and prepare its integral family. In a notebook, displaying diagram renders the graph. The methods below reuse this setup.
from symbolica import S, E
from symbolica.community import hepkit as hep
model = hep.Model.phi4()
process = model.process(["phi", "phi"], ["phi", "phi"])
result = process.generate_diagrams(loops=1)
diagram = result.diagrams[0]
diagram.validate()
assert diagram.loop_count == 1
propagators = [(edge.id, edge.particle_name) for edge in diagram.internal_edges]
numerator = diagram.numerator_expression()
family = diagram.integral_family()
assert family.is_completeMember details
linnet_selection
Property · read-only#linnet_selection: symbolica.community.graph.Subgraph Return the canonical Linnet selection representing this physics region.
Examples
Using the setup in the FeynmanDiagram class example:
region = diagram.subgraph(diagram.linnet_selection)
assert region.n_half_edges == len(diagram.half_edges)name
Property · read-only#name: strReturn the deterministic name assigned during diagram generation.
Examples
Using the setup in the FeynmanDiagram class example:
by_name = {item.name: item for item in result.diagrams}id
Property · read-only#id: strReturn the stable content-derived hexadecimal diagram ID.
Examples
Using the setup in the FeynmanDiagram class example:
selected = process.generate_diagrams(loops=1, select_diagrams=[diagram.id])
assert len(selected.diagrams) == 1symmetry_factor
Property · read-only#symmetry_factor: intReturn the positive integer denominator of the graph symmetry factor.
Examples
Using the setup in the FeynmanDiagram class example:
graph_weight = 1 / diagram.symmetry_factoroverall_factor
Property · read-only#overall_factor: strReturn the diagram-wide multiplicative factor as Symbolica source text.
This string form is useful for serialization. For algebra or notebook display, prefer overall_factor_expression() so Symbolica's native rich formatting is preserved.
Examples
Using the setup in the FeynmanDiagram class example:
source = diagram.overall_factor
factor = diagram.overall_factor_expression()
factor # rich Symbolica output in a notebooknumerator
Property · read-only#numerator: strReturn the diagram numerator annotation as source text.
Examples
Using the setup in the FeynmanDiagram class example:
source_text = diagram.numerator
numerator = diagram.numerator_expression()cuts
Property · read-only#cuts: list[DiagramCut] Return physical final-state cuts selected during generation.
Examples
Using the setup in the FeynmanDiagram class example:
physical_cuts = [cut.edges for cut in diagram.cuts]
assert physical_cuts == [] # ordinary amplitude, not a sewn cross sectiontopology_threshold_candidates
Property · read-only#topology_threshold_candidates: list[DiagramThresholdCandidate] Return topology threshold candidates separately from physical cuts.
Examples
Using the setup in the FeynmanDiagram class example:
partitions = [candidate.edges for candidate in diagram.topology_threshold_candidates]is_selection_only
Property · read-only#is_selection_only: boolWhether only spectator cuts selected this cross-section diagram.
A selection-only diagram has no physical cuts; it can be listed, displayed and exported, but not turned into an amplitude or integrand.
Examples
Using the setup in the FeynmanDiagram class example:
assert not diagram.is_selection_onlyspectator_cuts
Property · read-only#spectator_cuts: list[tuple[list[int], list[int], list[int]]] Return the spectator cuts that selected a selection-only diagram.
Each entry is (crossed_edges, left_spectators, right_spectators): the crossed non-initial-state edge IDs and the external connections whose incoming or outgoing leg crosses the cut. Like cuts, a view keeps only the records it fully contains: every crossed half-edge and both half-edges of each spectator's sewn initial-state edge. is_selection_only describes the whole diagram.
Examples
Using the setup in the FeynmanDiagram class example:
assert diagram.spectator_cuts == []loop_momentum_basis
Property · read-only#loop_momentum_basis: LoopMomentumBasisReturn the loop-momentum routing selected during generation.
Examples
Using the setup in the FeynmanDiagram class example:
basis = diagram.loop_momentum_basis
assert len(basis.loop_edges) == diagram.loop_countloop_count
Property · read-only#loop_count: intReturn the number of independent loops in the diagram topology.
Examples
Using the setup in the FeynmanDiagram class example:
basis = diagram.loop_momentum_bases(limit=1)[0]
len(basis.loop_edges) == diagram.loop_countvertices
Property · read-only#vertices: list[DiagramVertex] Return the diagram's interaction vertices with stable integer identifiers.
Examples
Using the setup in the FeynmanDiagram class example:
interactions = [model.vertex_rule(vertex.interaction) for vertex in diagram.vertices]edges
Property · read-only#edges: list[DiagramEdge] Return every particle line, including dangling and sewn external carriers.
Examples
Using the setup in the FeynmanDiagram class example:
particles_by_edge = {edge.id: edge.particle_name for edge in diagram.edges}half_edges
Property · read-only#half_edges: list[DiagramHalfEdge] Return diagram half-edges with native diagram IDs and physics edge objects.
Examples
Using the setup in the FeynmanDiagram class example:
half_edge_ids = [half_edge.id for half_edge in diagram.half_edges]internal_edges
Property · read-only#internal_edges: list[DiagramEdge] Return propagators excluding external momentum carriers and dummy edges.
Examples
Using the setup in the FeynmanDiagram class example:
propagators = [(edge.id, edge.particle_name) for edge in diagram.internal_edges]
assert len(propagators) == 2external_edges
Property · read-only#external_edges: list[DiagramEdge] Return incoming or outgoing external-state momentum carriers.
Examples
Using the setup in the FeynmanDiagram class example:
external_particles = [edge.particle_name for edge in diagram.external_edges]integrate_energy
Method#Overloads
Overload 1 #
integrate_energy(*, method: Literal["cff"], max_orientations: Optional[int] = None, fixed_orientations: Optional[Mapping[int, bool]] = None, contracted_edges: Optional[Sequence[int]] = None, initial_state_edges: Optional[Sequence[int]] = None, numerator: Optional[symbolica.Expression] = None) -> CffRepresentation Integrate propagators and an optional CFF numerator over loop energies.
The measure is :math:d\ell^0/(2\pi i) per loop, with contours closed below. Both representations include contour signs and on-shell factors, and share gammalooprs::OSE(e) for :math:E_e=\sqrt{\boldsymbol{q}_e^2+m_e^2}. CFF accepts a polynomial numerator; couplings, graph weights and the spatial measure are separate.
CFF supports subgraph selections and the constraints below. LTD requires a complete ordinary diagram and uses its stored ordered loop-momentum basis. Display either result directly to explore its terms and surfaces in a notebook.
Examples
Using the setup in the FeynmanDiagram class example:
cff = diagram.integrate_energy(method="cff")
ltd = diagram.integrate_energy(method="ltd")
expression = cff.to_expression()Returns
CffRepresentation or LtdRepresentation
The selected scalar energy representation, with structured term and surface inspection, expression conversion and notebook display.
Raises
ValueErrorThe method is unknown, or CFF-only options are supplied for LTD.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
method | Literal[ | — | Required representation choice. Literal arguments retain the concrete return type in editors and type checkers. |
max_orientations | Optional[ | None | CFF-only limit on candidate orientations. None imposes no limit. |
fixed_orientations | Optional[ | None | CFF-only constraints by physical edge ID: False keeps the stored direction; True reverses it. None leaves orientations unconstrained. |
contracted_edges | Optional[ | None | CFF-only physical edge IDs to contract before constructing surfaces. None contracts no edges. |
initial_state_edges | Optional[ | None | CFF-only physical edge IDs whose on-shell energies are moved into external energy shifts. None performs no such replacements. |
numerator | Optional[ | None | CFF polynomial in |
Overload 2 #
integrate_energy(*, method: Literal["ltd"]) -> LtdRepresentation Integrate propagators and an optional CFF numerator over loop energies.
The measure is :math:d\ell^0/(2\pi i) per loop, with contours closed below. Both representations include contour signs and on-shell factors, and share gammalooprs::OSE(e) for :math:E_e=\sqrt{\boldsymbol{q}_e^2+m_e^2}. CFF accepts a polynomial numerator; couplings, graph weights and the spatial measure are separate.
CFF supports subgraph selections and the constraints below. LTD requires a complete ordinary diagram and uses its stored ordered loop-momentum basis. Display either result directly to explore its terms and surfaces in a notebook.
Examples
Using the setup in the FeynmanDiagram class example:
cff = diagram.integrate_energy(method="cff")
ltd = diagram.integrate_energy(method="ltd")
expression = cff.to_expression()Returns
CffRepresentation or LtdRepresentation
The selected scalar energy representation, with structured term and surface inspection, expression conversion and notebook display.
Raises
ValueErrorThe method is unknown, or CFF-only options are supplied for LTD.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
method | Literal[ | — | Required representation choice. Literal arguments retain the concrete return type in editors and type checkers. |
to_graph
Method#to_graph() -> symbolica.community.graph.Graph Return the canonical installed Linnet graph with physics objects as payloads.
Node, edge, and half-edge identities are mapped explicitly. Structural edits affect this analysis graph only; the next export starts a fresh graph, and selections from the modified topology cannot be used here.
Examples
Using the setup in the FeynmanDiagram class example:
graph = diagram.to_graph()
gluons = graph.filter(edge=lambda edge: edge.data.particle_name == "g")subgraph
Method#subgraph(selection: Subgraph | None = None, *, nodes: Optional[Sequence[int]] = None, edges: Optional[Sequence[int]] = None, half_edges: Optional[Sequence[int]] = None) -> Subgraph Select graph elements using native diagram IDs or an existing physics region. Nested selections intersect this region and retain its immutable original diagram.
Examples
Using the setup in the FeynmanDiagram class example:
region = diagram.subgraph(edges=[0, 1])
numerator = region.numerator_expression()Parameters
| Name | Type | Default | Description |
|---|---|---|---|
selection | Subgraph | None | None | Existing selection from the same original diagram; exclusive with element IDs. Generic Linnet selections additionally require the |
nodes | Optional[ | None | Diagram vertex IDs to include, with all incident half-edges. |
edges | Optional[ | None | Diagram edge IDs to include. |
half_edges | Optional[ | None | Native diagram half-edge IDs to include. |
filter
Method#filter(*, node: Callable[[DiagramVertex], bool] | None = None, edge: Callable[[DiagramEdge], bool] | None = None, half_edge: Callable[[DiagramHalfEdge], bool] | None = None) -> Subgraph Select by predicates on diagram vertices, edges, and half-edges.
Examples
Using the setup in the FeynmanDiagram class example:
region = diagram.filter(edge=lambda edge: edge.particle_name == "g")Parameters
| Name | Type | Default | Description |
|---|---|---|---|
node | Callable[ | None | Predicate on DiagramVertex objects. |
edge | Callable[ | None | Predicate on DiagramEdge objects. |
half_edge | Callable[ | None | Predicate on DiagramHalfEdge objects. |
boundary
Method#boundary() -> SubgraphReturn boundaries around the selected interaction region.
The current region determines which interaction boundaries are returned.
Examples
Using the setup in the FeynmanDiagram class example:
region = diagram.subgraph(nodes=[0])
boundary = region.boundary()connected_components
Method#connected_components() -> list[Subgraph] Return connected interaction regions as reusable selections.
Examples
Using the setup in the FeynmanDiagram class example:
components = diagram.connected_components()is_connected
Method#is_connected() -> boolTest connectivity of the current diagram or selected region.
Examples
Using the setup in the FeynmanDiagram class example:
connected = diagram.is_connected()bridges
Method#bridges() -> SubgraphReturn lines whose removal disconnects the selection.
Examples
Using the setup in the FeynmanDiagram class example:
bridges = diagram.bridges()cycle_basis
Method#all_spanning_forests
Method#all_spanning_forests() -> list[Subgraph] Enumerate spanning forests within the selected topology.
Examples
Using the setup in the FeynmanDiagram class example:
forests = diagram.all_spanning_forests()all_bonds
Method#all_bonds(*, min_size: Optional[int] = None, max_size: Optional[int] = None) -> list[Subgraph] Enumerate minimal cutsets, independently of physical final-state cuts.
Examples
Using the setup in the FeynmanDiagram class example:
bonds = diagram.all_bonds(min_size=2, max_size=3)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
min_size | Optional[ | None | Minimum number of crossing edges. |
max_size | Optional[ | None | Maximum number of crossing edges. |
all_cuts
Method#all_cuts(source: Sequence[int], target: Sequence[int]) -> list[CutPartition] Enumerate separating partitions between disjoint interaction vertex groups.
Examples
Using the setup in the FeynmanDiagram class example:
partitions = diagram.all_cuts([0], [1])Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | Sequence[ | — | Diagram vertex IDs required on the first side. |
target | Sequence[ | — | Diagram vertex IDs required on the opposite side. |
depth_first_traverse
Method#depth_first_traverse(root: int, *, include: Optional[int] = None) -> TraversalTree Traverse a selected interaction region in depth-first order.
Examples
Using the setup in the FeynmanDiagram class example:
tree = diagram.depth_first_traverse(0)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
root | int | — | Diagram vertex ID at which traversal starts. |
include | Optional[ | None | Native diagram half-edge ID to prioritize at the root. |
breadth_first_traverse
Method#breadth_first_traverse(root: int, *, include: Optional[int] = None) -> TraversalTree Traverse a selected interaction region in breadth-first order.
Examples
Using the setup in the FeynmanDiagram class example:
tree = diagram.breadth_first_traverse(0)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
root | int | — | Diagram vertex ID at which traversal starts. |
include | Optional[ | None | Native diagram half-edge ID to prioritize at the root. |
from_json
Static method#from_json(model: Model, json: str) -> FeynmanDiagram Deserialize a Feynman diagram from its JSON representation.
Examples
Using the setup in the FeynmanDiagram class example:
encoded = diagram.to_json()
restored = hep.FeynmanDiagram.from_json(model, encoded)
restored.validate()
restored # render the recovered graph in a notebookParameters
from_dot
Static method#from_dot(model: Model, dot: str) -> FeynmanDiagram Parse a Feynman diagram from Graphviz DOT text.
Examples
Using the setup in the FeynmanDiagram class example:
dot = diagram.to_dot()
restored = hep.FeynmanDiagram.from_dot(model, dot)
restored.validate()
restored # preserve topology through a Graphviz workflowParameters
apply_feynman_rules
Method#apply_feynman_rules() -> FeynmanDiagramInstantiate the model's vertex and propagator Feynman rules.
Returns a new diagram whose local numerator fragments are built in the existing half-edge frame. Momentum routing, graph weights, numerator prefactors and the external-state projector are retained.
Examples
from symbolica.community import hepkit as hep
model = hep.Model.phi4()
diagram = hep.FeynmanDiagram.from_dot(model, '''digraph sunrise {
ext [style=invis];
ext -> a [particle="phi"];
a -> b [particle="phi"];
a -> b [particle="phi"];
a -> b [particle="phi"];
b -> ext [particle="phi"];
}''').apply_feynman_rules()
numerator = diagram.numerator_expression(in_lmb=True)from_dot_set
Static method#from_dot_set(model: Model, dot: str) -> list[FeynmanDiagram] Parse a document containing multiple Feynman diagrams in DOT format. Graphs are returned in document order and validated against the model.
Examples
Using the setup in the FeynmanDiagram class example:
dot = "\n".join(item.to_dot() for item in result.diagrams)
restored = hep.FeynmanDiagram.from_dot_set(model, dot)
len(restored) == len(result.diagrams)Parameters
overall_factor_expression
Method#overall_factor_expression(*, evaluate: bool = False) -> Expression Return the diagram-wide multiplicative factor as a Symbolica expression.
evaluate=True evaluates the generator's sign, multiplicity and symmetry annotations using the shared graph-factor evaluator. Other symbolic factors remain unchanged.
Examples
Using the setup in the FeynmanDiagram class example:
factor = diagram.overall_factor_expression()
weighted_numerator = factor * diagram.numerator_expression()
weighted_numeratorParameters
| Name | Type | Default | Description |
|---|---|---|---|
evaluate | bool | False | Evaluate known graph-factor annotations while preserving other symbols. |
denominator_expression
Method#denominator_expression(*, edge_powers: Optional[Mapping[int, int]] = None, dimension: Optional[Expression | int | Float | int | float | str | decimal.Decimal | ComplexFloat | Float | int | float | str | decimal.Decimal | complex | tuple[Float | int | float | str | decimal.Decimal, Float | int | float | str | decimal.Decimal]] = None, in_lmb: bool = False, lmb: Optional[LoopMomentumBasis] = None) -> TensorExpression Return the product of internal propagator denominators as a scalar TensorExpression.
Each factor retains GammaLoop's four-argument denom annotation around q_e² - m_e², with matching momentum labels and symbolic masses. Dimension defaults to GammaLoop's symbolic dimension; powers may be signed. The default region excludes external carriers and dummy edges. An explicit region follows GammaLoop and includes every complete selected edge. Widths, an imaginary prescription, and custom UFO denominator formulas are excluded. A selection without internal edges returns one.
Examples
Using the setup in the FeynmanDiagram class example:
denominator = diagram.denominator_expression(in_lmb=True)
integrand = diagram.numerator_expression(in_lmb=True) / denominator
basis = diagram.loop_momentum_bases()[0]
denominator = diagram.denominator_expression(lmb=basis)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
edge_powers | Optional[ | None | Signed propagator powers by diagram edge ID; omitted edges have power one. |
dimension | Optional[ | None | Lorentz dimension; defaults to the shared symbolic dimension. |
in_lmb | bool | False | Express edge momenta in the diagram's stored loop-momentum basis. |
lmb | Optional[ | None | Basis from this diagram instance. Supplying it enables routing and takes precedence over |
integral_family
Method#integral_family(independent_dot_products: Optional[Sequence[Expression]] = None, *, kinematics: Optional[Kinematics] = None) -> IntegralFamily Build a complete integral family with preferred or automatic ISPs.
Physical propagators retain their edge order and model masses. Preferred independent dot products are appended when they increase the rank; automatic scalar products fill any remaining directions. Auxiliary entries have zero powers in the original scalar integral. Equivalent to IntegralFamily.from_diagram(self, independent_dot_products, kinematics=kinematics). Tree diagrams and dependent propagators raise DiagramError. Use propagator_family() to extract dependent propagators for partial fractioning before completing their families.
Examples
Using the setup in the FeynmanDiagram class example:
family = diagram.integral_family()Parameters
| Name | Type | Default | Description |
|---|---|---|---|
independent_dot_products | Optional[ | None | Preferred auxiliary inverse propagators in the routed momenta. None selects a suitable basis automatically. |
kinematics | Optional[ | None | External assumptions and dimension; defaults to the diagram's symbolic dimension with no on-shell assumptions. |
propagator_family
Method#propagator_family(*, kinematics: Optional[Kinematics] = None) -> IntegralFamily Extract the physical propagators using the diagram's stored momentum routing.
Reuses the shared propagator builder and model masses. Denominators follow ascending internal edge IDs, as in internal_edges, retaining bridges and repeated propagators. Dependent external coordinates are eliminated; external carriers and dummy edges are excluded. Widths, prescriptions and custom UFO denominator formulas are not inferred. Tree diagrams raise DiagramError because they contain no loop integral. Use diagram.integral_family() to also complete the basis with automatic or explicitly chosen auxiliary scalar products.
Examples
Using the setup in the FeynmanDiagram class example:
family = diagram.propagator_family()
assert len(family.denominators) == len(diagram.internal_edges)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
kinematics | Optional[ | None | Assumptions on routed momentum names and the Lorentz dimension. None uses the shared symbolic dimension with no on-shell assumptions. |
numerator_expression
Method#numerator_expression(*, without: Subgraph | None = None, in_lmb: bool = False, lmb: Optional[LoopMomentumBasis] = None) -> TensorExpression Return the diagram numerator as a Spenso TensorExpression.
Examples
Using the setup in the FeynmanDiagram class example:
numerator = diagram.numerator_expression(in_lmb=True)
basis = diagram.loop_momentum_bases()[0]
numerator = diagram.numerator_expression(lmb=basis)
integrand_numerator = diagram.overall_factor_expression() * numerator
integrand_numerator # native Symbolica algebra and rich displayParameters
| Name | Type | Default | Description |
|---|---|---|---|
without | Subgraph | None | None | Ignored region, using GammaLoop boundary and local-factor selection semantics. |
in_lmb | bool | False | Express edge momenta in the diagram's stored loop-momentum basis. |
lmb | Optional[ | None | Basis from this diagram instance. Supplying it enables routing and takes precedence over |
uv_expansion
Method#uv_expansion(uv_mass: Expression | int | Float | int | float | str | decimal.Decimal | ComplexFloat | Float | int | float | str | decimal.Decimal | complex | tuple[Float | int | float | str | decimal.Decimal, Float | int | float | str | decimal.Decimal], *, dimension: int = 4, numerator: symbolica.Expression | symbolica.community.tensor.TensorExpression | None = None, edge_powers: Optional[Mapping[int, int]] = None) -> TensorExpression Expand the local integrand through its UV degree of divergence.
The selected region's loop momenta are scaled together. Propagators are expanded about the auxiliary mass uv_mass, retaining every power through logarithmic divergence in dimension spacetime dimensions. The result uses edge momenta and the same tagged denom convention as denominator_expression; the diagram is unchanged.
numerator optionally replaces the local numerator (in edge momenta), for example after contracting a projector. Overall factors, numerator prefactors and projectors remain separate unless supplied in it. edge_powers uses the signed powers of denominator_expression. Move rational propagator factors out of a prepared numerator into these powers so they receive the same auxiliary-mass expansion. Powers do not change the selected region or its loop integration measure. Empty, tree and UV-convergent regions return zero. This performs one UV limit; it does not enumerate forests or integrate the counterterm.
Examples
Using the setup in the FeynmanDiagram class example:
expanded = diagram.uv_expansion(0)
expansion = expanded # symbolic Taylor-expanded integrandParameters
| Name | Type | Default | Description |
|---|---|---|---|
uv_mass | Expression | int | Float | int | float | str | decimal. | — | Auxiliary mass used for the propagator expansion. |
dimension | int | 4 | Positive spacetime dimension for UV power counting; defaults to four. |
numerator | symbolica. | None | Prepared numerator in edge momenta; None uses the selected local numerator. |
edge_powers | Optional[ | None | Signed propagator powers by diagram edge ID; omitted edges have power one. Zero omits the denominator; negative powers put it in the numerator. Entries outside the selected internal edges are ignored. |
uv_counterterm
Method#uv_counterterm(uv_mass: Expression | int | Float | int | float | str | decimal.Decimal | ComplexFloat | Float | int | float | str | decimal.Decimal | complex | tuple[Float | int | float | str | decimal.Decimal, Float | int | float | str | decimal.Decimal], *, dimension: int = 4, numerator: symbolica.Expression | symbolica.community.tensor.TensorExpression | None = None, edge_powers: Optional[Mapping[int, int]] = None) -> TensorExpression Return the additive local UV counterterm, the negative of uv_expansion.
Arguments and selection semantics are those of uv_expansion. Add this unintegrated expression to the selected integrand to subtract its simultaneous UV limit. Subdivergences require separate forest terms.
Examples
Using the setup in the FeynmanDiagram class example:
from symbolica import S
mass = S("mUV", is_scalar=True)
counterterm = diagram.uv_counterterm(mass)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
uv_mass | Expression | int | Float | int | float | str | decimal. | — | Auxiliary mass used for the propagator expansion. |
dimension | int | 4 | Positive spacetime dimension for UV power counting; defaults to four. |
numerator | symbolica. | None | Prepared numerator in edge momenta; None uses the selected local numerator. |
edge_powers | Optional[ | None | Signed propagator powers by diagram edge ID; omitted edges have power one. Zero omits the denominator; negative powers put it in the numerator. Entries outside the selected internal edges are ignored. |
numerator_prefactor_expression
Method#numerator_prefactor_expression() -> TensorExpressionReturn the request-wide numerator multiplier with its tensor interface.
Examples
Using the setup in the FeynmanDiagram class example:
prefactor = diagram.numerator_prefactor_expression()
weighted_numerator = prefactor * diagram.numerator_expression()
weighted_numeratorprojector_expression
Method#projector_expression() -> TensorExpressionReturn the external-state projector with its tensor interface.
Examples
Using the setup in the FeynmanDiagram class example:
projector = diagram.projector_expression()
projected_numerator = projector * diagram.numerator_expression()
projected_numeratortensor_reduce
Method#tensor_reduce(dimension: Expression | int | Float | int | float | str | decimal.Decimal | ComplexFloat | Float | int | float | str | decimal.Decimal | complex | tuple[Float | int | float | str | decimal.Decimal, Float | int | float | str | decimal.Decimal], *, expression: symbolica.Expression | symbolica.community.tensor.TensorExpression | None = None, projector: symbolica.Expression | symbolica.community.tensor.TensorExpression | None = None) -> TensorExpression Reduce the numerator and projector using the diagram's internal edge momenta.
Four-dimensional Lorentz slots are promoted to D before reduction. External momenta remain projector vectors, and the scalar numerator prefactor remains separate. Requires at least one internal edge. A supplied expression replaces the numerator and projector, for example after a UV expansion; it must use the diagram's edge momentum names.
Examples
Using the setup in the FeynmanDiagram class example:
from symbolica import E
reduced = diagram.tensor_reduce(E("D"))Parameters
| Name | Type | Default | Description |
|---|---|---|---|
dimension | Expression | int | Float | int | float | str | decimal. | — | Lorentz dimension used for the reduction and four-dimensional input slots. |
expression | symbolica. | None | Complete prepared input to reduce instead of the numerator and projector. Cannot be combined with an explicit projector. |
projector | symbolica. | None | Explicit external tensor projector, required for partial regions unless expression is supplied. |
reduce_tensor_numerator
Method#reduce_tensor_numerator(reducer: TensorReducer) -> TensorExpressionReduce the finalized numerator and projector with a tensor reducer.
The result is a native Symbolica expression using spenso::dot and spenso::g. For a fully projected vacuum numerator, all Lorentz indices disappear and only scalar invariants remain. Residual free projector indices are preserved as metric tensors; use reduce_tensor_graphs when scalar graph contributions are required. The scalar numerator prefactor remains separate and is not included in this expression.
Examples
Reduce a vacuum graph after explicitly selecting its integrated momentum head:
from symbolica import S, E
from symbolica.community import hepkit as hep
model = hep.Model.phi4()
vacuum_diagram = model.process([], []).generate_diagrams(loops=2, factorized_loop_topologies_count_range=None).diagrams[0]
reducer = hep.TensorReducer(E("4"), integrated=[E("gammalooprs::Q")])
scalar_numerator = vacuum_diagram.reduce_tensor_numerator(reducer)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
reducer | TensorReducer | — | Tensor projector and integrated-momentum selection to apply. |
reduce_tensor_graphs
Method#reduce_tensor_graphs(reducer: TensorReducer) -> list[FeynmanDiagram] Split the tensor numerator into scalar contributions on this topology.
Each returned diagram has one compact reduction term as its numerator, including that term's exact projector coefficient. The graph topology, model, denominator data, and topology ID are preserved; deterministic .tensor[index] name suffixes distinguish the derived contributions. The external-state projector is consumed and reset to one, while the scalar numerator prefactor is retained. The projection must be fully contracted: any residual indexed Minkowski slot raises TensorReductionError. Use reduce_tensor_numerator when residual free Lorentz indices are intentional.
Examples
Construct scalar numerator graphs for a vacuum diagram:
from symbolica import S, E
from symbolica.community import hepkit as hep
model = hep.Model.phi4()
vacuum_diagram = model.process([], []).generate_diagrams(loops=2, factorized_loop_topologies_count_range=None).diagrams[0]
reducer = hep.TensorReducer(E("4"), integrated=[E("gammalooprs::Q")])
scalar_graphs = vacuum_diagram.reduce_tensor_graphs(reducer)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
reducer | TensorReducer | — | Tensor projector and integrated-momentum selection to apply. |
with_loop_momentum_edges
Method#with_loop_momentum_edges(edges: Sequence[int]) -> FeynmanDiagram Return a diagram using the specified loop-edge coordinates, in the supplied order.
Examples
Using the setup in the FeynmanDiagram class example:
rerouted = diagram.with_loop_momentum_edges(diagram.loop_momentum_basis.loop_edges)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
edges | Sequence[ | — | Diagram edge IDs specifying the requested routing coordinates. |
with_loop_momentum_tree_edges
Method#with_loop_momentum_tree_edges(edges: Sequence[int]) -> FeynmanDiagram Return a diagram whose momentum routing uses the specified spanning forest.
Examples
Using the setup in the FeynmanDiagram class example:
rerouted = diagram.with_loop_momentum_tree_edges(diagram.loop_momentum_basis.tree_edges)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
edges | Sequence[ | — | Diagram edge IDs specifying the requested routing coordinates. |
momentum_basis
Method#momentum_basis() -> LoopMomentumBasisConstruct the canonical routing of the selected interaction region.
Examples
Using the setup in the FeynmanDiagram class example:
basis = diagram.momentum_basis()
routed = basis.route_expression(diagram.numerator_expression())compatible_momentum_basis
Method#compatible_momentum_basis(parent: LoopMomentumBasis) -> LoopMomentumBasisReuse a parent basis's loop coordinates wherever the selected topology permits it.
Examples
Using the setup in the FeynmanDiagram class example:
basis = diagram.compatible_momentum_basis(diagram.loop_momentum_basis)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
parent | LoopMomentumBasis | — | Parent coordinates belonging to this same diagram instance. |
contracted_momentum_basis
Method#contracted_momentum_basis(contracted: Subgraph) -> LoopMomentumBasisRoute the selected region after contracting complete internal edges.
Examples
Using the setup in the FeynmanDiagram class example:
contracted = diagram.filter(edge=lambda edge: edge.is_dummy)
basis = diagram.contracted_momentum_basis(contracted)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
contracted | Subgraph | — | Complete internal edges to contract, selected from this diagram. |
superficial_degree_of_divergence
Method#superficial_degree_of_divergence(*, dimension: int = 4) -> int Return the local superficial UV degree of divergence.
Counts dimension * loops plus vertex momentum powers and internal propagator numerator powers minus two per internal propagator. Uses the stored local numerators; excludes external legs, projectors, and global prefactors. Vertex momenta scale together, before tensor cancellations. Zero is logarithmic, positive is power divergent, and negative is superficially convergent. Subdivergences are not tested.
Examples
Using the setup in the FeynmanDiagram class example:
degree = diagram.superficial_degree_of_divergence()
degree_in_six_dimensions = diagram.superficial_degree_of_divergence(dimension=6)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
dimension | int | 4 | Spacetime dimension for each loop integration measure; defaults to four. |
validate
Method#validate() -> NoneValidate particle and interaction references against a physics model.
Examples
Using the setup in the FeynmanDiagram class example:
Validation raises DiagramError for invalid particle or interaction references:
diagram.validate()to_json
Method#to_json() -> strSerialize the complete diagram to JSON text.
Examples
Using the setup in the FeynmanDiagram class example:
encoded = diagram.to_json()
restored = hep.FeynmanDiagram.from_json(model, encoded)
restored.validate()to_dot
Method#to_dot() -> strSerialize the diagram topology and annotations to Graphviz DOT text.
Examples
Using the setup in the FeynmanDiagram class example:
dot = diagram.to_dot()
restored = hep.FeynmanDiagram.from_dot(model, dot)
restored.validate()to_linnest
Method#to_linnest(*, config: Optional[RenderSettings] = None, style: Optional[DiagramStyle] = None, momenta: bool = False, lmb: Optional[LoopMomentumBasis] = None, highlight: Subgraph | None = None) -> str Export a self-contained Typst document embedding an outlined SVG.
Uses the same config, momenta, lmb and highlight settings as render. This explicit vector export uses the optional Python typst compiler to outline labels; compiling the exported source needs no Linnest, Kurvst, MiTeX, or model assets.
Examples
Using the setup in the FeynmanDiagram class example:
from pathlib import Path
Path("diagram.typ").write_text(diagram.to_linnest(momenta=True))Parameters
| Name | Type | Default | Description |
|---|---|---|---|
config | Optional[ | None | Layout, drawing, and graph style settings, as in |
style | Optional[ | None | Particle, momentum, and physical index presentation. |
momenta | bool | False | Draw momentum arrows and labels in the stored basis. |
lmb | Optional[ | None | Routing from this diagram; also enables momentum display. |
highlight | Subgraph | None | None | Region to highlight in the complete diagram. |
render
Method#render(*, config: Optional[RenderSettings] = None, style: Optional[DiagramStyle] = None, momenta: bool = False, lmb: Optional[LoopMomentumBasis] = None, highlight: Subgraph | None = None) -> DiagramView Prepare a browser-measured view using the shared physics renderer.
The notebook browser measures MathML labels and titles, then Rust draws graph geometry. LayoutSettings(impred_labels=True) refines the layout around those measurements. Scripts must supply measurements or explicitly select a browser with drawing.measured(browser="chromium") before export.
Examples
Using the setup in the FeynmanDiagram class example:
from symbolica.community.graph import LayoutSettings, RenderSettings
settings = RenderSettings(
layouts=LayoutSettings(impred_steps=100))
drawing = diagram.render(momenta=True, config=settings, style=hep.DiagramStyle(show_particle=False))
drawing
svg = drawing.measured(browser="chromium").to_svg()
drawing = diagram.render(lmb=next(iter(diagram.loop_momentum_bases())))Parameters
| Name | Type | Default | Description |
|---|---|---|---|
config | Optional[ | None | Immutable layout, styling, and physics overrides. Use |
style | Optional[ | None | Particle, momentum, and physical index presentation. |
momenta | bool | False | Show momentum arrows and labels routed in the diagram's stored basis. Explicit fields in |
lmb | Optional[ | None | Explicit routing from this diagram; also enables momentum display. Rendering never changes the diagram's stored loop-momentum basis. |
highlight | Subgraph | None | None | Highlight a region while preserving the full diagram as muted context. A Subgraph highlights its own region by default. |
to_html
Method#to_html(*, config: Optional[RenderSettings] = None, style: Optional[DiagramStyle] = None, momenta: bool = False, lmb: Optional[LoopMomentumBasis] = None, highlight: Subgraph | None = None, browser: Optional[str] = None) -> str Export a complete static HTML figure with the same options as render.
Examples
Using the setup in the FeynmanDiagram class example:
import marimo as mo
mo.iframe(diagram.to_html(momenta=True, browser="chromium"))Parameters
| Name | Type | Default | Description |
|---|---|---|---|
config | Optional[ | None | Layout, drawing, and graph style settings, as in |
style | Optional[ | None | Particle, momentum, and physical index presentation. |
momenta | bool | False | Draw momentum arrows and labels in the stored basis. |
lmb | Optional[ | None | Routing from this diagram; also enables momentum display. |
highlight | Subgraph | None | None | Region to highlight in the complete diagram. |
browser | Optional[ | None | Explicit headless browser for script exports; none is started implicitly. Defaults use a completed measurement, optional Typst, or estimated MathML label sizes. For exact notebook measurements, use |
_repr_mimebundle_
Method#_repr_mimebundle_(include: Optional[Sequence[str]] = None, exclude: Optional[Sequence[str]] = None) -> Any Render the diagram as HTML in Marimo, Jupyter, and IPython.
Examples
Using the setup in the FeynmanDiagram class example:
from IPython.display import display
display(diagram)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
include | Optional[ | None | MIME types requested by the frontend; None allows all available types. |
exclude | Optional[ | None | MIME types omitted from the frontend response. |
_mime_
Method#_mime_() -> AnyReturn Marimo MIME data for the browser-measured diagram view.
Examples
Using the setup in the FeynmanDiagram class example:
view = diagram.render(momenta=True)
view # notebook display measures labels before mounting the diagram
snapshot = view.measured(browser="chromium")_repr_pretty_
Method#_repr_pretty_(pretty: Any, cycle: bool) -> None Write a concise summary to an IPython pretty printer.
Examples
Using the setup in the FeynmanDiagram class example:
from IPython.lib.pretty import pretty
text = pretty(diagram)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
pretty | Any | — | The IPython pretty-printer object. |
cycle | bool | — | Whether this object is part of a recursive formatting cycle. |
loop_momentum_bases
Method#loop_momentum_bases(limit: Optional[int] = None) -> list[LoopMomentumBasis] Enumerate valid loop-momentum bases for this diagram.
Examples
Using the setup in the FeynmanDiagram class example:
Limit exploratory calculations to the first basis:
basis = diagram.loop_momentum_bases(limit=1)[0]
routing = {
edge_id: signature.format_momentum()
for edge_id, signature in basis.edge_signatures.items()
}Parameters
| Name | Type | Default | Description |
|---|---|---|---|
limit | Optional[ | None | Maximum number of bases to return. Pass |
__repr__
Method#__repr__() -> strReturn a concise description of the diagram and its loop count.
Examples
Using the setup in the FeynmanDiagram class example:
print(diagram)sector_decompose
Method#sector_decompose(*, regulator: symbolica.Expression, kinematics: Optional[Kinematics] = None, dimension: Optional[symbolica.Expression] = None, powers: Optional[Dict[int, int]] = None, numerator: None = None, scalar_values: Optional[Dict[symbolica.Expression, symbolica.Expression]] = None, auxiliary_momenta: Optional[Sequence[symbolica.Expression]] = None, measure_multiplier: Optional[symbolica.Expression] = None, max_order: int = 0, coefficient_expansion: str = 'physical', observer: Optional[Callable[[symbolica.community.hepkit.sector_decomposition.GenerationSnapshot], Optional[bool]]] = None, progress: Union[Literal["auto"], Callable[[symbolica.community.hepkit.sector_decomposition.GenerationSnapshot], Optional[bool]], None] = 'auto') -> symbolica.community.hepkit.sector_decomposition.GeneratedIntegral Generate Laurent integrands using the complete native diagram.
Examples
With a complete diagram and admitted numerical kinematics:
from symbolica import E, S
from symbolica.community import hepkit as hep
model = hep.Model.phi3()
diagram = model.process(["phi"], ["phi"]).generate_diagrams(loops=1, max_vertices=2, maximum_bridges=0, progress=None).diagrams[0]
from symbolica.community.hepkit.sector_decomposition import with_diagram_expressions
diagram = with_diagram_expressions(diagram, overall_factor=diagram.overall_factor_expression(evaluate=True))
eps, D = S("eps", "D")
P = hep.Kinematics.external_momentum()
point = hep.Kinematics(D, momenta=[P(0)]).with_scalar_product(P(0), P(0), E("-1"))
values = {model.particle("phi").mass: E("1"), model.parameter("g").symbol: E("1")}
generated = diagram.sector_decompose(regulator=eps, kinematics=point, scalar_values=values, progress=None)
kernels = generated.compile()Parameters
| Name | Type | Default | Description |
|---|---|---|---|
regulator | symbolica. | — | Dimensional regulator symbol. |
kinematics | Optional[ | None | Numerical external point retaining its symbolic tensor dimension. |
dimension | Optional[ | None | Integration dimension; defaults to 4 - 2*regulator. |
powers | Optional[ | None | Positive propagator powers by stable diagram edge ID. |
numerator | None | None | Use the diagram's numerator; explicit overrides are rejected. |
scalar_values | Optional[ | None | Explicit masses, couplings and invariant substitutions. |
auxiliary_momenta | Optional[ | None | Additional external vector heads, such as polarizations. |
measure_multiplier | Optional[ | None | Explicit multiplicative measure convention, applied once. |
max_order | int | 0 | Largest signed epsilon power retained. |
coefficient_expansion | str | 'physical' | Native physical or package coefficient convention. |
observer | Optional[ | None | Native generation events; False cancels at an event boundary. |
progress | Union[ | 'auto' | Automatic marimo display unless observer is supplied; None disables it. A callable receives every native event after observer and may cancel. |
View generated signature source: docs/api/python/feynkit-community.pyi:2847