Skip to content

Viewing node inputs and outputs

Loman computations contain methods to see what nodes are inputs to any node, and what nodes a given node is itself an input to. First, let's define a simple Computation:

>>> comp = Computation()
>>> comp.add_node("a", value=1)
>>> comp.add_node("b", lambda a: a + 1)
>>> comp.add_node("c", lambda a: 2 * a)
>>> comp.add_node("d", lambda b, c: b + c)
>>> comp.compute_all()
>>> comp

Gn0an1bn0->n1n2cn0->n2n3dn1->n3n2->n3

We can find the inputs of a node using the get_inputs method, or the i attribute (which works similarly to the v and s attributes to access value and state):

>>> comp.get_inputs("b")
['a']
>>> comp.get_inputs("d")
['c', 'b']
>>> comp.i.d  # Attribute-style access
['c', 'b']
>>> comp.i["d"]  # Dictionary-style access
['c', 'b']
>>> comp.i[["b", "d"]]  # Multiple dictionary-style accesses:
[['a'], ['c', 'b]]

We can also use get_original_inputs to find the inputs of the entire Computation (or a subset of it):

>>> comp.get_original_inputs()
['a']
>>> comp.get_original_inputs(["b"])  # Just the inputs used to compute b
['a']

To find what a node feeds into, there are get_outputs, the o attribute and get_final_outputs (although as intermediate nodes are often useful, this latter is less useful):

>>> comp.get_outputs("a")
['b', 'c']
>>> comp.o.a
['b', 'c']
>>> comp.o[["b", "c"]]
[['d'], ['d']]
>>> comp.get_final_outputs()
['d']

Finally, these can be used with the v accessor to quickly see all the input values to a given node:

>>> {n: comp.v[n] for n in comp.i.d}
{'c': 2, 'b': 2}