Download 1.x PDF - Read the Docs

Transcript
IPython Documentation, Release 1.2.1: An Afternoon Hack
• We have run these examples on a cluster running RHEL 5 and Sun GridEngine. IPython’s built
in support for SGE (and other batch systems) makes it easy to get started with IPython’s parallel
capabilities.
5.12 DAG Dependencies
Often, parallel workflow is described in terms of a Directed Acyclic Graph or DAG. A popular library
for working with Graphs is NetworkX. Here, we will walk through a demo mapping a nx DAG to task
dependencies.
The full script that runs this demo can be found in examples/parallel/dagdeps.py.
5.12.1 Why are DAGs good for task dependencies?
The ‘G’ in DAG is ‘Graph’. A Graph is a collection of nodes and edges that connect the nodes. For our
purposes, each node would be a task, and each edge would be a dependency. The ‘D’ in DAG stands for
‘Directed’. This means that each edge has a direction associated with it. So we can interpret the edge (a,b)
as meaning that b depends on a, whereas the edge (b,a) would mean a depends on b. The ‘A’ is ‘Acyclic’,
meaning that there must not be any closed loops in the graph. This is important for dependencies, because if
a loop were closed, then a task could ultimately depend on itself, and never be able to run. If your workflow
can be described as a DAG, then it is impossible for your dependencies to cause a deadlock.
5.12.2 A Sample DAG
Here, we have a very simple 5-node DAG:
With NetworkX, an arrow is just a fattened bit on the edge. Here, we can see that task 0 depends on nothing,
and can run immediately. 1 and 2 depend on 0; 3 depends on 1 and 2; and 4 depends only on 1.
A possible sequence of events for this workflow:
0. Task 0 can run right away
1. 0 finishes, so 1,2 can start
2. 1 finishes, 3 is still waiting on 2, but 4 can start right away
3. 2 finishes, and 3 can finally start
Further, taking failures into account, assuming all dependencies are run with the default success=True,failure=False, the following cases would occur for each node’s failure:
0. fails: all other tasks fail as Impossible
1. 2 can still succeed, but 3,4 are unreachable
2. 3 becomes unreachable, but 4 is unaffected
3. and 4. are terminal, and can have no effect on other nodes
The code to generate the simple DAG:
5.12. DAG Dependencies
327