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 representation 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 |
color_tadpole |
Check whether loop |
count_particles |
Count the number of propagators in the diagram for which the particle name is in |
count_vertices |
Count the number of vertices in the diagram for which the interaction matches |
draw_svg |
Draw the diagram in SVG format and write the result to |
draw_tikz |
Draw the diagram in TikZ (TikZiT) format and write the result to |
incoming |
Get a list of the incoming legs. |
loop_vertices |
Get a list of the vertices beloning to the |
loopsize |
Get the number of propagators belonging to the |
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. |
order |
Get the order of the diagram in the given coupling. |
orders |
Returns the index of the first diagram for which |
outgoing |
Get a list of the outgoing legs. |
propagator |
Get the propagator with 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 |
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.
color_tadpole(index: int) -> bool
¶
Check whether loop index is a color tadpole, i.e. only a single colored propagator is attached to this loop.
count_particles(particles: list[str]) -> int
¶
Count the number of propagators in the diagram for which the particle name is in particles.
count_vertices(particles: list[str]) -> int
¶
Count the number of vertices in the diagram for which the interaction matches particles. '_' can be used as
a wildcard, matching every particle.
draw_svg(file: str) -> None
¶
Draw the diagram in SVG format and write the result to file
draw_tikz(file: str) -> None
¶
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.
loopsize(index: int) -> int
¶
Get the number of propagators belonging 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.
order(coupling: str) -> int
¶
Get the order of the diagram in the given coupling.
orders() -> dict[str, int]
¶
Returns the index of the first diagram for which f returns true, or None if all diagrams return false.
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 |
query_function |
Query whether there is a diagram in the container, for which |
__getitem__(index: int) -> Diagram
¶
__len__() -> int
¶
draw(diagrams: list[int], n_cols: Optional[int] = 4) -> None
¶
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 |
query_function(f: Callable[[Diagram], bool]) -> None | int
¶
Query whether there is a diagram in the container, for which f returns True.
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 |
__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]) -> None
¶
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 |
add_topology_function |
Add a custom topology selection function, which is used when the |
select_coupling_power |
Add a constraint to only select diagrams for which the power of |
select_coupling_power_list |
Add a constraint to only select diagrams for which the power of |
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 |
select_propagator_count |
Add a constraint to only select diagrams which contain exactly |
select_self_loops |
Add a constraint to only select diagrams with |
select_tadpoles |
Add a criterion to only keep diagrams with |
select_vertex_count |
Add a constraint to only select diagrams which contain exactly |
select_vertex_degree |
Add a criterion to only keep diagrams which contains |
add_custom_function(py_function: Callable[[Diagram], bool]) -> None
¶
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]) -> None
¶
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) -> None
¶
Add a constraint to only select diagrams for which the power of coupling sums to power.
select_coupling_power_list(coupling: str, powers: list[int]) -> None
¶
Add a constraint to only select diagrams for which the power of coupling sums to any of the values given in powers.
select_on_shell() -> None
¶
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) -> None
¶
Add a constraint to only select diagrams with opi_count one-particle-irreducible components.
select_propagator_count(particle: str, count: int) -> None
¶
Add a constraint to only select diagrams which contain exactly count propagators of the field particle.
select_self_loops(count: int) -> None
¶
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_tadpoles(count: int) -> None
¶
Add a criterion to only keep diagrams with count tadpoles. A tadpole is defined as a subdiagram without any
external legs connected to the remaining vertices only by a single propagator carrying no momentum.
select_vertex_count(particles: list[str], count: int) -> None
¶
Add a constraint to only select diagrams which contain exactly count vertices of the fields particles.
select_vertex_degree(degree: int, count: int) -> None
¶
Add a criterion to only keep diagrams which contains count vertices of degree degree.
InteractionVertex
¶
Internal representation 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. |
order |
Get the vertex' order in the coupling |
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 |
ray_index_ordered |
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 |
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.
ray_index_ordered(_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. The ray index is given with
respect to the propagators ordered as in the interaction vertex.
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. |
add_coupling |
Add a new coupling to the interaction vertex |
add_particle |
Add a new particle with the given properties to the model or overwrite an existing one. If |
add_vertex |
Add a new vertex with the given properties to the model or overwrite an existing one. The |
as_topology_model |
Return the topology model derived from the model. |
empty |
Create a new model without any particles, vertices or couplings. |
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 |
merge_vertices |
Deduplicate vertices in the model, i.e. merge all vertices with identical particles, spin connection and |
particles |
Return the list of particles contained in the model. |
split_vertex |
Split the existing vertex |
splitting |
Get the splitting of the original vertex |
vertices |
Return the list of vertices contained in the model. |
__new__() -> Model
¶
Construct the default mode, the Standard Model in Feynman gauge.
add_coupling(vertex: str, coupling: str, power: int) -> None
¶
Add a new coupling to the interaction vertex vertex or overwrite an existing one.
add_particle(name: str, anti_name: str, spin: int, color: int, pdg_id: int, texname: str, antitexname: str, linestyle: str, fermi: bool) -> None
¶
Add a new particle with the given properties to the model or overwrite an existing one. If name == anti_name,
the particle is automatically marked as its own anti particle. Otherwise, the corresponding anti particle is
automatically also added to the model.
The available options for linestyle are dashed, dotted, straight, wavy, curly, scurly, swavy,
double and none.
add_vertex(name: str, particles: list[str], spin_map: list[int], coupling_orders: dict[str, int]) -> None
¶
Add a new vertex with the given properties to the model or overwrite an existing one. The i-th entry of the
spin_map must be the leg j to which leg i is spin-connected.
as_topology_model() -> TopologyModel
¶
Return the topology model derived from the model.
empty() -> Model
staticmethod
¶
Create a new model without any particles, vertices or couplings.
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.
merge_vertices() -> dict[str, list[str]]
¶
Deduplicate vertices in the model, i.e. merge all vertices with identical particles, spin connection and coupling powers. Returns a hash map containing the new vertex and all vertices which were merged into it.
particles() -> list[Particle]
¶
Return the list of particles contained in the model.
split_vertex(vertex: str, new_vertices: list[str]) -> None
¶
Split the existing vertex vertex into new vertices with names new_vertices.
splitting(name: str) -> None | dict[str, list[tuple[int, int]]]
¶
Get the splitting of the original vertex name. Returns None if the requested vertex was not split up or
does not exist in the model. If it was split, a dict containing the vertices into which it was split is
returned. For each vertex, the dict contains a list of the (color_index, lorentz_index) tuples assigned
to the created vertex.
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 |
color |
Get the size of the particle's color representation. |
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 |
spin |
Get \(2s\), where \(s\) is the particle's spin. |
anti_name() -> str
¶
Get the name of the particle's anti particle
color() -> int
¶
Get the size of the particle's color representation.
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
spin() -> int
¶
Get \(2s\), where \(s\) is the particle's spin.
Propagator
¶
The class representing an internal propagator.
Methods:
| Name | Description |
|---|---|
id |
Get the propagagtors internal id |
invert |
Get an inverted version of the propagator. |
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. |
normalize |
Normalize the propagator, i.e. get an inverted version of it if it carries an anti particle. |
particle |
Get the particle assigned to the propagator. |
ray_index |
Get the propagators ray index with respect to the |
ray_index_ordered |
Get the propagators ray index with respect to the |
vertex |
Get the |
vertices |
Get a list of vertices the propagator is connected to. |
id() -> int
¶
Get the propagagtors internal id
invert() -> Self
¶
Get an inverted version of the propagator.
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.
normalize() -> Self
¶
Normalize the propagator, i.e. get an inverted version of it if it carries an anti particle.
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.
ray_index_ordered(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. The ray index is given with respect to
the propagators ordered as in the interaction vertex.
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 |
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 |
__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_particle_combinations |
Same as |
match_particles |
Check whether the given particle names match the interaction of the vertex. "_" can be used as a wildcard to |
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_particle_combinations(query: list[list[str]]) -> bool
¶
Same as match_particles, but multiple particles can be specified per query entry.
match_particles(query: list[str]) -> bool
¶
Check whether the given particle names match the interaction of the vertex. "_" can be used as a wildcard to match all particles.
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) -> None
¶
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 |