finesse.graph.operator_graph.OperatorGraph
¶
Overview
- class finesse.graph.operator_graph.OperatorGraph(num_nodes)¶
Bases:
object
A class representing a graph of linear operators.
This class provides methods for creating, manipulating, and analyzing a graph of linear operators. The graph is represented using an adjacency list data structure, where each node represents a state and each edge represents a linear operator connecting two states.
- Parameters
- num_nodesint
The number of nodes in the graph.
- Attributes
- graphGraph
The underlying graph data structure.
- operator_indicesdict
A dictionary mapping operator names to their corresponding indices.
- indices_operator_namesdict
A dictionary mapping indices to their corresponding operator names.
Methods
_validate_node(node)
Validates if a given node index is within the valid range.
number_of_nodes()
Returns the number of nodes in the graph.
number_of_edges()
Returns the number of edges in the graph.
edges()
Returns an iterator over all edges in the graph.
output_edges(from_node)
Returns an iterator over the outgoing edges at a particular node.
input_edges(node)
Returns an iterator over the input edges at a particular node.
print_graph()
Prints the graph.
add_edge(name, from_node, to_node)
Adds an edge to the graph.
remove_edge(from_node, to_node)
Removes an edge from the graph.
get_edge_operator_expression(from_node, to_node)
Returns a list presentation of the operator expression associated with an edge.
number_of_self_loops()
Returns the number of self-loops in the graph.
nodes_with_self_loops()
Returns the nodes in the graph that have self-loops.
self_loop_edges()
Returns the edges in the graph that are self-loops.
has_self_loop(node)
Checks if a node has a self-loop.
in_degree(node)
Returns the in-degree of a node.
out_degree(node)
Returns the out-degree of a node.
fix_node(node, state)
Fixes a node to a specific state.
next_reducible_node()
Returns a node index that can be reduced
evaluation_nodes(ignore_self_loops)
Returns the nodes that have both inputs and outputs in the graph.
sum_rule(node)
Applies the sum reduction rule to a node.
split_rule(node)
Applies the split reduction rule to a node.
fan_rule(node)
Applies the fan reduction rule to a node.
series_rule(node)
Applies the series reduction rule to a node.
Properties
Get the nodes in the graph that have self-loops. |
|
Get the number of self-loops in the graph. |
|
Get the edges in the graph that are self-loops. |
Methods
|
|
|
Add an edge to the graph. |
|
An iterator over all edges |
|
Nodes that have both inputs and outputs in the graph. |
|
Apply the fan reduction rule to a node in the graph. |
Finds all paths between nodes which do not have any forks in. |
|
|
Fix a node to a specific state. |
Retrieves the operator expression associated with an edge between two nodes. |
|
|
Check if a node has a self-loop. |
|
Get the in-degree of a node. |
|
An iterator over the input edges at a particular node |
Nodes which have no input or output edges |
|
|
Keeps returning a node index if there is one that can be reduced. |
|
Get the out-degree of a node. |
|
An iterator over the outgoing edges at a particular node |
|
Plot the operator graph using Graphviz. |
|
Reduces the graph to as few evaluations nodes as possible. |
|
Remove an edge from the graph. |
|
Apply the series reduction rule to a node in the graph. |
|
Nodes which have no output edges |
|
Nodes which have no input edges |
|
Apply the split reduction rule to a node in the graph. |
|
Apply the sum reduction rule to a node in the graph. |
|
Convert the graph to a NetworkX MultiDiGraph. |