-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add representative rechunking workflow (#1536)
- Loading branch information
1 parent
5c99386
commit c626d45
Showing
4 changed files
with
127 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import os | ||
import uuid | ||
from typing import Any, Literal | ||
|
||
import coiled | ||
import pytest | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--scale", | ||
action="store", | ||
default="small", | ||
help="Scale to run. Either 'small' or 'large'", | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def scale(request): | ||
return request.config.getoption("scale") | ||
|
||
|
||
def get_cluster_spec(scale: Literal["small", "large"]) -> dict[str, Any]: | ||
everywhere = dict( | ||
workspace="dask-engineering-gcp", | ||
region="us-central1", | ||
wait_for_workers=True, | ||
spot_policy="on-demand", | ||
) | ||
|
||
if scale == "small": | ||
return { | ||
"n_workers": 10, | ||
**everywhere, | ||
} | ||
elif scale == "large": | ||
return { | ||
"n_workers": 100, | ||
**everywhere, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def cluster_name(request, scale): | ||
module = os.path.basename(request.fspath).split(".")[0] | ||
module = module.replace("test_", "") | ||
return f"geospatial-{module}-{scale}-{uuid.uuid4().hex[:8]}" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def cluster( | ||
cluster_name, | ||
scale, | ||
github_cluster_tags, | ||
): | ||
kwargs = dict( | ||
name=cluster_name, | ||
tags=github_cluster_tags, | ||
**get_cluster_spec(scale), | ||
) | ||
with coiled.Cluster(**kwargs) as cluster: | ||
yield cluster | ||
|
||
|
||
@pytest.fixture() | ||
def client(cluster, benchmark_all): | ||
with cluster.get_client() as client: | ||
with benchmark_all(client): | ||
yield client |
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,25 @@ | ||
import pytest | ||
import xarray as xr | ||
from coiled.credentials.google import CoiledShippedCredentials | ||
|
||
|
||
@pytest.mark.client("era5_rechunking") | ||
def test_era5_rechunking(client, gcs_url, scale): | ||
# Load dataset | ||
ds = xr.open_zarr( | ||
"gs://weatherbench2/datasets/era5/1959-2023_01_10-full_37-1h-0p25deg-chunk-1.zarr", | ||
).drop_encoding() | ||
|
||
if scale == "small": | ||
# 101.83 GiB (small) | ||
time_range = slice("2020-01-01", "2023-01-01") | ||
else: | ||
# 2.12 TiB (large) | ||
time_range = slice(None) | ||
subset = ds.sea_surface_temperature.sel(time=time_range) | ||
|
||
# Rechunk | ||
result = subset.chunk({"time": -1, "longitude": "auto", "latitude": "auto"}) | ||
|
||
# Write result to cloud storage | ||
result.to_zarr(gcs_url, storage_options={"token": CoiledShippedCredentials()}) |