8000 Introduce benchmark setup validation by trexfeathers · Pull Request #6496 · SciTools/iris · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Introduce benchmark setup validation #6496

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

Merged
merged 5 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# and to reinforce the culture of using this label.
benchmark_this:
- changed-files:
- any-glob-to-any-file: ['requirements/locks/*.lock', "setup.py"]
- any-glob-to-any-file: ['requirements/locks/*.lock']
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: marceloprado/has-changed-path@df1b7a3161b8fb9fd8c90403c66a9e66dfde50cb
with:
# SEE ALSO .github/labeler.yml .
paths: requirements/locks/*.lock setup.py
paths: requirements/locks/*.lock
- id: overnight
name: Check overnight scenario
if: github.event_name != 'pull_request'
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/benchmarks_validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: benchmarks-validate
run-name: Validate the benchmarking setup

on:
push:
branches:
- "main"
- "v*x"
tags:
- "v*"
pull_request:
branches:
- "*"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
validate:
runs-on: ubuntu-latest

env:
# Lets us manually bump the cache to rebuild
ENV_CACHE_BUILD: "0"

steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Nox
run: |
pip install nox!=2025.05.01

- name: Cache environment directories
id: cache-env-dir
uses: actions/cache@v4
with:
path: |
.nox
benchmarks/.asv/env
$CONDA/pkgs
key: ${{ runner.os }}-${{ hashFiles('requirements/') }}-${{ env.ENV_CACHE_BUILD }}

- name: Validate setup
run: nox -s benchmarks -- validate
24 changes: 24 additions & 0 deletions benchmarks/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

from os import environ

import iris

from . import generate_data
from .generate_data.um_files import create_um_files


def disable_repeat_between_setup(benchmark_object):
"""Benchmark where object persistence would be inappropriate (decorator).
Expand Down Expand Up @@ -50,3 +55,22 @@ def on_demand_benchmark(benchmark_object):
"""
if "ON_DEMAND_BENCHMARKS" in environ:
return benchmark_object


@on_demand_benchmark
class ValidateSetup:
"""Simple benchmarks that exercise all elements of our setup."""

params = [1, 2]

def setup(self, param):
generate_data.REUSE_DATA = False
(self.file_path,) = create_um_files(
param, param, param, param, False, ["NetCDF"]
).values()

def time_validate(self, param):
_ = iris.load(self.file_path)

def tracemalloc_validate(self, param):
_ = iris.load(self.file_path)
45 changes: 45 additions & 0 deletions benchmarks/bm_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,50 @@ def func(args: argparse.Namespace) -> None:
_subprocess_runner(asv_command, asv=True)


class Validate(_SubParserGenerator):
name = "validate"
description = (
"Quickly check that the benchmark architecture works as intended with "
"the current codebase. Things that are checked: env creation/update, "
"package build/install/uninstall, artificial data creation."
)
epilog = "Sole acceptable syntax: python bm_runner.py validate"

@staticmethod
def func(args: argparse.Namespace) -> None:
_setup_common()

git_command = shlex.split("git rev-parse HEAD")
head_sha = _subprocess_runner_capture(git_command)[:8]

# Find the most recent commit where the lock-files are not
# identical to HEAD - will force environment updates.
locks_dir = Path(__file__).parents[1] / "requirements" / "locks"
assert locks_dir.is_dir()
git_command = shlex.split(
f"git log -1 --pretty=format:%P -- {locks_dir.resolve()}"
)
locks_sha = _subprocess_runner_capture(git_command)[:8]

with NamedTemporaryFile("w") as hashfile:
hashfile.writelines([locks_sha, "\n", head_sha])
hashfile.flush()
asv_command = shlex.split(
f"run HASHFILE:{hashfile.name} --bench ValidateSetup "
"--attribute rounds=1 --show-stderr"
)
extra_env = environ | {"ON_DEMAND_BENCHMARKS": "1"}
_subprocess_runner(asv_command, asv=True, env=extra_env)

# No arguments permitted for this subclass:

def add_arguments(self) -> None:
pass

def add_asv_arguments(self) -> None:
pass


class GhPost(_SubParserGenerator):
name = "_gh_post"
description = (
Expand Down Expand Up @@ -670,6 +714,7 @@ def main():
SPerf,
Custom,
TrialRun,
Validate,
GhPost,
)

Expand Down
3 changes: 3 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ This document explains the changes made to Iris for this release
on `lychee <https://github.com/lycheeverse/lychee-action>`__.
(:issue:`4140`, :pull:`6386`)

#. `@trexfeathers`_ added a CI workflow to quickly validate that the
benchmarking setup is still working. (:pull:`6496`)


.. comment
Whatsnew author names (@github name) in alphabetical order. Note that,
Expand Down
Loading
0