pydra.engine.graph module

Data structure to support Workflow tasks.

class pydra.engine.graph.DiGraph(name=None, nodes=None, edges=None)[source]

Bases: object

A simple Directed Graph object.


Add new edges and sort the new graph.


adding detailed description of the connections, filling _nodes_details


Insert new nodes and sort the new graph.


Calculate maximum paths.

Maximum paths are calculated between any node without “history” (no predecessors) and all of the connections.


Duplicate this graph.

Create a copy that contains new lists and dictionaries, but runnable objects are the same.

create_dotfile_detailed(outdir, name='graph_det')[source]

creates a detailed dotfile (detailed connections - input/output fields, but no nested structure)

create_dotfile_nested(outdir, name='graph')[source]

dotfile that includes the nested structures for workflows

create_dotfile_simple(outdir, name='graph')[source]

creates a simple dotfile (no nested structure)

property edges

Get a list of the links between nodes.

property edges_names

Get edges as pairs of the nodes they connect.

export_graph(dotfile, ext='png')[source]

exporting dotfile to other formats requires the dot command

property nodes

Get a list of the nodes currently contained in the graph.

property nodes_details

dictionary with details of the nodes for each task, there are inputs/outputs and connections (with input/output fields names)

property nodes_names_map

Get a map of node names to nodes.

remove_nodes(nodes, check_ready=True)[source]

Mark nodes for removal from the graph, re-sorting if needed.


This method does not remove connections, see remove_node_connections(). Nodes are added to the _node_wip list, marking them for removal when all referring connections are removed.

  • nodes (list) – List of nodes to be marked for removal.

  • check_ready (:obj: bool) – checking if the node is ready to be removed


Remove connections between nodes.

Also prunes the nodes from _node_wip.


nodes (list) – List of nodes which connections are to be removed.


Remove connections that the node has with predecessors.

Also prunes the nodes from _node_wip.


nodes (list) – List of nodes which connections are to be removed.


Removing all the nodes that follow the node

property sorted_nodes

Return sorted nodes (runs sorting if needed).

property sorted_nodes_names

Return a list of sorted nodes names.


Sort this graph.

Sorting starts either from self.nodes or the previously sorted list.


presorted (list) – A list of previously sorted nodes.