Repository navigation
Offset chunk key encoding: grow an array in the negative direction by whole chunks - #80
rhoadesScholar wants to merge 2 commits into
Conversation
The default encoding applied to the chunk grid coordinate plus a fixed per-dimension integer offset, so that an array grows in the negative direction of an axis by whole chunks as a metadata-only change: shape grows, offset drops, and every existing chunk keeps its key. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CSaEKF9nB55gU7PQgQ22X5
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CSaEKF9nB55gU7PQgQ22X5
|
Ready for review. Implementations are open as zarr-developers/zarr-python#4516 (core + |
|
Defining this as a chunk_key_encoding is indeed a clever, minimal way to specify it. However, there are some drawbacks:
What I'd rather see is an |
|
Thanks both, agreed on all three points. I missed #79 before opening this, sorry for the overlap. I've added notes from the prototype there (#79 (comment)), and I'll treat this PR and the three implementation PRs as a prototype to rework once the metadata shape settles. |
A regular chunk grid with an `origin` (the array coordinate where chunk 0 starts) and a `lower_bound` (the coordinate of the first element). Chunk grid indices may be negative and the first chunk may be partly filled, so an array grows before its first element by any number of elements as a metadata-only change. Supersedes the `offset` chunk key encoding proposed in zarr-developers#80; planned in zarr-developers#79.
Registers the
offsetchunk key encoding: thedefaultencoding applied to the chunk gridcoordinate plus a fixed per-dimension integer offset, so that adding
kwhole chunks beforearray index 0 is two metadata edits (
shape[a] += k * chunk_shape[a],offset[a] -= k) andno chunk changes its key.
Array indexing stays zero-based;
shape, theregularchunk grid and the codecs keep theirmeaning. With an all-zero offset the keys are byte-for-byte those of
default. Animplementation that does not know the name refuses the array, which is why this is a new
encoding rather than a field on the
regulargrid (current readers would ignore such a fieldand address every chunk from grid coordinate 0).
This is the chunk-level extension named as the alternative when zarr-specs#122 / #144 declined
a change to array indexing (rabernat: "an optional extension that would operate at the chunk
level, i.e. creating chunks like
-1.0.0"; d-v-b: "explicitly tracking the name of the firstchunk in some metadata"), and the direction jbms pointed at when closing zarr-specs#9. It
keeps to the one field it needs; sub-chunk growth and a user-facing non-zero array origin are
out of scope.
What it costs today versus with the encoding. Growing a
default-encoded array by twochunk rows in front, on one machine (NVMe, zarr-python 3.4.1), wall seconds:
offset: onezarr.jsonwriteThe rename column is the best case and only exists on a filesystem; on an object store the
rename is a copy + delete per chunk (44 s at 32 768 chunks through the zarr store API). The
offsetcolumn does not grow with the array. Script and raw rows:https://github.com/rhoadesScholar/zarr-chunk-offset/tree/main/bench
Implementations
(
zarr.chunk_key_encodingentry point, zarr-python >= 3.1.3), withadoptandprepend_chunksand tests, including a metadata-only prepend on a copy of a realmultiscale level.
OffsetChunkKeyEncodingplusArray.prepend_chunks/Array.prepend,branch https://github.com/rhoadesScholar/zarr-python/tree/offset-chunk-key-encoding
(Add Array.prepend and the regular_bounded chunk grid zarr-python#4516).
negative key components,
https://github.com/rhoadesScholar/tensorstore/tree/zarr3-offset-chunk-key-encoding
(zarr3: support the regular_bounded chunk grid google/tensorstore#296).
https://github.com/rhoadesScholar/neuroglancer/tree/zarr-offset-chunk-key-encoding
(zarr: read the regular_bounded chunk grid google/neuroglancer#1133).
Motivation: volumes assembled from parts that arrive over time in no fixed order (our case:
serial-section pages registered as they are imaged, where a page can land below pages already
rendered). Licensed under CC BY 3.0 as the registry requires.
Issues
proposal as a registered extension.
new name rather than an
originkey on theregulargrid because of the concern raised there:a key that current readers would ignore cannot be made safe. The array-index-space origin and
underfilling the first chunk are left to that discussion.
Proposal: open ended zarrs zarr-specs#39 (open-ended arrays that grow at both ends).