Skip to content

API Reference

Modules:

Name Description
feyngraph

A modern Feynman diagram generation toolkit.

topology
wolfram

Classes:

Name Description
Diagram

The Feynman diagram class.

DiagramContainer

A container of Feynman diagrams and accompanying information

DiagramGenerator

The main class used to generate Feynman diagrams.

DiagramSelector

A selector class which determines whether a diagram is to be kept or to be discarded. Multiple criteria can

InteractionVertex

Internal representaion of an interaction vertex.

Leg

The class representing an external leg.

Model

Internal representation of a model in FeynGraph.

Particle

Internal representation of a particle in FeynGraph.

Propagator

The class representing an internal propagator.

Topology

The internal representation of a topology graph.

TopologyModel

A model containing only topological information, i.e. the allowed degrees of nodes.

Vertex

The class representing an internal vertex.

Functions:

Name Description
generate_diagrams

Convenience function for diagram generation. This function only requires the minimal set of input information,

set_threads

Set the number of threads FeynGraph will use. The default is the maximum number of available threads.

Diagram

The Feynman diagram class.

Methods:

Name Description
bridges

Get a list of the bridge propagators.

chord

Get a list of the propagators belonging to the index-th loop.

draw_svg

Draw the diagram in SVG format and write the result to file

draw_tikz

Draw the diagram in TikZ (TikZiT) format and write the result to file

incoming

Get a list of the incoming legs.

loop_vertices

Get a list of the vertices beloning to the index-th loop.

n_ext

Get the number of external legs.

n_in

Get the number of incoming external legs.

n_out

Get the number of outgoing external legs.

outgoing

Get a list of the outgoing legs.

propagator

Get the propagator with index index.

propagators

Get a list of the internal propagators.

sign

Get the diagram's relative sign.

symmetry_factor

Get the diagram's symmetry factor.

vertex

Get the vertex with index index.

vertices

Get a list of the internal vertices.

bridges() -> list[Propagator]

Get a list of the bridge propagators.

chord(index: int) -> list[Propagator]

Get a list of the propagators belonging to the index-th loop.

draw_svg(file: str)

Draw the diagram in SVG format and write the result to file

draw_tikz(file: str)

Draw the diagram in TikZ (TikZiT) format and write the result to file

incoming() -> list[Leg]

Get a list of the incoming legs.

loop_vertices(index: int) -> list[Vertex]

Get a list of the vertices beloning to the index-th loop.

n_ext() -> int

Get the number of external legs.

n_in() -> int

Get the number of incoming external legs.

n_out() -> int

Get the number of outgoing external legs.

outgoing() -> list[Leg]

Get a list of the outgoing legs.

propagator(index: int) -> Propagator

Get the propagator with index index.

propagators() -> list[Propagator]

Get a list of the internal propagators.

sign() -> int

Get the diagram's relative sign.

symmetry_factor() -> int

Get the diagram's symmetry factor.

vertex(index: int) -> Vertex

Get the vertex with index index.

vertices() -> list[Vertex]

Get a list of the internal vertices.

DiagramContainer

A container of Feynman diagrams and accompanying information

Methods:

Name Description
__getitem__
__len__
draw

Draw the specified diagrams into a large canvas. Returns an SVG string, which can be displayed e.g. in a

query

Query whether there is a diagram in the container, which would be selected by selector.

__getitem__(index: int) -> Diagram

__len__() -> int

draw(diagrams: list[int], n_cols: Optional[int] = 4)

Draw the specified diagrams into a large canvas. Returns an SVG string, which can be displayed e.g. in a Jupyter notebook.

Example:

from from IPython.display import SVG
from feyngraph import generate_diagrams
diags = generate_diagrams(["u", "u~"], ["u", "u~"], 0)
SVG(topos.draw(range(len(diags))))

Parameters:

Name Type Description Default
diagrams list[int]

list of IDs of diagrams to draw

required
n_cols Optional[int]

number of topologies to draw in each row

4

query(selector: DiagramSelector) -> None | int

Query whether there is a diagram in the container, which would be selected by selector.

Returns:

Type Description
None | int

None if no diagram is selected, the position of the first selected diagram otherwise

DiagramGenerator

The main class used to generate Feynman diagrams.

Examples:

