Skip to content

Compatibility with dask 2021.02.0 #4884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/requirements/environment-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
# - cdms2 # Not available on Windows
# - cfgrib # Causes Python interpreter crash on Windows: https://github.com/pydata/xarray/pull/3340
- cftime
- dask<2021.02.0
- dask
- distributed
- h5netcdf
- h5py=2
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- cdms2
- cfgrib
- cftime
- dask<2021.02.0
- dask
- distributed
- h5netcdf
- h5py=2
Expand Down
32 changes: 25 additions & 7 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,20 +920,38 @@ def _dask_postcompute(results, info, *args):

@staticmethod
def _dask_postpersist(dsk, info, *args):
from dask.core import flatten
from dask.highlevelgraph import HighLevelGraph
from dask.optimization import cull

variables = {}
# postpersist is called in both dask.optimize and dask.persist
# When persisting, we want to filter out unrelated keys for
# each Variable's task graph.
is_persist = len(dsk) == len(info)
for is_dask, k, v in info:
if is_dask:
func, args2 = v
if is_persist:
name = args2[1][0]
dsk2 = {k: v for k, v in dsk.items() if k[0] == name}
rebuild, rebuild_args = v
tmp = rebuild(dsk, *rebuild_args)
keys = set(flatten(tmp.__dask_keys__()))
if isinstance(dsk, HighLevelGraph):
# __dask_postpersist__() was invoked by various functions in the
# dask.graph_manipulation module.
#
# In case of multiple layers, don't pollute a Variable's
# HighLevelGraph with layers belonging exclusively to other
# Variables. However, we need to prevent partial layers:
# https://github.com/dask/dask/issues/7137
# TODO We're wasting a lot of key-level work. We should write a fast
# variant of HighLevelGraph.cull() that works at layer level
# only.
dsk2 = dsk.cull(keys)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add tests for this code path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will once dask/dask#7203 is out. I can remove the code path for now if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe that's safer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the HLG and reworked the whole thing

dsk3 = HighLevelGraph(
{k: dsk.layers[k] for k in dsk2.layers}, dsk2.dependencies
)
else:
dsk2 = dsk
result = func(dsk2, *args2)
# __dask_postpersist__() was invoked by dask.persist()
dsk3, _ = cull(dsk, keys)
result = rebuild(dsk3, *rebuild_args)
else:
result = v
variables[k] = result
Expand Down