paya.lib.evalgraph#

class EvalGraph(dct)#

Simple directed-acyclic-graph simulator. Good for rig build sequences etc.

Construction by Dictionary

EvalGraph objects use a dictionary with the following structure:

{
    <nodeName>: [inputNodeName, inputNodeName...],
    <nodeName>: [inputNodeName, inputNodeName...],
    [...]
}

A EvalGraph can be instantiated directly around such a dictionary, or via fromSegments(), which may be more intuitive.

Graphs cannot be edited after instantiation, only analysed and evaluated.

To get a build sequence for the entire graph, either iterate over the object or call getBuildSequence().

classmethod fromSegments(segments)#
Example

items = [
    ['A', 'C', 'D', 'G'],
    ['B', 'C', 'E', 'H'],
    ['E', 'F', 'G']
]

graph = EvalGraph.fromSegments(items)
print(list(graph)) # evaluate
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
Parameters

segments (list) – a list of lists (or tuples) where each sublist describes left-to-right connections between two or more nodes

Return type

EvalGraph

nodes(startTerminals=False, endTerminals=False, orphan=False)#

If startTerminals, endTerminals and orphan are omitted, all nodes will be returned.

Parameters
  • startTerminals (bool) – return only nodes with no inputs; defaults to False

  • endTerminals (bool) – return only nodes with no outputs; defaults to False

  • orphan (bool) – return only nodes with no inputs or outputs; defaults to False

Returns

A list of node names.

Return type

[str]

getNodeInputs(node)#
Parameters

node (str) – the node whose input nodes to return

Returns

The node’s inputs.

Return type

[str]

getNodeOutputs(node)#
Parameters

node (str) – the node whose output nodes to return

Returns

The node’s outputs.

Return type

[str]

getNodesUpstreamOf(node)#
Parameters

node – the node to trace from

Returns

All nodes upstream of node.

Return type

[str]

getNodesDownstreamOf(node)#
Parameters

node – the node to trace from

Returns

All nodes downstream of node.

Return type

[str]

getPath(start, end)#
Parameters
  • start (str) – the start node

  • end (str) – the end node

Raises

NoPathError – A path could not be found.

Returns

A path from the start to the end node.

Return type

[str]

reduceTargetList(*targets)#

Given a list of target nodes, returns another list with duplicates and implied nodes (i.e. nodes that are already upstream of other nodes) removed.

Parameters

*targets (str, [str]) – the targets to process

Returns

The reduced target list.

Return type

list

getBuildSequence(targets=None)#
Parameters

*targets (str, [str]) – optionally, a subset of target nodes to evaluate for; if omitted, the graph’s downstream-terminating nodes will be used as targets

Raises

NonExistentNodeError – A specified target node does not exist.

Returns

The full build sequence.

Return type

[str]