topology

topology

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

KeyType

Type the keys of the Mapping, see KeysView.

alias of TypeVar(‘KeyType’, bound=Comparable)

ValueType

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: qrules.topology.FrozenDict[int, qrules.topology.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)
1
>>> 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)
3
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.

Parameters
  • 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]
EdgeType

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]