model = Model.from_ufo("tests/Standard_Model_UFO")
selector = DiagramSelector()
selector.set_opi_components(1)
diags = DiagramGenerator(["g", "g"], ["u", "u__tilde__", "g"], 1, model, selector).generate()
assert(len(diags), 51)

Methods:

Name Description
__new__

Create a new Diagram generator for the given process

assign_topologies

Assign particles and interactions to the given topologies.

assign_topology

Assign particles and interactions to the given topology.

count

Generate the diagrams of the given process without keeping them, only retaining the total number of found

generate

Generate the diagrams of the given process

set_momentum_labels

Set the names of the momenta. The first n_external ones are the external momenta, the remaining ones are

__new__(incoming: list[str], outgoing: list[str], n_loops: int, model: Model, selector: DiagramSelector | None = None) -> DiagramGenerator

Create a new Diagram generator for the given process

assign_topologies(topos: list[Topology]) -> DiagramContainer

Assign particles and interactions to the given topologies.

assign_topology(topo: Topology) -> DiagramContainer

Assign particles and interactions to the given topology.

count() -> int

Generate the diagrams of the given process without keeping them, only retaining the total number of found diagrams.

generate() -> DiagramContainer

Generate the diagrams of the given process

set_momentum_labels(labels: list[str])

Set the names of the momenta. The first n_external ones are the external momenta, the remaining ones are the loop momenta. Returns an error if the number of labels does not match the diagram.

DiagramSelector

A selector class which determines whether a diagram is to be kept or to be discarded. Multiple criteria can be specified. The available criteria are

  • opi components: select only diagrams for which the number of one-particle-irreducible components matches any of the given counts
  • custom functions: select only diagrams for which any of the given custom functions return true
  • self loops: select only diagrams which contain the specified number of self-loops
  • on-shell: select only diagrams with on-shell external legs
  • coupling powers: select only diagrams of the given power in the given coupling
  • propagator count: select only diagrams with the specified number of propagators of the given field
  • vertex count: select only diagrams with the specified number of vertices with the given fields

For more precise definitions of each criterion, see the respective function.

Examples:

selector = DiagramSelector()
selector.select_on_shell()
selector.select_self_loops(0)
selector.add_coupling_power("QCD", 2)
selector.add_coupling_power("QED", 0)
selector.add_propagator_count("t", 0)

Methods:

Name Description
add_custom_function

Add a constraint to only select diagrams for which the given function returns true. The function receives

add_topology_function

Add a custom topology selection function, which is used when the DiagramSelector is converted to a

select_coupling_power

Add a constraint to only select diagrams for which the power of coupling sums to power.

select_on_shell

Add a constraint to only select on-shell diagrams. On-shell diagrams are defined as diagrams with no self-energy

select_opi_components

Add a constraint to only select diagrams with opi_count one-particle-irreducible components.

select_propagator_count

Add a constraint to only select diagrams which contain exactly count propagators of the field particle.

select_self_loops

Add a constraint to only select diagrams with count self-loops. A self-loop is defined as an edge which ends

select_vertex_count

Add a constraint to only select diagrams which contain exactly count vertices of the fields particles.

select_vertex_degree

Add a criterion to only keep diagrams which contains count vertices of degree degree.

add_custom_function(py_function: Callable[[Diagram], bool])

Add a constraint to only select diagrams for which the given function returns true. The function receives a single diagrams as input and should return a boolean.

Examples:

def s_channel(diag: feyngraph.Diagram) -> bool:
    n_momenta = len(diag.propagators()[0].momentum()) # Total number of momenta in the process
    s_momentum = [1, 1]+ [0]*(n_momenta-2) # e.g. = [1, 1, 0, 0] for n_momenta = 4
    return any(propagator.momentum() == s_momentum for propagator in diag.propagators())

selector = feyngraph.DiagramSelector()
selector.add_custom_function(s_channel)

add_topology_function(py_function: Callable[[Topology], bool])

Add a custom topology selection function, which is used when the DiagramSelector is converted to a TopologySelector, e.g. when a DiagramGenerator automatically generates topologies.

select_coupling_power(coupling: str, power: int)

Add a constraint to only select diagrams for which the power of coupling sums to power.

select_on_shell()

Add a constraint to only select on-shell diagrams. On-shell diagrams are defined as diagrams with no self-energy insertions on external legs. This implementation considers internal edges carrying a single external momentum and no loop momentum, which is equivalent to a self-energy insertion on an external propagator.

