-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
open_mfdataset: support for multiple zarr datasets #3668
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
You can use the pseudocode here: https://xarray.pydata.org/en/stable/io.html#reading-multi-file-datasets and change |
Hi @dmedv -- thanks a lot for raising this issue here! One clarification question: is there just a single zarr store you are trying to read? Or are you trying to combine multiple stores, like
Can you provide more detail about how the zarr data is distributed across the different workers and client. |
@rabernat For now, I'm trying to open just a single zarr store. I have only mentioned @dcherian def modify(ds):
# modify ds here
return ds
# this is basically what open_mfdataset does
open_kwargs = dict(decode_cf=True, decode_times=False)
open_tasks = [dask.delayed(xr.open_dataset)(f, **open_kwargs) for f in file_names]
tasks = [dask.delayed(modify)(task) for task in open_tasks]
datasets = dask.compute(tasks) # get a list of xarray.Datasets
combined = xr.combine_nested(datasets) # or some combination of concat, merge In case of a single data source, I think, it can be condensed into this:
But it doesn't work quite as I expected, either with zarr, or with NetCDF. First I'll have to explain what I get with
I get
on the client. Only if I wrap it in
So, this approach is not fully equivalent to what If I add Now, back to zarr:
doesn't run at all, regardless of the chunks setting, giving me
so I don't even get a dataset object. Seems that something is quite different in the zarr backend implementation. I haven't had the chance to look at the code carefully yet, but I will do so in the next few days. Sorry for this long-winded explanation, I hope it clarifies what I'm trying to achieve here. |
Here is the stacktrace (somewhat abbreviated). Looks like a deserialization problem. As far as I can see from the Dask status dashboard and worker logs,
|
I tried to do serialization/deserialization by hand:
ds = xr.open_zarr("/sciserver/filedb02-01/ocean/LLC4320/SST")
pickle.dump(ds, open("/home/dask/zarr.p", "wb"))
It failed with the same error:
I then tried the same thing with a NetCDF dataset, and it worked fine. Also, the pickle file for NetCDF was much smaller. So I guess in the case of zarr dataset there is some initialization code that tries to open the zarr files when the dataset object gets deserialized on the client, and of course it cannot, because there is no data on the client. That explains a lot... although I'm still not sure if xarray was ever intended to be used that way. Maybe I'm trying to do a completely wrong thing here? |
Thanks for these detailed reports! The scenario you are describing--trying to open a file that is not accessible at all from the client--is certainly not something we ever considered when designing this. It is a miracle to me that it does work with netCDF. I think you are on track with the serialization diagnostics. I believe that @jhamman has the best understanding of this topic. He implemented the parallel mode in In the meantime, it seems worth asking the obvious question...how hard would it be to mount the NFS volume on the client? That would avoid having to go down this route. |
@rabernat |
True. I think its fair to say that the behavior you are enjoying (accessing data that the client cannot see) is the exception, not the rule. I expect there are many places in our backends that will not support this functionality at present. The motivation for implementing the Ironically, this dask issue also popped up and has some significant overlap here: dask/dask#5769 In both of these cases, the desire is for the worker to open the file (or zarr dataset), construct the underlying dask arrays, and return the meta object. This requires the object to be fully pickle-able and for any references to be maintained. It is possible, as indicated by your traceback, that the zarr backend is trying to reference the |
Also, @dmedv, can you add the output of |
I did another experiment: copied the metadata to the client ( |
Zarr documentation is not entirely clear on whether metadata gets pickled or not with but the code shows that the metadata is read from a file upon See I think at this point I will just give up and mount the necessary directories on the client, but at least I have a much better understanding of the issue now. Feel free to close if you think there's nothing else that can/should be done in xarray code about it. |
@dmedv and @rabernat - after thinking about this a bit more and reviewing the links in the last post, I'm pretty sure we're bumping into a bug in zarray's directory store pickle support. It would be nice to confirm this with some zarr-only tests but I don't see why the store needs to reference the zgroup files when the object is unpickled. |
@jhamman I did already confirm it with a zarr-only test, pickling and unpickling a zarr group object. I get the same error as with an xarray dataset: Not sure if we can call it a bug though. According to the storage specification https://zarr.readthedocs.io/en/stable/spec/v2.html#storage for a group to exist a |
It would be wonderful if we could translate this complex xarray issue into a minimally simple zarr issue. Then the zarr devs can decide whether this use case is compatible with the zarr spec or not. |
I am running calculations on a remote Dask cluster. Some of the data is only available on the workers, not on the client. It is already possible to have an xarray dataset that "points" to a remote NetCDF data collection by using the
parallel
option withxarray.open_mfdataset()
like this:Then it will use
dask.delayed
and, for example, the following simple mean calculation will be distributed between the workers, the result returned to the client:Unfortunately, I cannot do the same thing with zarr, because
open_mfdataset()
does not support it, andopen_zarr()
does not have an option to utilizedask.delayed
. Would it be possible to adddask.delayed
support to the zarr backend? Or, perhaps, I am missing something, and there is another better way to work with zarr data on a remote Dask cluster?Output of
xr.show_versions()
:The text was updated successfully, but these errors were encountered: