Developer Documentation

pyungo.core.topological_sort(data)

Topological sort algorithm

Parameters

data (dict) – dictionnary representing dependencies Example: {‘a’: [‘b’, ‘c’]} node id ‘a’ depends on node id ‘b’ and ‘c’

Returns

list of list of node ids

Example: [[‘a’], [‘b’, ‘c’], [‘d’]] The sequence is representing the order to be run. The nested lists are node ids that can be run in parallel

Return type

ordered (list)

Raises

PyungoError – In case a cyclic dependency exists

class pyungo.core.Node(fct, inputs, outputs, args=None, kwargs=None)

Node object (aka vertex in graph theory)

Parameters
  • fct (function) – The Python function attached to the node

  • inputs (list) – List of inputs (which can be Input, str or dict)

  • outputs (list) – List of outputs (Output or str)

  • args (list) – Optional list of args

  • kwargs (list) – Optional list of kwargs

Raises

PyungoError – In case inputs have the wrong type

class pyungo.core.Graph(inputs=None, outputs=None, parallel=False, pool_size=2, schema=None)

Graph object, collection of related nodes

Parameters
  • inputs (list) – List of optional Input if defined separately

  • outputs (list) – List of optional Output if defined separately

  • parallel (bool) – Parallelism flag

  • pool_size (int) – Size of the pool in case parallelism is enabled

  • schema (dict) – Optional JSON schema to validate inputs data

Raises

ImportError will raise in case parallelism is chosen and multiprocess – not installed

add_node(function, **kwargs)

explicit method to add a node to the graph

Parameters
  • function (function) – Python function attached to the node

  • inputs (list) – List of inputs (Input, str, or dict)

  • outputs (list) – List of outputs (Output or str)

  • args (list) – List of optional args

  • kwargs (list) – List of optional kwargs

calculate(data)

run graph calculations

property dag

return the ordered nodes graph

property data

return the data of the graph (inputs + outputs)

register(**kwargs)

register decorator

static run_node(node)

run the node

Parameters

node (Node) – The node to run

Returns

node id, node output values

Return type

results (tuple)

property sim_inputs

return input names (mapped) of every nodes

property sim_kwargs

return kwarg names (mapped) of every nodes

property sim_outputs

return output names (mapped) of every nodes

class pyungo.io.Input(name, map=None, meta=None, contract=None)

Object representing a function input

Parameters
  • name (str) – The variable name of the input / output

  • map (str) – Optional mapping name. This is the name referenced in the data inputs / outputs

  • meta (dict) – Not used yet

  • contract (str) – Optional contract rule used by pycontracts

class pyungo.io.Output(name, map=None, meta=None, contract=None)

Object representing a function output

Parameters
  • name (str) – The variable name of the input / output

  • map (str) – Optional mapping name. This is the name referenced in the data inputs / outputs

  • meta (dict) – Not used yet

  • contract (str) – Optional contract rule used by pycontracts