select_opi_components(opi_count: int)

Add a constraint to only select diagrams with opi_count one-particle-irreducible components.

select_propagator_count(particle: str, count: int)

Add a constraint to only select diagrams which contain exactly count propagators of the field particle.

select_self_loops(count: int)

Add a constraint to only select diagrams with count self-loops. A self-loop is defined as an edge which ends on the same node it started on.

select_vertex_count(particles: list[str], count: int)

Add a constraint to only select diagrams which contain exactly count vertices of the fields particles.

select_vertex_degree(degree: int, count: int)

Add a criterion to only keep diagrams which contains count vertices of degree degree.

InteractionVertex

Internal representaion of an interaction vertex.

Methods:

Name Description
coupling_orders

Get a list of coupling orders of the interaction.

name

Get the name of the interaction vertex.

coupling_orders()

Get a list of coupling orders of the interaction.

name()

Get the name of the interaction vertex.

Leg

The class representing an external leg.

Methods:

Name Description
id

Get the leg's internal id

momentum

Get the internal representation of the propagator's momentum. The function returns a list of integers, where

momentum_str

Get the string-formatted momentum flowing through the propagator.

particle

Get the particle assigned to this leg.

ray_index

Get the external leg's ray index, i.e. the index of the leg of the vertex to which the external leg is

vertex

Get the vertex this leg is attached to. This function accepts an addition _index parameter to make its

id() -> int

Get the leg's internal id

momentum() -> list[int]

Get the internal representation of the propagator's momentum. The function returns a list of integers, where the i-th entry is the coefficient of the i-th momentum. The first n_ext momenta are external, the remaining momenta are the n_loops loop momenta.

momentum_str() -> str

Get the string-formatted momentum flowing through the propagator.

particle() -> Particle

Get the particle assigned to this leg.

ray_index(_vertex: int = 0) -> int

Get the external leg's ray index, i.e. the index of the leg of the vertex to which the external leg is connected to (from the vertex perspective). This function accepts an addition _vertex parameter to make its signature identical to Propagator.ray_index, but the parameter is always ignored.

vertex(_index: int = 0) -> Vertex

Get the vertex this leg is attached to. This function accepts an addition _index parameter to make its signature identical to Propagator.index, but the parameter is always ignored.

Model

Internal representation of a model in FeynGraph.

Methods:

Name Description
__new__

Construct the default mode, the Standard Model in Feynman gauge.

as_topology_model

Return the topology model dervied from the model.

from_qgraf

Import a model in QGRAF's model format. The parser is not exhaustive in the options QGRAF supports and is only

from_ufo

Import a model in the UFO format. The path should specify the folder containing the model's .py files.

particles

Return the list of particles contained in the model.

vertices

Return the list of vertices contained in the model.

__new__() -> Model

Construct the default mode, the Standard Model in Feynman gauge.

as_topology_model() -> TopologyModel

Return the topology model dervied from the model.

from_qgraf(path: str) -> Model staticmethod

Import a model in QGRAF's model format. The parser is not exhaustive in the options QGRAF supports and is only intended for backwards compatibility, especially for the models included in GoSam. UFO models should be preferred whenever possible.

from_ufo(path: str) -> Model staticmethod

Import a model in the UFO format. The path should specify the folder containing the model's .py files.

particles() -> list[Particle]

Return the list of particles contained in the model.

vertices() -> list[InteractionVertex]

Return the list of vertices contained in the model.

Particle

Internal representation of a particle in FeynGraph.

Methods:

Name Description
anti_name

Get the name of the particle's anti particle

is_anti

Return true, if the particle is an anti particle (PDG ID < 0)

is_fermi

Return true if the particle obeys Fermi-Dirac statistics

name

Get the particle's name

pdg

Get the particle's PDG ID

anti_name() -> str

Get the name of the particle's anti particle

is_anti() -> bool

Return true, if the particle is an anti particle (PDG ID < 0)

is_fermi() -> bool

Return true if the particle obeys Fermi-Dirac statistics

name() -> str

Get the particle's name

pdg() -> int

Get the particle's PDG ID

Propagator

The class representing an internal propagator.

Methods:

Name Description
id

Get the propagagtors internal id

momentum

Get the internal representation of the propagator's momentum. The function returns a list of integers, where

momentum_str

Get the string-formatted momentum flowing through the propagator.

particle

Get the particle assigned to the propagator.

