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

OperatorGraph.nodes_with_self_loops

Get the nodes in the graph that have self-loops.

OperatorGraph.number_of_edges

OperatorGraph.number_of_nodes

OperatorGraph.number_of_self_loops

Get the number of self-loops in the graph.

OperatorGraph.self_loop_edges

Get the edges in the graph that are self-loops.

Methods

OperatorGraph.__init__(*args, **kwargs)

OperatorGraph.add_edge(self, unicode name, ...)

Add an edge to the graph.

OperatorGraph.edges(self)

An iterator over all edges

OperatorGraph.evaluation_nodes(self[, ...])

Nodes that have both inputs and outputs in the graph.

OperatorGraph.fan_rule(self, node)

Apply the fan reduction rule to a node in the graph.

OperatorGraph.find_forkless_paths(self)

Finds all paths between nodes which do not have any forks in.

OperatorGraph.fix_node(self, int node, ...)

Fix a node to a specific state.

OperatorGraph.get_edge_operator_expression(...)

Retrieves the operator expression associated with an edge between two nodes.

OperatorGraph.has_self_loop(self, node)

Check if a node has a self-loop.

OperatorGraph.in_degree(self, node)

Get the in-degree of a node.

OperatorGraph.input_edges(self, node)

An iterator over the input edges at a particular node

OperatorGraph.isolated_nodes(self)

Nodes which have no input or output edges

OperatorGraph.next_reducible_node(self[, keep])

Keeps returning a node index if there is one that can be reduced.

OperatorGraph.out_degree(self, node)

Get the out-degree of a node.

OperatorGraph.output_edges(self, from_node)

An iterator over the outgoing edges at a particular node

OperatorGraph.plot(self[, graphviz_prog, ...])

Plot the operator graph using Graphviz.

OperatorGraph.print_graph(self)

OperatorGraph.reduce(self[, keep, reductions])

Reduces the graph to as few evaluations nodes as possible.

OperatorGraph.remove_edge(self, from_node, ...)

Remove an edge from the graph.

OperatorGraph.series_rule(self, node)

Apply the series reduction rule to a node in the graph.

OperatorGraph.sink_nodes(self[, ...])

Nodes which have no output edges

OperatorGraph.source_nodes(self[, ...])

Nodes which have no input edges

OperatorGraph.split_rule(self, node)

Apply the split reduction rule to a node in the graph.

OperatorGraph.sum_rule(self, node)

Apply the sum reduction rule to a node in the graph.

OperatorGraph.to_networkx(self[, ignore_nodes])

Convert the graph to a NetworkX MultiDiGraph.