Class Graph
A Graph is composed of nodes and edges (i.e., Node and
Edge objects).
Note that for general discussion, we use the words “step” and “node”
interchangeably in the following documentation. The python code defines a
Step class and a Node class which are aliases of each
other. We recommend using the Node class. The Step
class is deprecated.
Adding Nodes
- Graph.add_node(node)
Adds a Node to the graph as a node.
The name of the new Node cannot conflict with any nodes that already exist in the graph. This method fails an assertion if given a duplicate node name.
- Parameters
node – A Node object
- Graph.get_node(node_name)
Gets the Node object with the given name.
- Parameters
node_name – A string representing the name of the node from
Node.get_name()
- Graph.all_nodes()
Connecting Nodes Together
The Graph.connect_by_name() method is preferred when possible to
keep code clean. This requires setting up nodes such that the inputs and
outputs are name-matched (e.g., nodeA has output foo and nodeB has input
foo).
Parameter System
- Graph.update_params(params)
Updates parameters for all nodes in the graph.
Calls
Node.update_params()for each node in the graph with the given parameter dictionary.
- Parameters
params – A dict of parameter names (strings) and values
Advanced Graph-Building
- Graph.param_space(node, param_name, param_space)
Spins out new copies of the node across the parameter space.
For example, for a graph like this:
+-----+ +-----------+ +-----------+ | foo | -> | bar | -> | baz | | | | ( p = 1 ) | | | +-----+ +-----------+ +-----------+this call:
g = Graph() (...) g.param_space( 'bar', 'p', [ 1, 2, 3 ] )will be transformed into a graph like this:
+-----------+ +-----------+ +-> | bar-p-1 | -> | baz-p-1 | | | ( p = 1 ) | | | | +-----------+ +-----------+ +-----+ | +-----------+ +-----------+ | foo | --> | bar-p-2 | -> | baz-p-2 | | | | | ( p = 2 ) | | | +-----+ | +-----------+ +-----------+ | +-----------+ +-----------+ +-> | bar-p-3 | -> | baz-p-3 | | ( p = 3 ) | | | +-----------+ +-----------+
- Parameters
node – A string for the node name targeted for expansion
param_name – A string for the parameter name
param_space – A list of parameter values to expand to
- Returns
A list of (parameterized) nodes (i.e., ‘bar-p-1’, ‘bar-p-2’, and ‘bar-p-3’).