Class Graph

A Graph is composed of nodes and edges (i.e., Step and Edge objects).

class mflowgen.components.Graph

Graph of nodes and edges (i.e., Step and Edge).

Adding Steps

Graph.add_step(step)

Adds a Step to the graph as a node.

The name of the new Step cannot conflict with any steps that already exist in the graph. This method fails an assertion if given a duplicate step name.

Parameters:step – A Step object
Graph.get_step(step_name)

Gets the Step object with the given name.

Parameters:step_name – A string representing the name of the step from Step.get_name()
Graph.all_steps()

Connecting Steps 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., stepA has output foo and stepB has input foo).

Graph.connect(l_handle, r_handle)
Graph.connect_by_name(src, dst)

Parameter System

Graph.update_params(params)

Updates parameters for all steps in the graph.

Calls Step.update_params() for each step in the graph with the given parameter dictionary.

Parameters:params – A dict of parameter names (strings) and values

Advanced Graph-Building

Graph.param_space(step, param_name, param_space)

Spins out new copies of the step 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:
  • step – A string for the step 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) steps (i.e., ‘bar-p-1’, ‘bar-p-2’, and ‘bar-p-3’).