Null Terminator
Null Terminator

Reputation: 116

visualize DASK task graphs

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!

Upvotes: 3

Views: 2455

Answers (2)

pavithraes
pavithraes

Reputation: 794

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

Upvotes: 2

Alexandra Dudkina
Alexandra Dudkina

Reputation: 4462

Pass your graph to dask.vizulalize():

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

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

get(dsk, "w")

dask.visualize(dsk)

See "Vizualize task graphs" documentation chapter as well.

Upvotes: 0

Related Questions