3

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!

2 Answers2

2

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

pavithraes
  • 724
  • 5
  • 9
0

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.

Alexandra Dudkina
  • 4,302
  • 3
  • 15
  • 27
  • Thank you for the reply! That creates an empty image. – Null Terminator Jan 27 '22 at 15:50
  • Do you have graphviz installed? There should be both graphviz system library installed and python graphviz library. – Alexandra Dudkina Jan 27 '22 at 16:32
  • Yes. When I use tried to visualize the returns of a @delayed function the graph looks as expected. – Null Terminator Jan 27 '22 at 16:49
  • I would try to update the versions of affected libraries: dask, python graphviz module and system graphviz library. Seems like some discrepancy between participant components. – Alexandra Dudkina Jan 27 '22 at 17:50
  • I think this answer is incorrect for recent versions of dask. As described in [this issue](https://github.com/dask/dask/issues/8883) this stopped working in version 2021.12.0. The [answer](https://stackoverflow.com/a/70898095/1588847) from @pavithraes reflects the same workaround (tho it's less than ideal!). – Justin Nov 26 '22 at 15:36