Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visualize DASK task graphs

Tags:

python

dask

I am following this tutorial and created a graph like so:

from dask.threaded import get

from operator import add

dsk = {
   'x': 1,
   'y': 2,
   'z': (add, 'x', 'y'),
   'w': (sum, ['x', 'y', 'z'])
}

get(dsk, "w")

That works and I get the desired output. How can I visualize the computational graph? The visualize method expects a DASK object and I only a have a dictionary.

Thanks in advance!

like image 342
Null Terminator Avatar asked Oct 28 '25 04:10

Null Terminator


1 Answers

dask.visualize works on Dask Collections -- the API docs here mention args need to be a "dask object", which means a Dask Collection (I've opened this issue to improve the docs!).

So, if you wrap your task graph dsk in a Collection, you should be able to visualize it:

import dask

from operator import add
from dask.threaded import get
from dask.delayed import Delayed

dsk = {
   'x': 1,
   'y': 2,
   'z': (add, 'x', 'y'),
   'w': (sum, ['x', 'y', 'z'])
}

# wrapping dsk in a Dask Collection (Delayed)
delayed_dsk = Delayed("w", dsk)

# call visualize as usual
delayed_dsk.visualize()

# Or,
dask.visualize(delayed_dsk)

task graph visualized

like image 183
pavithraes Avatar answered Oct 31 '25 11:10

pavithraes