Subgraph

Symbolica documentation for getting started, symbolic expressions, numerical evaluation, pattern matching, and APIs in Python and Rust.

Subgraph

class Subgraph

A physics region retaining its immutable original Feynman diagram.

Construct with diagram.subgraph(...) or diagram.filter(...). Inherited physics operations use this selection, with original edge IDs and momentum coordinates. Display keeps the full original graph as muted context. excise() creates independent topology and routing when those are needed.

Examples

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]
region = diagram.filter(edge=lambda edge: not edge.data.is_external)
left = diagram.subgraph(nodes=[0])
right = diagram.subgraph(nodes=[1])
common = left & right
independent = region.excise()
independent.validate()

Attributes

Name Description
n_half_edges Return the number of selected half-edges, excluding isolated vertices.
original Return a full view of the immutable original diagram, sharing the same underlying diagram.

n_half_edges

Subgraph.n_half_edges: builtins.int

Return the number of selected half-edges, excluding isolated vertices.

Examples

Using the setup in the Subgraph class example:

assert region.n_half_edges == len(region.half_edge_indices())

original

Subgraph.original: FeynmanDiagram

Return a full view of the immutable original diagram, sharing the same underlying diagram.

Examples

Using the setup in the Subgraph class example:

assert region.original.id == diagram.id

Methods

Name Description
__and__ Intersect two regions belonging to the same original diagram.
__bool__ Test whether any half-edge or isolated vertex is selected.
__invert__ Complement the region relative to its immutable original diagram.
__len__ Count selected half-edges and explicitly selected isolated vertices.
__or__ Unite two regions belonging to the same original diagram.
__sub__ Remove the other region’s elements from this selection.
__xor__ Select elements present in exactly one of two regions.
excise Materialize an independent diagram with dangling legs at the region boundary
half_edge_indices Return canonical Linnet half-edge IDs of this region.
isolated_node_indices Return explicitly selected vertices with no incident half-edges.

__and__

Subgraph.__and__(other: FeynmanDiagram) -> Subgraph

Intersect two regions belonging to the same original diagram.

Examples

Using the setup in the Subgraph class example:

common = left & right

Parameters

  • other (FeynmanDiagram) Region or full diagram sharing this region’s immutable original.

__bool__

Subgraph.__bool__() -> builtins.bool

Test whether any half-edge or isolated vertex is selected.

Examples

Using the setup in the Subgraph class example:

nonempty = bool(region)

__invert__

Subgraph.__invert__() -> Subgraph

Complement the region relative to its immutable original diagram.

Examples

Using the setup in the Subgraph class example:

outside = ~region

__len__

Subgraph.__len__() -> builtins.int

Count selected half-edges and explicitly selected isolated vertices.

Examples

Using the setup in the Subgraph class example:

size = len(region)

__or__

Subgraph.__or__(other: FeynmanDiagram) -> Subgraph

Unite two regions belonging to the same original diagram.

Examples

Using the setup in the Subgraph class example:

combined = left | right

Parameters

  • other (FeynmanDiagram) Region or full diagram sharing this region’s immutable original.

__sub__

Subgraph.__sub__(other: FeynmanDiagram) -> Subgraph

Remove the other region’s elements from this selection.

Examples

Using the setup in the Subgraph class example:

remaining = left - right

Parameters

  • other (FeynmanDiagram) Region or full diagram sharing this region’s immutable original.

__xor__

Subgraph.__xor__(other: FeynmanDiagram) -> Subgraph

Select elements present in exactly one of two regions.

Examples

Using the setup in the Subgraph class example:

exclusive = left ^ right

Parameters

  • other (FeynmanDiagram) Region or full diagram sharing this region’s immutable original.

excise

Subgraph.excise() -> FeynmanDiagram

Materialize an independent diagram with dangling legs at the region boundary.

Complete interaction crowns are retained. Only selected internal pairs stay paired; remaining incident halves become boundary legs. Proper regions get independent momentum coordinates and unit global weights and projector. Excising the complete original preserves its factors, cuts and routing.

Examples

Using the setup in the Subgraph class example:

region = diagram.subgraph(nodes=[0])
independent = region.excise()
independent.validate()

half_edge_indices

Subgraph.half_edge_indices() -> builtins.list[builtins.int]

Return canonical Linnet half-edge IDs of this region.

Examples

Using the setup in the Subgraph class example:

selected_half_edges = region.half_edge_indices()
canonical = region.to_linnet().subgraph(half_edges=selected_half_edges)

isolated_node_indices

Subgraph.isolated_node_indices() -> builtins.list[builtins.int]

Return explicitly selected vertices with no incident half-edges.

Examples

Using the setup in the Subgraph class example:

isolated_vertices = region.isolated_node_indices()