Skip to content

Check return types of distributed computations - #733

Closed
ivirshup wants to merge 0 commit into
scverse:masterfrom
ivirshup:distributed-array-types
Closed

ivirshup wants to merge 0 commit into
scverse:masterfrom
ivirshup:distributed-array-types

Conversation

@ivirshup

@ivirshup ivirshup commented Jul 9, 2019

Copy link
Copy Markdown
Member

Add checks to make sure the distributed backend is staying distributed. This currently fails for dask arrays, since they become numpy arrays when subset.

@tomwhite Is this it right to assume that dask arrays should stay as dask arrays, and Zappy arrays should stay as Zappy arrays? Currently dask arrays are becoming numpy arrays when the parent AnnData is subset via the last line here (though this exact code is being replaced):

https://github.com/theislab/anndata/blob/75296bb210d141fa1de24960412bfcab77a9604d/anndata/core/anndata.py#L637-L657

Also, are ZappyArrays always read-only like the DirectZappyArrays are? I'm wondering about the set of anndata features they should work with.

ivirshup added a commit to ivirshup/anndata that referenced this pull request Jul 9, 2019
* Previously, Zappy and dask arrays were being converted to numpy arrays, which caused tests to pass, but with the wrong behaviour.
    * This is being corrected by scverse/scanpy#733, though I'm not sure how we should be dealing with dask arrays.
* Additionally, I've changed behaviour for `adata[idx].X[other_idx] = value` to making a copy-on-modify for the parent view, as it was in `<0.6.21`. I'm not totally sure if this is the intended behaviour, but it certainly is easier and now tested for.
@ivirshup ivirshup mentioned this pull request Jul 10, 2019
2 tasks done
@tomwhite

Copy link
Copy Markdown
Contributor

Thanks for opening this @ivirshup. The principle should be that Anndata doesn't change array types to numpy arrays. It may not have done this in the past (and this is one example), but we should fix that. Hopefully with improvements in numpy itself (like https://www.numpy.org/neps/nep-0018-array-function-protocol.html, and __array_ufunc__) it should be achievable. (I don't know how much work is needed in Anndata to do that though.)

Also, are ZappyArrays always read-only like the DirectZappyArrays are?

Yes, the idea is that they are immutable, and they are changed by transformation (e.g. applying a ufunc) to create a new array.

ivirshup added a commit to ivirshup/anndata that referenced this pull request Jul 26, 2019
* Previously, Zappy and dask arrays were being converted to numpy arrays, which caused tests to pass, but with the wrong behaviour.
    * This is being corrected by scverse/scanpy#733, though I'm not sure how we should be dealing with dask arrays.
* Additionally, I've changed behaviour for `adata[idx].X[other_idx] = value` to making a copy-on-modify for the parent view, as it was in `<0.6.21`. I'm not totally sure if this is the intended behaviour, but it certainly is easier and now tested for.
@ivirshup

Copy link
Copy Markdown
Member Author

The principle should be that Anndata doesn't change array types to numpy arrays.

I mostly agree with this, but think there would be a fair amount of work needed in AnnData. Most array types have special treatment in at least one place. A lot of this is due to our need to support sparse matrices. I'm hoping this can be reduced with some new stuff I'm adding though. This is definitely a good use case to test with.

There's also the issue of when converting implicitly makes sense. We will do transformations from sparse to dense if the values becomes dense. We will also convert between sparse matrix formats if it will make calculations more efficient.

On the topic of Zappy arrays. Can you take a view of a zappy array? This would be useful for some of the expectations around subsetting AnnData objects.

@ivirshup

Copy link
Copy Markdown
Member Author

Looking at the view code again, I see a key pain point for working with generic arrays is how our views work. Right now, we have to make a new subclass for every array type we accept, so that we can take views of arbitrary indices.

@ivirshup
ivirshup force-pushed the distributed-array-types branch from 8ecd68c to 687431b Compare July 28, 2019 08:03
ivirshup added a commit to ivirshup/anndata that referenced this pull request Jul 28, 2019
This solves some issues with the distributed backend, Namely, most errors
for scverse/scanpy#733 stop occuring. `normalize_per_cell`
still fails for dask, but the array doesn't appear to get modified. This
will need more looking into.
ivirshup added a commit to scverse/anndata that referenced this pull request Jul 29, 2019
* Previously, Zappy and dask arrays were being converted to numpy arrays, which caused tests to pass, but with the wrong behaviour.
    * This is being corrected by scverse/scanpy#733, though I'm not sure how we should be dealing with dask arrays.
* Additionally, I've changed behaviour for `adata[idx].X[other_idx] = value` to making a copy-on-modify for the parent view, as it was in `<0.6.21`. I'm not totally sure if this is the intended behaviour, but it certainly is easier and now tested for.
ivirshup added a commit to scverse/anndata that referenced this pull request Jul 29, 2019
This solves some issues with the distributed backend, Namely, most errors
for scverse/scanpy#733 stop occuring. `normalize_per_cell`
still fails for dask, but the array doesn't appear to get modified. This
will need more looking into.
@ivirshup

ivirshup commented Aug 1, 2019 •

Copy link
Copy Markdown
Member Author

I've managed to mostly fix this with only a slightly hacky change to AnnData (no longer requiring X to have a view type defined when making a copy). However the normalize_per_cell test still fails, as it seems like the matrix isn't actually being modified. I think it's because the reference to the dask array on this line becomes a copy when assigned to.

I've asked about this behaviour, and if it might change or throw a warning in dask/dask#5199

@LuckyMD

LuckyMD commented Aug 1, 2019

Copy link
Copy Markdown
Contributor

@aopisco This might be relevant to your questions about zarr arrays in backed/distributed mode.

@ivirshup
ivirshup force-pushed the distributed-array-types branch 3 times, most recently from 5dcb4a9 to 508f6c2 Compare August 4, 2019 06:37
@ivirshup ivirshup closed this Aug 4, 2019
@ivirshup
ivirshup force-pushed the distributed-array-types branch from a0a95bc to 508f6c2 Compare August 4, 2019 07:45
@ivirshup

ivirshup commented Aug 4, 2019 •

Copy link
Copy Markdown
Member Author

@tomwhite, I'm getting a little lost with dask at the moment. Right now this works on my machine, but doesn't work on travis. Any idea what's going on?

Nope, I was dumb. It's obviously that anndata hasn't been updated in this build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants