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 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.

__eq__(other)

Method generated by attrs for class Edge.

ending_node_id: Optional[int]
get_connected_nodes() → Set[int][source]
originating_node_id: Optional[int]
EdgeType

A TypeVar representing the type of edge properties.

alias of TypeVar(‘EdgeType’)

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

Bases: object

Struct-like definition of an interaction node.

class SimpleStateTransitionTopologyBuilder(interaction_node_set: Sequence[expertsystem.reaction.topology.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_graphs(number_of_initial_edges: int, number_of_final_edges: int) → List[expertsystem.reaction.topology.Topology][source]
extend_graph(graph: Tuple[expertsystem.reaction.topology.Topology, Sequence[int]]) → List[Tuple[expertsystem.reaction.topology.Topology, List[int]]][source]
class StateTransitionGraph(topology: expertsystem.reaction.topology.Topology, node_props: Optional[Dict[int, expertsystem.reaction.quantum_numbers.InteractionProperties]] = None, edge_props: Optional[Dict[int, EdgeType]] = None)[source]

Bases: Generic[expertsystem.reaction.topology.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.

__eq__(other: object)bool[source]

Return self==value.

compare(other: expertsystem.reaction.topology.StateTransitionGraph, edge_comparator: Optional[Callable[[EdgeType, EdgeType], bool]] = None, node_comparator: Optional[Callable[[expertsystem.reaction.quantum_numbers.InteractionProperties, expertsystem.reaction.quantum_numbers.InteractionProperties], bool]] = None)bool[source]
property edges
evolve(node_props: Optional[Dict[int, expertsystem.reaction.quantum_numbers.InteractionProperties]] = None, edge_props: Optional[Dict[int, EdgeType]] = None)expertsystem.reaction.topology.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.

get_edge_ids_ingoing_to_node(node_id: int) → List[int][source]
get_edge_ids_outgoing_from_node(node_id: int) → List[int][source]
get_edge_props(edge_id: int)EdgeType[source]
get_final_state_edge_ids() → List[int][source]
get_initial_state_edge_ids() → List[int][source]
get_intermediate_state_edge_ids() → List[int][source]
get_node_props(node_id: int)expertsystem.reaction.quantum_numbers.InteractionProperties[source]
get_originating_node_list(edge_ids: Iterable[int]) → List[int][source]
property nodes
swap_edges(edge_id1: int, edge_id2: int)None[source]
class Topology(nodes: Optional[Set[int]] = None, edges: Optional[Mapping[int, expertsystem.reaction.topology.Edge]] = None)[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.

__eq__(other: object)bool[source]

Return self==value.

add_edges(edge_ids: List[int])None[source]

Add edges with the ids in the edge_ids list.

add_node(node_id: int)None[source]

Adds a node with id node_id.

Raises

ValueError – if node_id already exists

attach_edges_to_node_ingoing(ingoing_edge_ids: Iterable[int], node_id: int)None[source]

Attach existing edges to nodes.

So that the are ingoing to these nodes.

Parameters
  • ingoing_edge_ids ([int]) – list of edge ids, that will be attached

  • node_id (int) – id of the node to which the edges will be attached

Raises
  • ValueError – if an edge not doesn’t exist.

  • ValueError – if an edge ID is already an ingoing node.

attach_edges_to_node_outgoing(outgoing_edge_ids: Iterable[int], node_id: int)None[source]
property edges
get_edge_ids_ingoing_to_node(node_id: int) → List[int][source]
get_edge_ids_outgoing_from_node(node_id: int) → List[int][source]
get_final_state_edge_ids() → List[int][source]
get_initial_state_edge_ids() → List[int][source]
get_intermediate_state_edge_ids() → List[int][source]
get_originating_final_state_edge_ids(node_id: int) → List[int][source]
get_originating_initial_state_edge_ids(node_id: int) → List[int][source]
get_originating_node_list(edge_ids: Iterable[int]) → List[int][source]

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

Parameters

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

Returns

a list of node ids

Return type

[int]

is_isomorphic(other: expertsystem.reaction.topology.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.

Return type

bool

property nodes
swap_edges(edge_id1: int, edge_id2: int)None[source]
verify()None[source]

Verify if there are no dangling edges or nodes.