-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add example for xarray groupby reduction causing memory pressure #1528
Merged
+84
−5
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a862003
Add example for xarray groupby reduction causing memory pressure
phofl 22da8a4
Add example for xarray groupby reduction causing memory pressure
phofl 9660f60
Fixup
phofl 6da5cf7
Add ids
phofl 5280044
Update cluster_kwargs.yaml
phofl 79d309b
Move skips
phofl d3c31ee
Update tests/benchmarks/test_xarray.py
phofl 8efa235
Move imports
phofl 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 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 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 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 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 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 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,69 @@ | ||
import uuid | ||
|
||
import fsspec | ||
import pytest | ||
from coiled import Cluster | ||
from distributed import Client | ||
|
||
from tests.conftest import dump_cluster_kwargs | ||
from tests.utils_test import wait | ||
|
||
xr = pytest.importorskip("xarray") | ||
pytest.importorskip("flox") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def group_reduction_cluster(dask_env_variables, cluster_kwargs, github_cluster_tags): | ||
kwargs = dict( | ||
name=f"xarray-group-reduction-{uuid.uuid4().hex[:8]}", | ||
environ=dask_env_variables, | ||
tags=github_cluster_tags, | ||
**cluster_kwargs["group_reduction_cluster"], | ||
) | ||
dump_cluster_kwargs(kwargs, "group_reduction_cluster") | ||
with Cluster(**kwargs) as cluster: | ||
yield cluster | ||
|
||
|
||
@pytest.fixture | ||
def group_reduction_client( | ||
group_reduction_cluster, cluster_kwargs, upload_cluster_dump, benchmark_all | ||
): | ||
n_workers = cluster_kwargs["group_reduction_cluster"]["n_workers"] | ||
with Client(group_reduction_cluster) as client: | ||
group_reduction_cluster.scale(n_workers) | ||
client.wait_for_workers(n_workers, timeout=600) | ||
client.restart() | ||
with upload_cluster_dump(client), benchmark_all(client): | ||
yield client | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"func", | ||
[ | ||
pytest.param( | ||
lambda x: x.groupby("time.month").mean(method="cohorts"), id="cohorts" | ||
), | ||
pytest.param( | ||
lambda x: x.groupby("time.month").mean(method="map-reduce"), id="map-reduce" | ||
), | ||
pytest.param( | ||
lambda x: x.chunk(time=xr.groupers.TimeResampler("ME")) | ||
.groupby("time.month") | ||
.mean(method="cohorts"), | ||
id="chunked-cohorts", | ||
), | ||
], | ||
) | ||
def test_xarray_groupby_reduction(group_reduction_client, func): | ||
ds = xr.open_zarr( | ||
fsspec.get_mapper( | ||
"s3://noaa-nwm-retrospective-2-1-zarr-pds/rtout.zarr", anon=True | ||
), | ||
consolidated=True, | ||
) | ||
# slice dataset properly to keep runtime in check | ||
subset = ds.zwattablrt.sel(time=slice("2001", "2002")) | ||
subset = subset.isel(x=slice(0, 350 * 8), y=slice(0, 350 * 8)) | ||
result = func(subset) | ||
wait(result, group_reduction_client, 10 * 60) |
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.
I'd suggest moving the xarray-related tests to
test_xarray.py
.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'd rather do this as a follow up, but the general idea is good