You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The data is loaded as dask arrays, as expected. But if we then manually call xarray.decode_cf(), it'll eagerly load the data. Is this the expected behavior, or should decode_cf() preserve the laziness of the data?
You could call .chunk() on it again to load it into dask, but even though the whole thing is lazy, the new dask arrays don't know they are holding dask arrays, which makes life difficult for dask.
You might ask why this separate lazy compute machinery exists. The answer is that dask fails to optimize element-wise operations like (scale * array)[subset] -> scale * array[subset], which is a critical optimization for lazy decoding of large datasets.
See dask/dask#746 for discussion and links to PRs about this. @jcrist had a solution that worked, but it slowed down every dask array operations by 20%, which wasn't a great win.
I wonder if this is worth revisiting with a simpler, less general optimization pass that doesn't bother with broadcasting. See the subclasses of NDArrayMixin in xarray/conventions.py for examples of the sorts of functionality we need:
Casting (e.g., array.astype(bool)).
Chained arithmetic with scalars (e.g., 0.5 + 0.5 * array).
Custom aggregations that drop a dimension (e.g., map_blocks(characters_to_string, array, drop_axis=-1))
If we could optimize all these operations (and ideally chain them), then we could drop all the lazy loading stuff from xarray in favor of dask, which would be a real win. @mrocklin any thoughts?
Optimization has come up a bit recently. In other projects like dask-glm I've actually been thinking about just turning it off entirely. The spread of desires here is wide. I think it would be good to make it a bit more customizable so that different applications can more easily customize their optimization suite (see dask/dask#2206)
But for this application in particular presumably all of these already tasks fuse together into a single composite task, yes? Then we would need to commute certain operations in some order (preferring to push down slicing operations). Then we would need to merge all of the slices, yes? I think it would be interesting to see how fast one could make such an optimization. If the answer is "decently fast" then we might also want to look into doing inplace operations. If the answer is "only sorta-fast" then I would hesitate before adding this as a default to dask.array but would again stress that we should work to make different projects customize optimization to suit their own needs.
But for this application in particular presumably all of these already tasks fuse together into a single composite task, yes? Then we would need to commute certain operations in some order (preferring to push down slicing operations). Then we would need to merge all of the slices, yes?
I just hit this issue. I tried to reproduce it with a synthetic dataset, as in @shoyer's example, but I couldn't. I can only reproduce it with data loaded from netcdf4 via open_mfdataset.
I downloaded one year of air-temperature data from NARR:
ftp://ftp.cdc.noaa.gov/Datasets/NARR/Dailies/pressure/
I load it this way (preprocessing is necessary to resolve conflict between missing_value and _FillValue):
There are no more chunks: ds_decode.air.chunks is Nonebutds_decode.air._in_memory is False.
This is already a weird situation, since the data is not in memory, but it is not a dask array either.
If I try to do anything beyond this with the data, it triggers eager computation. Even if I just call type(ds.air.data) it computes. If I do any arithmetic, it computes.
In my case, I could get around this problem if the preprocess function in open_mfdataset were applied before the cf_decoding of the store. But in general, we really need to make decode_cf fully dask compatible.
Activity
shoyer commentedon Apr 12, 2017
decode_cf()should definitely work lazily on dask array. If not, I would consider that a bug.spencerahill commentedon Apr 13, 2017
+1 we have come across this recently also in aospy
shoyer commentedon Apr 13, 2017
A simple test case:
shoyer commentedon Apr 13, 2017
Ah, so here's the thing:
decode_cfis actually lazy, but it uses some old xarray machinery for lazily decoding conventions instead of dask:You could call
.chunk()on it again to load it into dask, but even though the whole thing is lazy, the new dask arrays don't know they are holding dask arrays, which makes life difficult for dask.You might ask why this separate lazy compute machinery exists. The answer is that dask fails to optimize element-wise operations like
(scale * array)[subset]->scale * array[subset], which is a critical optimization for lazy decoding of large datasets.See dask/dask#746 for discussion and links to PRs about this. @jcrist had a solution that worked, but it slowed down every dask array operations by 20%, which wasn't a great win.
I wonder if this is worth revisiting with a simpler, less general optimization pass that doesn't bother with broadcasting. See the subclasses of
NDArrayMixinin xarray/conventions.py for examples of the sorts of functionality we need:array.astype(bool)).0.5 + 0.5 * array).map_blocks(convert_to_datetime64, array, dtype=np.datetime64))map_blocks(characters_to_string, array, drop_axis=-1))If we could optimize all these operations (and ideally chain them), then we could drop all the lazy loading stuff from xarray in favor of dask, which would be a real win. @mrocklin any thoughts?
mrocklin commentedon Apr 13, 2017
Optimization has come up a bit recently. In other projects like dask-glm I've actually been thinking about just turning it off entirely. The spread of desires here is wide. I think it would be good to make it a bit more customizable so that different applications can more easily customize their optimization suite (see dask/dask#2206)
But for this application in particular presumably all of these already tasks
fusetogether into a single composite task, yes? Then we would need to commute certain operations in some order (preferring to push down slicing operations). Then we would need to merge all of the slices, yes? I think it would be interesting to see how fast one could make such an optimization. If the answer is "decently fast" then we might also want to look into doing inplace operations. If the answer is "only sorta-fast" then I would hesitate before adding this as a default to dask.array but would again stress that we should work to make different projects customize optimization to suit their own needs.shoyer commentedon Apr 13, 2017
Yes, that sounds right to me.
rabernat commentedon Oct 19, 2017
I just hit this issue. I tried to reproduce it with a synthetic dataset, as in @shoyer's example, but I couldn't. I can only reproduce it with data loaded from netcdf4 via open_mfdataset.
I downloaded one year of air-temperature data from NARR:
ftp://ftp.cdc.noaa.gov/Datasets/NARR/Dailies/pressure/
I load it this way (preprocessing is necessary to resolve conflict between
missing_valueand_FillValue):If I try to decode cf, it returns instantly.
There are no more chunks:
ds_decode.air.chunks is Nonebutds_decode.air._in_memory is False.This is already a weird situation, since the data is not in memory, but it is not a dask array either.
If I try to do anything beyond this with the data, it triggers eager computation. Even if I just call
type(ds.air.data)it computes. If I do any arithmetic, it computes.In my case, I could get around this problem if the preprocess function in
open_mfdatasetwere applied before the cf_decoding of the store. But in general, we really need to makedecode_cffully dask compatible.fixes pydata#1372
Fix decode cf with dask (#2047)