'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!
Solution 1:[1]
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.
Solution 2:[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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alexandra Dudkina |
| Solution 2 |

