0

I am trying to understand Dask delayed more deeply so I decided to work through the examples here. I modified some of the code to reflect how I want to use Dask (see below). But the results are different than what I expected ie. a tuple vs list. When I try to apply '.visualize()' to see what the execution graph looks like I get nothing.

I worked through all the examples in 'delayed.ipynb' and they all work properly including all the visualizations. I then modified the 'for' loop for one example:

for i in range(256):
    x = inc(i)
    y = dec(x)
    z = add(x, y)
    zs.append(z)

to a function call the uses a list comprehension. The result is a variation on the original working example.

%%time
import time
import random
from dask import delayed, compute, visualize

zs = []

@delayed
def inc(x):
    time.sleep(random.random())
    return x + 1

@delayed
def dec(x):
    time.sleep(random.random())
    return x - 1

@delayed    
def add(x, y):
    time.sleep(random.random())
    return x + y

def myloop(x):
    x.append([add(inc(i), dec(inc(i))) for i in range(8)])
    return x

result = myloop(zs)
final = compute(*result)
print(final)

I have tried printing out 'result' (function call) which provides the expected list of delay calls but when I print the results of 'compute' I unexpectedly get the desired list as part of a tuple. Why don't I get a just a list?

When I try to 'visualize' the execution graph I get nothing at all. I was expecting to see as many nodes as are in the generated list.

I did not think I made any significant modifications to the example so what am I not understanding?

MikeB2019x
  • 823
  • 8
  • 23

1 Answers1

0

The visualize function has the same call signature as compute. So if your compute(*result) call works then try visualize(*result)

MRocklin
  • 55,641
  • 23
  • 163
  • 235