Repository navigation
Chunk the dask view of a sharded array by shard, not by inner chunk - #58
Open
rhoadesScholar wants to merge 6 commits into
Open
rhoadesScholar wants to merge 6 commits into
rhoadesScholar wants to merge 6 commits into
Conversation
open_ds(chunks="strict") and prepare_ds built the dask view on the zarr array's .chunks, which for a zarr v3 sharded array is the inner chunk. A (577, 64777, 78161) uint8 array stored as (1, 10, 336, 336) shards of (1, 10, 56, 56) inner chunks became a dask array of 93.7 million blocks: a lazy channel selection over it materialised ~80 GB of graph per process and a (64, 512, 512) block read took 55 s. Chunked by shard the same read takes 1.3 s and 0.7 GB and returns the same bytes. The dask view now follows the stored write unit: the shard shape when sharded, else the chunk shape. inner_chunk_shape keeps naming the stored inner chunk, read from the source array rather than from the dask chunking, so it no longer changes with a chunks= override. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VLT61ERzhKe9Ja3q1SS7o5
A view built from a dask array has no stored chunk, and a view opened with a chunks= override is not chunked as stored: both report the view's own chunk shape, as before. The decision is taken once, at construction, so a lazy op that truncates the view does not change it. The test's override is (1, 32, 32), which neither the shard nor the inner chunk equals, so the assertion discriminates; a dask-sourced Array is covered. _stored_chunks reads zarr's .shards directly and is defined before its first use. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VLT61ERzhKe9Ja3q1SS7o5
…e array.py already needs Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VLT61ERzhKe9Ja3q1SS7o5
…he shape; one stored_chunks rule; document the block cost of callable lazy ops A stored shard (or chunk) longer than the array along an axis is clipped by dask, so the view-as-stored test compared unequal tuples and inner_chunk_shape fell back to the clipped shard; the copy-layout recipe then refused. _data_mismatches reads the write unit through the same stored_chunks helper the views use. Tests: the unsharded view, a shard longer than the array, and the create path on every sharded store type. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VLT61ERzhKe9Ja3q1SS7o5
…t of a zarr source; open_ds(chunks="inner") The dask chunking is a read strategy (data.chunksize); the layout properties no longer follow it, so an override or a stored unit longer than the array leaves the copy-layout recipe intact, sharded or not. chunks="inner" restores one block per stored chunk for reads through callable lazy ops, whose per-block cost the docstrings now state. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VLT61ERzhKe9Ja3q1SS7o5
rhoadesScholar
marked this pull request as ready for review
November 28, 2026 02:44
… (an OME image array) is read as stored chunk_shape fell to the dask chunk for the iohub array open_ome_ds hands Array, while shard_shape still read its shards. stored_chunks duck-types chunks/shards and answers None for a dask or numpy array; the view-chunks keyword compare is guarded for array overrides. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VLT61ERzhKe9Ja3q1SS7o5
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
open_ds(chunks="strict")andprepare_dsbuild the dask view on the zarr array's.chunks, which for a zarr v3 sharded array is the inner chunk. On a large array stored as small inner chunks that view is unusable:(577, 64777, 78161)uint8 array stored as(1, 10, 336, 336)shards of(1, 10, 56, 56)inner chunks becomes a dask array of 93.7 million blocks;lazy_op(np.s_[0])) materialises about 80 GB of graph per process;(64, 512, 512)block read then takes 55 s.Chunked by shard the same read takes 1.3 s and 0.7 GB and returns the same bytes (checked against a direct zarr read on a block with 11 M nonzero voxels).
This PR makes the default dask chunking (
chunks="strict") follow the stored write unit: the shard shape when sharded, else the chunk shape (stored_chunks, which_data_mismatchesreads too), inopen_dsand in bothArrayconstructions ofprepare_ds.open_ds(chunks="inner")is new and chunks the view by stored chunk, the inner chunk of a sharded array (what the default did before). An explicitchunks=still passes through to dask.chunk_shape,shard_shapeandinner_chunk_shapenow describe the stored layout of a zarr source whatever the dask view is chunked by (the view's chunking is ondata.chunksize): previouslyinner_chunk_shapewas the dask chunk, which made it the override underchunks=, andchunk_shapeof an unsharded array was dask's shape-clipped chunk, so a stored unit longer than the array along an axis read back clipped andprepare_ds(..., chunk_shape=a.chunk_shape, inner_chunk_shape=a.inner_chunk_shape)refused or copied a different layout. The stored layout is read from any source carryingchunksandshards, so the iohub image arrayopen_ome_dshandsArraykeeps reporting its shard aschunk_shape(it is not azarr.Arraysubclass); for data that records no layout, a dask or numpy array, both stay the view's own chunk.One trade-off, stated in the
open_dsandlazy_opdocstrings: a callable lazy op (lambda d: d / 255) is computed per dask block, so on an array of large shards a read through it decodes and transforms every shard it touches whole, where the inner-chunk view decoded only the chunks under the read; plain slices and integer indices fuse into the read and are unaffected.chunks="inner"is the way back where that cost matters. Not changed here:open_ome_dsstill builds its view with dask'sautochunking.Tests:
test_sharded_dask_view_is_chunked_by_shard(open_ds, prepare_ds create and reopen on every sharded store type,chunks="inner", a(1, 32, 32)override),test_unsharded_dask_view_is_chunked_by_chunk,test_a_shard_longer_than_the_array_still_names_the_stored_inner_chunk(sharded and unsharded, with the append and copy recipes) andtest_inner_chunk_shape_of_data_that_is_not_zarr_is_the_views_chunk. Full suite (248 passed), ruff and ty pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01VLT61ERzhKe9Ja3q1SS7o5