Repository navigation
Closed
Labels
Description
While working on #2726, I found that da.diagonal() is broken in a way that I do not understand.
If both of the dimensions of a 2D input contains more than one chunk, the resulting graph can still be computed, but any composing that graph with another graph containing something else than itself, can not be computed, failing with:
"UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U46'), dtype('<U46')) -> dtype('<U46')"
In code:
x = da.ones((8,8), chunks=(4,4))
dd = da.ones((8,8), chunks=(4,4))
d = da.diagonal(dd)
print(d.compute()) # works
print((d+d).compute()) # also works
A = (d + x)
A.compute() # broken.Details
---------------------------------------------------------------------------
UFuncTypeError Traceback (most recent call last)
<ipython-input-106-1caaff1e195d> in <module>
5 print((d+d).compute()) # also works
6 A = (d + x)
----> 7 A.compute() # broken.
~/code/dask-dev/dask/dask/base.py in compute(self, **kwargs)
163 dask.base.compute
164 """
--> 165 (result,) = compute(self, traverse=False, **kwargs)
166 return result
167
~/code/dask-dev/dask/dask/base.py in compute(*args, **kwargs)
434 keys = [x.__dask_keys__() for x in collections]
435 postcomputes = [x.__dask_postcompute__() for x in collections]
--> 436 results = schedule(dsk, keys, **kwargs)
437 return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])
438
~/code/dask-dev/dask/dask/threaded.py in get(dsk, result, cache, num_workers, pool, **kwargs)
79 get_id=_thread_get_id,
80 pack_exception=pack_exception,
---> 81 **kwargs
82 )
83
~/code/dask-dev/dask/dask/local.py in get_async(apply_async, num_workers, dsk, result, cache, get_id, rerun_exceptions_locally, pack_exception, raise_exception, callbacks, dumps, loads, **kwargs)
484 _execute_task(task, data) # Re-execute locally
485 else:
--> 486 raise_exception(exc, tb)
487 res, worker_id = loads(res_info)
488 state["cache"][key] = res
~/code/dask-dev/dask/dask/local.py in reraise(exc, tb)
314 if exc.__traceback__ is not tb:
315 raise exc.with_traceback(tb)
--> 316 raise exc
317
318
~/code/dask-dev/dask/dask/local.py in execute_task(key, task_info, dumps, loads, get_id, pack_exception)
220 try:
221 task, data = loads(task_info)
--> 222 result = _execute_task(task, data)
223 id = get_id()
224 result = dumps((result, id))
~/code/dask-dev/dask/dask/core.py in _execute_task(arg, cache, dsk)
117 func, args = arg[0], arg[1:]
118 args2 = [_execute_task(a, cache) for a in args]
--> 119 return func(*args2)
120 elif not ishashable(arg):
121 return arg
~/code/dask-dev/dask/dask/optimization.py in __call__(self, *args)
980 if not len(args) == len(self.inkeys):
981 raise ValueError("Expected %d args, got %d" % (len(self.inkeys), len(args)))
--> 982 return core.get(self.dsk, self.outkey, dict(zip(self.inkeys, args)))
983
984 def __reduce__(self):
~/code/dask-dev/dask/dask/core.py in get(dsk, out, cache)
147 for key in toposort(dsk):
148 task = dsk[key]
--> 149 result = _execute_task(task, cache)
150 cache[key] = result
151 result = _execute_task(out, cache)
~/code/dask-dev/dask/dask/core.py in _execute_task(arg, cache, dsk)
117 func, args = arg[0], arg[1:]
118 args2 = [_execute_task(a, cache) for a in args]
--> 119 return func(*args2)
120 elif not ishashable(arg):
121 return arg
UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U46'), dtype('<U46')) -> dtype('<U46')Replacing dd by da.ones((8,8), chunks=(8,4)) or da.ones((8,8), chunks=(4,8)) does not expose the problem.
Activity
TAdeJong commentedon Dec 2, 2019
I would be happy to work on this and make a pull request together with my work on #2726, but I am a bit at a loss at what is happening here/ how to debug.
jacobtomlinson commentedon Dec 3, 2019
cc @TomAugspurger @mrocklin
mrocklin commentedon Dec 3, 2019
I'm able to reproduce the problem. Based on the dtype error my guess is that key values are leaking out into the actual values. I haven't investigated any further though. If someone wanted to dive further I would recommend running the computation with
compute(scheduler=single-threaded), and then usepdbto see what is going on when the error occurs.TomAugspurger commentedon Feb 6, 2020
A bit smaller reproducer
Will try to figure this out today.
TomAugspurger commentedon Feb 6, 2020
Going to have to table this for a bit, but this seems a bit strange in
dask.array.rechunk._compute_rechunkThe length-0 blocks are throwing some computation off
TomAugspurger commentedon Feb 11, 2020
Here's some currently-failing tests. Some of the
expectedvalues may be debatable, but I think getting those passing would (help) get this issue fixed.Alternatively,
rechunkcould filter out 0 chunks, but that seems unwise.martindurant commentedon Apr 7, 2020
@jsignell , do you have any thoughts of a timeline on this, how much effort it would take and whether you will have that effort to spare?
jsignell commentedon Apr 8, 2020
Thanks for the ping @martindurant. I don't really have an estimate for this. If no one has gotten to it in a week or so I'll probably have more time then to take another look.
heerad commentedon Oct 5, 2020
Hi, just wanted to note that I'm running into a similar error:
"UFuncTypeError: ufunc 'multiply' did not contain a loop with signature matching types (dtype('<U46'), dtype('<U46')) -> dtype('<U46')"Note that my error involves the ufunc
multiplyrather thanaddby OP @TAdeJong. I'm not explicitly callingda.diagonalanywhere in my code, and am rather using dask implicitly via xarray.TAdeJong commentedon Feb 9, 2022
Stumbled back upon this via #8689. As of 2022.01.1+20.gad3b688f, the bug is still there, although the error is different now:
KeyError: ('rechunk-merge-e63040be2c9c9793b8231bdea30520b8', 1, 0)Details
ParticularMiner commentedon Feb 9, 2022
Hi @TAdeJong ,
I think the problem here is that the
chunksattribute ofdiagonal()'s output 1D-daskarray has a mixture of chunks of zero and nonzero size, something thatdask.arrayseems to be allergic to (as I've come to learn from experience).The following code extract from
diagonal():dask/dask/array/creation.py
Lines 656 to 675 in 510bbc3
could be changed in the following way to make your code snippet above run successfully:
TAdeJong commentedon Feb 9, 2022
Heey @ParticularMiner,
Thanks for looking into this. It seems you are right about the zero and nonzero chunks, and now finally @TomAugspurger's comments here make sense to me, (and make my rereporting of this of limited use, I'm sorry) :-)
I guess we could fix
diagonal()in the way you suggest, but that would essentially only be symptom relief and I guess it would be preferable to really handle the zero size chunks better or at least try to throw a sensible warning.I for certain do not have the overview to make decisions here. Also I do not know how far @jsignell got at the time with resolving this.
ParticularMiner commentedon Feb 9, 2022
@TAdeJong
I completely agree.
As a side note, I've just discovered that my "fix" above allows your code snippet to pass, but not the main
test_diagonal()intest_creation.py. So there is something else going on here.ParticularMiner commentedon Feb 9, 2022
@TAdeJong
It seems the problem only occurs when the input array has exactly two dimensions. Really weird. So I've amended the "fix" above (see the edit). This will cause both the main
test_diagonal()and your code snippet to run successfully.But like you said before, this can only be a tentative patch-up solution awaiting a more comprehensive one.
offered a fix for rechunking with zero-size-chunks dask#5661
offered a fix for rechunking with zero-size-chunks dask#5661
offered a fix for rechunking with zero-size-chunks dask#5661
offered a fix for rechunking with zero-size-chunks dask#5661
offered a fix for rechunking with zero-size-chunks (#8703)
offered a fix for rechunking with zero-size-chunks (dask#8703)