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
where x is a 2D sparse array saved on disk, then partially loaded by some package supporting Numpy slicing syntax. I am aware of the Sparse array section in the documentation, however, I'm not certain how the proposed approach of swapping out in-memory numpy arrays with in-memory sparse arrays could apply with sparse arrays saved on disk.
I have posted a question on SO about it earlier, without receiving any suggestions on how this could be achievable. There I focused on scipy CSR arrays, loaded with joblib.load(.. , mmap_mode="r") because this allows partial loading of sparse arrays on disk and supports numpy slicing. However, I'm open to any other suggestions regarding the sparse array format / io package (e.g. using the mrocklin/sparse package).
I find the suggestions in the documentation about the storage format very useful (e.g. parquet for dataframes, more loosely hdf5 for dense arrays, etc). Is there any consensus yet as to what format could be used (possibly in the future) to store sparse arrays with dask? I'm not sure if anyone has worked on a language independent sparse array format (akin to feather or parquet for dataframes), or if it's possible to read/write the distributed sparse format from Spark in Python without installing PySpark...
If this is not yet possible in dask, is there a development roadmap for getting there? In particular, there were a number of issues on this, but at present, all of them are closed.
I personally do not know of a well-accepted on-disk format for sparse nd-arrays. If this is something that interests you then your research and efforts here would certainly be appreciated.
So, assuming there is an on disk format for sparse arrays (using joblib.dump/load on the sparse.COO works well enough) I was wondering what would be necessary to make da.from_array(X) work for such an object? The X[slice] could be a lazily loaded sparse array in any format, as needed.
Allocate a dense array on disk with the same shape as the sparse array
Copy the data from the sparse array to the dense array
Load the dense array with dask
Copy the data back into the sparse format with map_blocks(sparse.COO)
which is terribly inefficient. Is there a way around creating this initial dense array and doing the in memory replacement?
In particular, since I'm not (yet) familiar with the dask code base, I have a hard time estimating how difficult it would be to make a dask.array.from_sparse_array that would create a dask array directly from a sparse.COO or making dask.array.from_array work in this case. Unless there is a better way of doing this?
I would appreciate any suggestions regarding where to start on this. Thank you!
Slicing into an on-disk storage object should produce an ndarray object of some form (numpy, sparse, other).
That is the case for the on disk storage I am using, see above-linked notebook Out [10]:, however running da.from_array on this object fails. For that matter even applying da.from_array on an in memory sparse.COO array fails (with the same error), cf. above linked notebook sections 3.1, 3.2...
In [1]: import dask
In [2]: import dask.array as da
In [3]: import sparse
In [4]: x = sparse.COO({(10000, 10000): 1})
In [5]: x = da.from_array(x, chunks=(1000, 1000), asarray=False)
In [6]: x.compute()
Out[6]: <COO: shape=(10001, 10001), dtype=int64, nnz=1, sorted=False, duplicates=False>
@mrocklin In this example, how/when would you persist the array to a distributed cluster? It's probably due to a faulty mental model but I'm having a tough time figuring out how I could push multiple dask arrays to the cluster so that I could concatenate them afterward. I've tried scattering the sparse.COO array and then da.concatenating the futures but it doesn't seem to like that.
Activity
mrocklin commentedon Jul 27, 2017
I personally do not know of a well-accepted on-disk format for sparse nd-arrays. If this is something that interests you then your research and efforts here would certainly be appreciated.
rth commentedon Jul 27, 2017
@mrocklin Thanks for your response!
So, assuming there is an on disk format for sparse arrays (using
joblib.dump/loadon thesparse.COOworks well enough) I was wondering what would be necessary to makeda.from_array(X)work for such an object? TheX[slice]could be a lazily loaded sparse array in any format, as needed.Here are some things I have tried (using the
sparse.COOformat): https://github.com/rth/ipynb/blob/master/dask/On_disk_sparse_storage_dask.ipynband the only thing that worked was to,
map_blocks(sparse.COO)which is terribly inefficient. Is there a way around creating this initial dense array and doing the in memory replacement?
In particular, since I'm not (yet) familiar with the dask code base, I have a hard time estimating how difficult it would be to make a
dask.array.from_sparse_arraythat would create a dask array directly from asparse.COOor makingdask.array.from_arraywork in this case. Unless there is a better way of doing this?I would appreciate any suggestions regarding where to start on this. Thank you!
mrocklin commentedon Jul 27, 2017
Slicing into an on-disk storage object should produce an ndarray object of some form (numpy, sparse, other). See http://dask.pydata.org/en/latest/array-creation.html#simple-case-format-supports-numpy-slicing
rth commentedon Jul 27, 2017
That is the case for the on disk storage I am using, see above-linked notebook
Out [10]:, however runningda.from_arrayon this object fails. For that matter even applyingda.from_arrayon an in memorysparse.COOarray fails (with the same error), cf. above linked notebook sections 3.1, 3.2...mrocklin commentedon Jul 27, 2017
Two changes:
asarray=Falsekeyword argument to from_array to stop coercion to numpy arraysrth commentedon Jul 27, 2017
@mrocklin That's exactly what I was looking for. Thanks a lot!
seanlaw commentedon Jul 25, 2019
@mrocklin In this example, how/when would you
persistthe array to a distributed cluster? It's probably due to a faulty mental model but I'm having a tough time figuring out how I could push multiple dask arrays to the cluster so that I could concatenate them afterward. I've tried scattering the sparse.COO array and then da.concatenating the futures but it doesn't seem to like that.mrocklin commentedon Jul 25, 2019
Ideally you would load your data lazily as tasks, perhaps using something like dask.delayed and da.from_delayed. This blogpost might be helpful: https://blog.dask.org/2019/06/20/load-image-data
If you absolutely need to load data locally then you might consider using scatter and then da.from_delayed.