Skip to content

Commit

Permalink
Fix benchmark CI (#9013)
Browse files Browse the repository at this point in the history
* [skip-ci] Fix benchmark CI

* [skip-ci] reduce warnings

* Fix indexing benchmark
  • Loading branch information
dcherian authored May 7, 2024
1 parent 322e670 commit 71661d5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ jobs:
environment-name: xarray-tests
cache-environment: true
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}-benchmark"
# add "build" because of https://github.com/airspeed-velocity/asv/issues/1385
create-args: >-
asv
build
mamba
- name: Run benchmarks
Expand All @@ -47,9 +50,6 @@ jobs:
asv machine --yes
echo "Baseline: ${{ github.event.pull_request.base.sha }} (${{ github.event.pull_request.base.label }})"
echo "Contender: ${GITHUB_SHA} (${{ github.event.pull_request.head.label }})"
# Use mamba for env creation
# export CONDA_EXE=$(which mamba)
export CONDA_EXE=$(which conda)
# Run benchmarks for current commit against base
ASV_OPTIONS="--split --show-stderr --factor $ASV_FACTOR"
asv continuous $ASV_OPTIONS ${{ github.event.pull_request.base.sha }} ${GITHUB_SHA} \
Expand Down
12 changes: 8 additions & 4 deletions asv_bench/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// If missing or the empty string, the tool will be automatically
// determined by looking for tools on the PATH environment
// variable.
"environment_type": "conda",
"environment_type": "mamba",
"conda_channels": ["conda-forge"],

// timeout in seconds for installing any dependencies in environment
Expand All @@ -41,7 +41,7 @@

// The Pythons you'd like to test against. If not provided, defaults
// to the current version of Python used to run `asv`.
"pythons": ["3.10"],
"pythons": ["3.11"],

// The matrix of dependencies to test. Each key is the name of a
// package (in PyPI) and the values are version numbers. An empty
Expand Down Expand Up @@ -72,8 +72,12 @@
"sparse": [""],
"cftime": [""]
},


// fix for bad builds
// https://github.com/airspeed-velocity/asv/issues/1389#issuecomment-2076131185
"build_command": [
"python -m build",
"python -mpip wheel --no-deps --no-build-isolation --no-index -w {build_cache_dir} {build_dir}"
],
// Combinations of libraries/python versions can be excluded/included
// from the set to test. Each entry is a dictionary containing additional
// key-value pairs to include/exclude.
Expand Down
17 changes: 9 additions & 8 deletions asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def setup(self, *args, **kwargs):
self.ds2d_mean = self.ds2d.groupby("b").mean().compute()


# TODO: These don't work now because we are calling `.compute` explicitly.
class GroupByPandasDataFrame(GroupBy):
"""Run groupby tests using pandas DataFrame."""

Expand Down Expand Up @@ -111,11 +112,11 @@ def setup(self, *args, **kwargs):
{
"b": ("time", np.arange(365.0 * 24)),
},
coords={"time": pd.date_range("2001-01-01", freq="H", periods=365 * 24)},
coords={"time": pd.date_range("2001-01-01", freq="h", periods=365 * 24)},
)
self.ds2d = self.ds1d.expand_dims(z=10)
self.ds1d_mean = self.ds1d.resample(time="48H").mean()
self.ds2d_mean = self.ds2d.resample(time="48H").mean()
self.ds1d_mean = self.ds1d.resample(time="48h").mean()
self.ds2d_mean = self.ds2d.resample(time="48h").mean()

@parameterized(["ndim"], [(1, 2)])
def time_init(self, ndim):
Expand All @@ -127,15 +128,15 @@ def time_init(self, ndim):
def time_agg_small_num_groups(self, method, ndim, use_flox):
ds = getattr(self, f"ds{ndim}d")
with xr.set_options(use_flox=use_flox):
getattr(ds.resample(time="3M"), method)().compute()
getattr(ds.resample(time="3ME"), method)().compute()

@parameterized(
["method", "ndim", "use_flox"], [("sum", "mean"), (1, 2), (True, False)]
)
def time_agg_large_num_groups(self, method, ndim, use_flox):
ds = getattr(self, f"ds{ndim}d")
with xr.set_options(use_flox=use_flox):
getattr(ds.resample(time="48H"), method)().compute()
getattr(ds.resample(time="48h"), method)().compute()


class ResampleDask(Resample):
Expand All @@ -154,13 +155,13 @@ def setup(self, *args, **kwargs):
},
coords={
"time": xr.date_range(
"2001-01-01", freq="H", periods=365 * 24, calendar="noleap"
"2001-01-01", freq="h", periods=365 * 24, calendar="noleap"
)
},
)
self.ds2d = self.ds1d.expand_dims(z=10)
self.ds1d_mean = self.ds1d.resample(time="48H").mean()
self.ds2d_mean = self.ds2d.resample(time="48H").mean()
self.ds1d_mean = self.ds1d.resample(time="48h").mean()
self.ds2d_mean = self.ds2d.resample(time="48h").mean()


@parameterized(["use_cftime", "use_flox"], [[True, False], [True, False]])
Expand Down
1 change: 1 addition & 0 deletions asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}

basic_assignment_values = {
"1scalar": 0,
"1slice": xr.DataArray(randn((3, ny), frac_nan=0.1), dims=["x", "y"]),
"1slice-1scalar": xr.DataArray(randn(int(ny / 3) + 1, frac_nan=0.1), dims=["y"]),
"2slicess-1scalar": xr.DataArray(
Expand Down

0 comments on commit 71661d5

Please sign in to comment.