topology
topology¶
import qrules.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
.
- KeyType¶
Type the keys of the
Mapping
, seeKeysView
.alias of TypeVar(‘KeyType’, bound=
Comparable
)
- ValueType¶
Type the value of the
Mapping
, seeValuesView
.alias of TypeVar(‘ValueType’)
- class FrozenDict(mapping: Optional[Mapping] = None)[source]¶
Bases:
Hashable
,Mapping
,Generic
[KeyType
,ValueType
]- 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
.
- 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 aTopology
is not strictly speaking a graph from graph theory, because it allows open edges, like a Feynman-diagram.- 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.
- organize_edge_ids() Topology [source]¶
Create a new topology with edge IDs in range
[-m, n+i]
.where
m
is the number ofincoming_edge_ids
,n
is the number ofoutgoing_edge_ids
, andi
is the number ofintermediate_edge_ids
.In other words, relabel the edges so that:
incoming_edge_ids
lies in the range[-1, -2, ...]
outgoing_edge_ids
lies in the range[0, 1, ..., n]
intermediate_edge_ids
lies in the range[n+1, n+2, ...]
- 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
- 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.
- class InteractionNode(number_of_ingoing_edges: int, number_of_outgoing_edges: int)[source]¶
Bases:
object
Helper class for the
SimpleStateTransitionTopologyBuilder
.
- 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.
- create_n_body_topology(number_of_initial_states: int, number_of_final_states: int) Topology [source]¶
- class StateTransitionGraph(topology: Topology, node_props: Mapping[int, InteractionProperties], edge_props: Mapping[int, EdgeType])[source]¶
-
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]¶
- 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]¶