Skip to content

map_overlap supporting dict-based depth skipping trivial axes #3444

Closed

Description

@jakirkham

Currently map_overlap doesn't correctly support depth being a dict with some axes skipped (i.e. axes where a trivial, 0, depth is only needed). However it would be nice if it did. This came up during review of da.gradient.

cc @mrocklin

Example:
In [1]: import numpy as np

In [2]: import dask.array as da

In [3]: a = np.random.random((10, 15))

In [4]: d = da.from_array(a, chunks=5)

In [5]: d2 = d.map_overlap(
   ...:     np.diff,
   ...:     dtype=d.dtype,
   ...:     depth={0: 1},
   ...:     boundary="none",
   ...:     n=1,
   ...:     axis=0
   ...: )
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-5-240723218b21> in <module>()
      5     boundary="none",
      6     n=1,
----> 7     axis=0
      8 )

/zopt/conda2/envs/test/lib/python3.6/site-packages/dask/array/core.py in map_overlap(self, func, depth, boundary, trim, **kwargs)
   1747         """
   1748         from .ghost import map_overlap
-> 1749         return map_overlap(self, func, depth, boundary, trim, **kwargs)
   1750 
   1751     def cumsum(self, axis, dtype=None, out=None):

/zopt/conda2/envs/test/lib/python3.6/site-packages/dask/array/ghost.py in map_overlap(x, func, depth, boundary, trim, **kwargs)
    390     g2 = g.map_blocks(func, **kwargs)
    391     if trim:
--> 392         g3 = add_dummy_padding(g2, depth2, boundary2)
    393         return trim_internal(g3, depth2)
    394     else:

/zopt/conda2/envs/test/lib/python3.6/site-packages/dask/array/ghost.py in add_dummy_padding(x, depth, boundary)
    362     """
    363     for k, v in boundary.items():
--> 364         d = depth[k]
    365         if v == 'none' and d > 0:
    366             empty_shape = list(x.shape)

KeyError: 1
Environment:
name: test
channels:
  - conda-forge
  - defaults
dependencies:
  - appnope=0.1.0=py36_0
  - blas=1.1=openblas
  - bokeh=0.12.15=py36_0
  - ca-certificates=2018.1.18=0
  - certifi=2018.1.18=py36_0
  - click=6.7=py_1
  - cloudpickle=0.5.2=py_0
  - cytoolz=0.9.0.1=py36_0
  - dask=0.17.2=py_0
  - dask-core=0.17.2=py_0
  - decorator=4.2.1=py36_0
  - distributed=1.21.6=py36_0
  - heapdict=1.0.0=py36_0
  - ipython=6.2.1=py36_1
  - ipython_genutils=0.2.0=py36_0
  - jedi=0.11.1=py36_0
  - jinja2=2.10=py36_0
  - libgfortran=3.0.0=0
  - locket=0.2.0=py36_1
  - markupsafe=1.0=py36_0
  - msgpack-python=0.5.6=py36_0
  - ncurses=5.9=10
  - numpy=1.14.2=py36_blas_openblas_200
  - openblas=0.2.20=7
  - openssl=1.0.2n=0
  - packaging=17.1=py_0
  - pandas=0.22.0=py36_0
  - parso=0.1.1=py_0
  - partd=0.3.8=py36_0
  - pexpect=4.4.0=py36_0
  - pickleshare=0.7.4=py36_0
  - prompt_toolkit=1.0.15=py36_0
  - psutil=5.4.5=py36_0
  - ptyprocess=0.5.2=py36_0
  - pygments=2.2.0=py36_0
  - pyparsing=2.2.0=py36_0
  - python=3.6.5=0
  - python-dateutil=2.7.2=py_0
  - pytz=2018.4=py_0
  - pyyaml=3.12=py36_1
  - readline=7.0=0
  - setuptools=39.0.1=py36_0
  - simplegeneric=0.8.1=py36_0
  - six=1.11.0=py36_1
  - sortedcontainers=1.5.9=py36_0
  - sqlite=3.20.1=2
  - tblib=1.3.2=py36_0
  - tk=8.6.7=0
  - toolz=0.9.0=py_0
  - tornado=5.0.2=py36_0
  - traitlets=4.3.2=py36_0
  - wcwidth=0.1.7=py36_0
  - xz=5.2.3=0
  - yaml=0.1.7=0
  - zict=0.1.3=py_0
  - zlib=1.2.11=0

Activity

  1. mrocklin commented on Apr 25, 2018

    @mrocklin
    Member
  2. jakirkham commented on Apr 25, 2018

    @jakirkham
    MemberAuthor

    Agreed this is easy to fix.

    Some functions like ghost already use the depth.get(..., 0) strategy. So easy to continue that trend. Alternatively coerce_depth could guarantee a full dict with 0s for missing values. In either case, it would be good to have a test or two of using map_overlap with this syntax to ensure it doesn't regress.

    Not following your comment about generating tasks. Though I haven't dived deeply into the machinery behind map_overlap (only made a couple minor fixes).

  3. mrocklin commented on Apr 25, 2018

    @mrocklin
    Member
  4. jakirkham commented on Apr 25, 2018

    @jakirkham
    MemberAuthor

    Thanks for the clarification.

    Is this something that should be obvious at the graph level or does it require closer inspection? Trying to visualize what this test would look like. 🤔

  5. mrocklin commented on Apr 25, 2018

    @mrocklin
    Member

    It looks like we do an ok job here:

    In [1]: import dask.array as da
    
    In [2]: x = da.ones((10, 10), chunks=(2, 2))
    
    In [3]: len(x.map_overlap(lambda x: x, depth={0: 1, 1:1}).__dask_graph__())
    Out[3]: 569
    
    In [4]: len(x.map_overlap(lambda x: x, depth={0: 1, 1:0}).__dask_graph__())
    Out[4]: 392

    I'm not sure though, this might still be a little high?

  6. jakirkham commented on Apr 25, 2018

    @jakirkham
    MemberAuthor

    How should it scale per non-trivial dimension depth added?

  7. jakirkham commented on Apr 25, 2018

    @jakirkham
    MemberAuthor

    Added PR ( #3445 ) to address the syntax issue in the OP. If there is a separate performance issue, maybe we should migrate it to a new issue and address it separately.

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