-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New chunking approach that never splits encoded chunks #11060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jsignell
wants to merge
16
commits into
pydata:main
Choose a base branch
from
jsignell:non-splitting-auto
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+336
−12
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e61da90
Add an auto mechanism that doesn't split encoded chunks
jsignell 75c3f51
Forgot self
jsignell eecb8c5
Change from 'auto' to 'preserve'
jsignell 4461f87
Make sure api allows chunks='preserve'
jsignell c58093f
Add types
jsignell 1e85c59
Refactor and add test
jsignell fccd263
Add hypothesis testing
jsignell 478af0e
Tidy up strategy
jsignell a468c4b
Fix up typing
jsignell 20934cd
Move `preserve_chunks` call out of `normalize_chunks`
jsignell 4841a62
Merge branch 'main' into non-splitting-auto
jsignell f70a780
Add docs
jsignell e179264
Improve docs
jsignell e9fec1c
For non-uniform chunks just pass them back as is
jsignell a300f07
Use the last dim first to take advantage of c-ordered linearization
jsignell e6cef1c
Merge branch 'main' into non-splitting-auto
jsignell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| pytest.importorskip("hypothesis") | ||
| # isort: split | ||
|
|
||
| from hypothesis import given | ||
|
|
||
| import xarray.testing.strategies as xrst | ||
| from xarray.namedarray.parallelcompat import ChunkManagerEntrypoint | ||
|
|
||
|
|
||
| class TestPreserveChunks: | ||
| @given(xrst.shape_and_chunks()) | ||
| def test_preserve_all_chunks( | ||
| self, shape_and_chunks: tuple[tuple[int, ...], tuple[int, ...]] | ||
| ) -> None: | ||
| shape, previous_chunks = shape_and_chunks | ||
| typesize = 8 | ||
| target = 1024 * 1024 | ||
|
|
||
| actual = ChunkManagerEntrypoint.preserve_chunks( | ||
| chunks=("preserve",) * len(shape), | ||
| shape=shape, | ||
| target=target, | ||
| typesize=typesize, | ||
| previous_chunks=previous_chunks, | ||
| ) | ||
| for i, chunk in enumerate(actual): | ||
| if chunk != shape[i]: | ||
| assert chunk >= previous_chunks[i] | ||
| assert chunk % previous_chunks[i] == 0 | ||
| assert chunk <= shape[i] | ||
|
|
||
| if actual != shape: | ||
| assert np.prod(actual) * typesize >= 0.5 * target | ||
|
|
||
| @pytest.mark.parametrize("first_chunk", [-1, (), 1]) | ||
| @given(xrst.shape_and_chunks(min_dims=2)) | ||
| def test_preserve_some_chunks( | ||
| self, | ||
| first_chunk: int | tuple[int, ...], | ||
| shape_and_chunks: tuple[tuple[int, ...], tuple[int, ...]], | ||
| ) -> None: | ||
| shape, previous_chunks = shape_and_chunks | ||
| typesize = 4 | ||
| target = 2 * 1024 * 1024 | ||
|
|
||
| actual = ChunkManagerEntrypoint.preserve_chunks( | ||
| chunks=(first_chunk, *["preserve" for _ in range(len(shape) - 1)]), | ||
| shape=shape, | ||
| target=target, | ||
| typesize=typesize, | ||
| previous_chunks=previous_chunks, | ||
| ) | ||
| for i, chunk in enumerate(actual): | ||
| if i == 0: | ||
| if first_chunk == 1: | ||
| assert chunk == 1 | ||
| elif first_chunk == -1: | ||
| assert chunk == shape[i] | ||
| elif first_chunk == (): | ||
| assert chunk == previous_chunks[i] | ||
| elif chunk != shape[i]: | ||
| assert chunk >= previous_chunks[i] | ||
| assert chunk % previous_chunks[i] == 0 | ||
| assert chunk <= shape[i] | ||
|
|
||
| # if we have more than one chunk, make sure the chunks are big enough | ||
| if actual[1:] != shape[1:]: | ||
| assert np.prod(actual) * typesize >= 0.5 * target |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this should just be
"auto". Are we really working around a dask bug?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about doing this work in dask, but I ended up deciding that this is a sufficiently different goal from dask auto. The goal of dask auto is to guarantee that the chunksize will be under a configurable limit while preserving the aspect ratio of
previous_chunks. We don't really want either of those things.But maybe you are just saying: this is what xarray should mean by "auto" in which case I definitely agree. I'm just not sure how to make the transition from the old version of "auto" to the new version. Maybe it would be easier to give it a new name ("preserve") and then change the default value in kwargs from
chunks="auto"tochunks="preserve"at some point. If we just change what"auto"means then there is no way for people to get the dask auto behavior.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this again today and I think maybe we can get around the backwards incompatibility by adding a new option that does allows you to specify whether you want to use dask-style or preserve-style. I'll do an experiment with changing the behavior of "auto" itself and see how much it breaks stuff.