Skip to content

subgraph_callable failure with dask 0.20.1 #4201

Closed

Description

@sjperkins

This fails on python 2.7.14, dask 0.20.1, but works on dask 0.19.4.

As far as I can tell, a task like (operator.mul, 0j, [np.ndarray(...)]) gets constructed by subgraph_callable which produces the TypeError: can't multiply sequence by non-int of type 'complex' exception below

from __future__ import print_function

import dask.array as da
import numpy as np

row_chunks = (25, 25, 25, 25)
chan_chunks = (4, 4, 4, 4)
corr1_chunks = (2,)
corr2_chunks = (2,)

rows = sum(row_chunks)
chans = sum(chan_chunks)
corr1 = sum(corr1_chunks)
corr2 = sum(corr2_chunks)

shape = (rows, chans, corr1, corr2)
chunks = (row_chunks, chan_chunks, corr1_chunks, corr2_chunks)

vis = (da.random.random(shape, chunks=chunks) +
       da.random.random(shape, chunks=chunks)*1j)


def _grid2(vis):
    vis = vis[0][0]
    return np.ones(vis.shape[:2], dtype=vis.dtype)


grid2 = da.core.atop(_grid2, ("row", "chan"),
                     vis, ("row", "chan", "corr1", "corr2"),
                     dtype=vis.dtype)


print(grid2.compute().shape)

Produces the following:

Traceback (most recent call last):
  File "dask_atop_issue.py", line 38, in <module>
    print(grid.compute().shape)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/base.py", line 156, in compute
    (result,) = compute(self, traverse=False, **kwargs)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/base.py", line 397, in compute
    results = schedule(dsk, keys, **kwargs)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/threaded.py", line 76, in get
    pack_exception=pack_exception, **kwargs)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/local.py", line 501, in get_async
    raise_exception(exc, tb)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/local.py", line 272, in execute_task
    result = _execute_task(task, data)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/local.py", line 253, in _execute_task
    return func(*args2)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/optimization.py", line 942, in __call__
    dict(zip(self.inkeys, args)))
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/core.py", line 132, in _get_recursive
    res = cache[x] = _get_recursive(dsk, dsk[x], cache)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/core.py", line 136, in _get_recursive
    args2 = [_get_recursive(dsk, k, cache) for k in args]
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/core.py", line 126, in _get_recursive
    return [_get_recursive(dsk, k, cache) for k in x]
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/core.py", line 132, in _get_recursive
    res = cache[x] = _get_recursive(dsk, dsk[x], cache)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/core.py", line 136, in _get_recursive
    args2 = [_get_recursive(dsk, k, cache) for k in args]
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/core.py", line 132, in _get_recursive
    res = cache[x] = _get_recursive(dsk, dsk[x], cache)
  File "/home/sperkins/tmp/python/dask/venv/local/lib/python2.7/site-packages/dask/core.py", line 137, in _get_recursive
    return func(*args2)
TypeError: can't multiply sequence by non-int of type 'complex'

Activity

  1. mrocklin commented on Nov 12, 2018

    @mrocklin
    Member
  2. sjperkins commented on Nov 12, 2018

    @sjperkins
    MemberAuthor

    @mrocklin I've reduced the example further. concatenate=True does indeed ameliorate this issue, but its preferable not to rely on this for performance reasons. Unfortunately I don't have time to delve deep into the new dask internals.

  3. mrocklin commented on Nov 12, 2018

    @mrocklin
    Member

    Here is a perhaps even simpler failure that shows the problem you're running into

    import dask.array as da
    import numpy as np
    
    x = da.ones((10, 10), chunks=(5, 5))
    
    def f(chunk):
        assert isinstance(chunk, np.ndarray)
    
    
    y = da.core.atop(f, 'i',
                     x, 'ij',
                     dtype=x.dtype)
    y.compute()
          6 def f(chunk):
    ----> 7     assert isinstance(chunk, np.ndarray)
          8 
          9 
    
    AssertionError: 

    You are missing dimensions in your output, so they get concatenated into a list of elements. If you want to treat that list as a numpy array then you should pass concatenate=True. Really the question here is why this would have worked before.

    I'm curious, how is passing concatenate=True a performance issue for you?

  4. sjperkins commented on Nov 12, 2018

    @sjperkins
    MemberAuthor

    You are missing dimensions in your output, so they get concatenated into a list of elements. If you want to treat that list as a numpy array then you should pass concatenate=True

    Correct this is a mistake in my updated example, I've re-updated it, and the complex multiplied by list issue still occurs.

    I'm curious, how is passing concatenate=True a performance issue for you?

    I use this style based on @shoyer's comments in #3412 (comment)

  5. mrocklin commented on Nov 12, 2018

    @mrocklin
    Member

    Hrm, interesting, I've reduced this to the following minimal example

    import dask.array as da
    import numpy as np
    
    x = da.ones((10, 10), chunks=(5, 5)) * 1j
    
    
    def f(L):
        pass  # never actually get here
    
    y = da.core.atop(f, 'i',
                     x, 'ij',
                     dtype=x.dtype)
                     
    y.compute()

    Yeah, looks like a genuine bug. My guess is that this comes up in the atop fusion code, my guess is somewhere around here:

    dask/dask/array/top.py

    Lines 599 to 617 in df4c6dc

    if isinstance(layers[layer], TOP):
    top_layers = {layer}
    deps = set(top_layers)
    while deps: # we gather as many sub-layers as we can
    dep = deps.pop()
    if (dep in layers and
    isinstance(layers[dep], TOP) and
    not (dep != layer and dep in keep) and # output layer
    layers[dep].concatenate == layers[layer].concatenate): # punt on mixed concatenate
    top_layers.add(dep)
    # traverse further to this child's children
    for d in full_graph.dependencies.get(dep, ()):
    if len(dependents[d]) <= 1:
    deps.add(d)
    else:
    stack.append(d)
    else:
    stack.append(dep)

    If anyone has time to take a look that would be welcome. I'm busy the next couple days.

  6. added a commit that references this issue on Nov 14, 2018
    1f79bc1
  7. added a commit that references this issue on Nov 15, 2018
    d32eba2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions