All modules related to topology building.

Responsible for building all possible topologies bases on basic user input:

  • number of initial state particles

  • number of final state particles

The main interface is the StateTransitionGraph.

class Comparable(*args, **kwargs)[source]#

Bases: Protocol


Type the keys of the Mapping, see KeysView.

alias of TypeVar(β€˜KeyType’, bound=Comparable)


Type the value of the Mapping, see ValuesView.

alias of TypeVar(β€˜ValueType’)

class FrozenDict(mapping: Optional[Mapping] = None)[source]#

Bases: Hashable, Mapping, Generic[KeyType, ValueType]

__getitem__(key: KeyType) β†’ ValueType[source]#
keys() β†’ typing.KeysView[source]#
items() β†’ typing.ItemsView[source]#
values() β†’ typing.ValuesView[source]#
class Edge(originating_node_id: Optional[int] = None, ending_node_id: Optional[int] = None)[source]#

Bases: object

Struct-like definition of an edge, used in Topology.

originating_node_id: Optional[int]#
ending_node_id: Optional[int]#
get_connected_nodes() β†’ Set[int][source]#
class Topology(nodes: Iterable[int], edges)[source]#

Bases: object

Directed Feynman-like graph without edge or node properties.

Forms the underlying topology of StateTransitionGraph. The graphs are directed, meaning the edges are ingoing and outgoing to specific nodes (since feynman graphs also have a time axis). Note that a Topology is not strictly speaking a graph from graph theory, because it allows open edges, like a Feynman-diagram.

nodes: FrozenSet[int]#
edges: FrozenDict[int, Edge]#
incoming_edge_ids: FrozenSet[int]#
outgoing_edge_ids: FrozenSet[int]#
intermediate_edge_ids: FrozenSet[int]#
is_isomorphic(other: Topology) β†’ bool[source]#

Check if two graphs are isomorphic.

Returns True if the two graphs have a one-to-one mapping of the node IDs and edge IDs.

get_edge_ids_ingoing_to_node(node_id: int) β†’ Set[int][source]#
get_edge_ids_outgoing_from_node(node_id: int) β†’ Set[int][source]#
get_originating_final_state_edge_ids(node_id: int) β†’ Set[int][source]#
get_originating_initial_state_edge_ids(node_id: int) β†’ Set[int][source]#
organize_edge_ids() β†’ Topology[source]#

Create a new topology with edge IDs in range [-m, n+i].

where m is the number of incoming_edge_ids, n is the number of outgoing_edge_ids, and i is the number of intermediate_edge_ids.

In other words, relabel the edges so that:

relabel_edges(old_to_new_id: Mapping[int, int]) β†’ Topology[source]#

Create a new Topology with new edge IDs.

This method is particularly useful when creating permutations of a Topology, e.g.:

>>> topologies = create_isobar_topologies(3)
>>> len(topologies)
>>> topology = topologies[0]
>>> final_state_ids = topology.outgoing_edge_ids
>>> permuted_topologies = {
...     topology.relabel_edges(dict(zip(final_state_ids, permutation)))
...     for permutation in itertools.permutations(final_state_ids)
... }
>>> len(permuted_topologies)
swap_edges(edge_id1: int, edge_id2: int) β†’ Topology[source]#
get_originating_node_list(topology: Topology, edge_ids: Iterable[int]) β†’ List[int][source]#

Get list of node ids from which the supplied edges originate from.

  • topology – The Topology on which to perform the search.

  • edge_ids ([int]) – A list of edge ids for which the origin node is searched for.

class InteractionNode(number_of_ingoing_edges: int, number_of_outgoing_edges: int)[source]#

Bases: object

Helper class for the SimpleStateTransitionTopologyBuilder.

number_of_ingoing_edges: int#
number_of_outgoing_edges: int#
class SimpleStateTransitionTopologyBuilder(interaction_node_set: Iterable[InteractionNode])[source]#

Bases: object

Simple topology builder.

Recursively tries to add the interaction nodes to available open end edges/lines in all combinations until the number of open end lines matches the final state lines.

build(number_of_initial_edges: int, number_of_final_edges: int) β†’ Tuple[Topology, ...][source]#
create_isobar_topologies(number_of_final_states: int) β†’ Tuple[Topology, ...][source]#
create_n_body_topology(number_of_initial_states: int, number_of_final_states: int) β†’ Topology[source]#

A TypeVar representing the type of edge properties.

alias of TypeVar(β€˜EdgeType’)

class StateTransitionGraph(topology: Topology, node_props: Mapping[int, InteractionProperties], edge_props: Mapping[int, EdgeType])[source]#

Bases: Generic[EdgeType]

Graph class that resembles a frozen Topology with properties.

This class should contain the full information of a state transition from a initial state to a final state. This information can be attached to the nodes and edges via properties. In case not all information is provided, error can be raised on property retrieval.

get_node_props(node_id: int) β†’ InteractionProperties[source]#
get_edge_props(edge_id: int) β†’ EdgeType[source]#
evolve(node_props: Optional[Dict[int, InteractionProperties]] = None, edge_props: Optional[Dict[int, EdgeType]] = None) β†’ StateTransitionGraph[EdgeType][source]#

Changes the node and edge properties of a graph instance.

Since a StateTransitionGraph is frozen (cannot be modified), the evolve function will also create a shallow copy the properties.

compare(other: StateTransitionGraph, edge_comparator: Optional[Callable[[EdgeType, EdgeType], bool]] = None, node_comparator: Optional[Callable[[InteractionProperties, InteractionProperties], bool]] = None) β†’ bool[source]#
swap_edges(edge_id1: int, edge_id2: int) β†’ None[source]#