sft_wick.diagrams — Feynman Diagram Representation

Feynman diagram representation using networkx.

Each diagram is a MultiGraph where: - Nodes are either external points (observable fields) or interaction vertices - Edges are propagators (C or R)

class sft_wick.diagrams.FeynmanDiagram(graph=<factory>, _node_counter=0)[source]

Bases: object

Graph-based representation of a single Feynman diagram.

Parameters:
graph: MultiGraph
add_external_point(label, field_type, component=None, spatial='', full_label=None)[source]

Add an external point (observable field) to the diagram.

Parameters:
  • label (str) – Default display label for the node (typically a compact form like "$\phi_a$").

  • field_type (str) – "physical" or "response".

  • component (str | None) – Component index (None for scalar fields).

  • spatial (str) – Spatial argument string.

  • full_label (str | None) – Optional richer label that includes the spatial argument (e.g. "$\phi_a(x_1)$"). Stashed under the full_label node attribute so renderers can opt into it via the LABEL_FULL format flag. When None no full_label key is set (renderers fall back to label).

Returns:

The unique node ID assigned to this external point.

Return type:

str

add_vertex(coupling, copy_id=0, spatial_vars=())[source]

Add an interaction vertex to the diagram.

Parameters:
  • coupling (str) – Coupling constant name (e.g. "F", "g").

  • copy_id (int) – Which copy of the vertex in the expansion.

  • spatial_vars (Sequence[str]) – Spatial integration variables for this vertex.

Returns:

The unique node ID assigned to this vertex.

Return type:

str

add_propagator(node1, node2, kind, index_left=None, index_right=None, spatial_left='', spatial_right='', phi_end=None, psi_end=None)[source]

Add a propagator edge between two nodes.

Parameters:
  • node1 (str) – Source node ID.

  • node2 (str) – Target node ID.

  • kind (str) – "C" for correlation or "R" for response.

  • index_left (str | None) – Left component index (None for scalars).

  • index_right (str | None) – Right component index (None for scalars).

  • spatial_left (str) – Left spatial argument.

  • spatial_right (str) – Right spatial argument.

  • phi_end (str | None) – For R propagators, the node ID on the physical (φ) side. None for C propagators.

  • psi_end (str | None) – For R propagators, the node ID on the response (ψ) side. None for C propagators.

Return type:

None

Note

Arrow-direction convention for R propagators. An R edge R = ⟨φ ψ⟩ is directed: when rendered, the arrowhead points from the response (ψ) end to the physical (φ) end — i.e. the arrow lands on phi_end. This encodes the causal/retarded flow (a perturbation entering at the ψ leg produces the response at the φ leg). Both renderers honour this: DiagramRenderer (matplotlib) and TikzRenderer (TikZ). C propagators are undirected and carry no arrow.

property external_nodes: list[str]
property vertex_nodes: list[str]
property n_loops: int

Number of loops = E - V + connected_components.

property is_connected: bool
classmethod from_pairing(observable_ops, vertex_instances, pairing)[source]

Construct a diagram from a Wick contraction pairing.

Parameters:
Returns:

A fully-constructed FeynmanDiagram with external nodes, vertex nodes, and propagator edges.

Return type:

FeynmanDiagram

canonical_form()[source]

Return a hashable canonical form for this diagram’s topology.

Two diagrams have the same canonical form if and only if they are isomorphic under relabeling of vertex nodes that share the same coupling type. External nodes are distinguished by their position in the observable. Edge kind (C/R) and R-direction are structural; component indices and spatial arguments on edges are ignored.

Returns:

A hashable tuple (ext_meta, vert_meta, edges) that is identical for topologically equivalent diagrams.

Return type:

tuple

summary(short=False)[source]

Short textual description of the diagram topology.

Parameters:

short (bool) – If True, return a compact single-line summary suitable for subplot titles.

Return type:

str