ray_index

Get the propagators ray index with respect to the index-th vertex it is connected to, i.e. the index of the

vertex

Get the index-th vertex the propagator is connected to.

vertices

Get a list of vertices the propagator is connected to.

id() -> int

Get the propagagtors internal id

momentum() -> list[int]

Get the internal representation of the propagator's momentum. The function returns a list of integers, where the i-th entry is the coefficient of the i-th momentum. The first n_ext momenta are external, the remaining momenta are the n_loops loop momenta.

momentum_str() -> str

Get the string-formatted momentum flowing through the propagator.

particle() -> Particle

Get the particle assigned to the propagator.

ray_index(index: int) -> int

Get the propagators ray index with respect to the index-th vertex it is connected to, i.e. the index of the leg of the index-th vertex to which the propagator is connected to.

vertex(index: int) -> Vertex

Get the index-th vertex the propagator is connected to.

vertices() -> list[Vertex]

Get a list of vertices the propagator is connected to.

Topology

The internal representation of a topology graph.

Methods:

Name Description
draw_tikz

Draw the topology in the TikZ format

edges

Get a list of all nodes in the topology.

nodes

Get a list of all edges in the topology.

symmetry_factor

Get the topology's symmetry factor

draw_tikz(path: str)

Draw the topology in the TikZ format

edges() -> list[Edge]

Get a list of all nodes in the topology.

nodes() -> list[Node]

Get a list of all edges in the topology.

symmetry_factor() -> int

Get the topology's symmetry factor

TopologyModel

A model containing only topological information, i.e. the allowed degrees of nodes.

Methods:

Name Description
__new__

Create a new topology model containing nodes with degrees specified in node_degrees.

__new__(node_degrees: list[int]) -> TopologyModel

Create a new topology model containing nodes with degrees specified in node_degrees.

Vertex

The class representing an internal vertex.

Methods:

Name Description
degree

Get the vertex' degree

id

Get the vertex' internal id

interaction

Get the interaction assigned to the vertex.

match_particles

Check whether the given particle names match the interaction of the vertex.

particles_ordered

Get the particles flowing into this vertex ordered such, that the sequence of particles matches the

propagators

Get the propagators connected to this vertex. If one of the propagators is a self-loop, it will only

propagators_ordered

Get the propagators connected to this vertex ordered such, that the sequence of particles matches the

degree() -> int

Get the vertex' degree

id() -> int

Get the vertex' internal id

interaction() -> InteractionVertex

Get the interaction assigned to the vertex.

match_particles() -> bool

Check whether the given particle names match the interaction of the vertex.

particles_ordered() -> list[Particle]

Get the particles flowing into this vertex ordered such, that the sequence of particles matches the definition of the interaction in the model.

propagators() -> list[Leg | Propagator]

Get the propagators connected to this vertex. If one of the propagators is a self-loop, it will only appear once in the list of propagators!

propagators_ordered() -> list[Leg | Propagator]

Get the propagators connected to this vertex ordered such, that the sequence of particles matches the definition of the interaction in the model. If one of the propagators is a self-loop, it will only appear once in the list of propagators!

generate_diagrams(particles_in: list[str], particles_out: list[str], n_loops: int, model: Optional[Model] = None, selector: Optional[DiagramSelector] = None) -> DiagramContainer

Convenience function for diagram generation. This function only requires the minimal set of input information, the incoming particles and the outgoing particles. Sensible defaults are provided for all other variables.

Examples:

import feyngraph as fg
diagrams = fg.generate_diagrams(["u", "u__tilde__"], ["u", "u__tilde"], 2)
assert(len(diagrams), 4632)

Parameters:

Name Type Description Default
particles_in list[str]

list of incoming particles, specified by name

required
particles_out list[str]

list of outgoing particles, specified by name

required
n_loops int

number of loops in the generated diagrams [default: 0]

required
model Optional[Model]

model used in diagram generation [default: SM in Feynman gauge]

None
selector Optional[DiagramSelector]

selector struct determining which diagrams are to be kept [default: all diagrams for zero loops, only one-particle-irreducible diagrams for loop-diagrams]

None

set_threads(n_threads: int)

Set the number of threads FeynGraph will use. The default is the maximum number of available threads.

Parameters:

Name Type Description Default
n_threads int

Number of threads to use (shared across all instanced of FeynGraph running for the current process)

required