Skip to content

Commit

Permalink
ASV Benchmarking Pull Request Workflow (#831)
Browse files Browse the repository at this point in the history
* add workflow file, update asv config and enviroment.yml

* comment out broken benchmarks for now
  • Loading branch information
philipc2 authored Jul 2, 2024
1 parent 3b27d3f commit 07813fa
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 18 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/asv-benchmarking-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: ASV Benchmarking (PR)

on:
pull_request:
types: [opened, reopened, synchronize, labeled]
workflow_dispatch:

jobs:
benchmark:
if: ${{ contains(github.event.pull_request.labels.*.name, 'run-benchmark') && github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
name: Linux
runs-on: ubuntu-latest
env:
ASV_DIR: "./benchmarks"
CONDA_ENV_FILE: ci/environment.yml

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


- name: Set up Conda environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ${{env.CONDA_ENV_FILE}}
cache-environment: true
environment-name: uxarray_build
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}-benchmark"
create-args: >-
asv
build
mamba
- name: Run Benchmarks
shell: bash -l {0}
id: benchmark
run: |
set -x
# ID this runner
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 }})"
# Run benchmarks for current commit against base
ASV_OPTIONS="--split --show-stderr"
asv continuous $ASV_OPTIONS ${{ github.event.pull_request.base.sha }} ${GITHUB_SHA}
# Save compare results
asv compare --split ${{ github.event.pull_request.base.sha }} ${GITHUB_SHA} > asv_compare_results.txt
working-directory: ${{ env.ASV_DIR }}

- uses: actions/upload-artifact@v4
if: always()
with:
name: asv-benchmark-results-${{ runner.os }}
path: |
${{ env.ASV_DIR }}/results
${{ env.ASV_DIR }}/asv_compare_results.txt
- name: Post or update result comment
id: comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const compareResults = fs.readFileSync('${{ env.ASV_DIR }}/asv_compare_results.txt', 'utf8');
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
// Customize the comment content with your action results
const newComment = `
## ASV Benchmarking
<details>
<summary>Benchmark Comparison Results</summary>
${compareResults}
</details>
`;
// Fetch existing comments on the PR
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
// Find if there is an existing comment by this action
const botComment = comments.find(comment => comment.user.login === 'github-actions[bot]');
if (botComment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner,
repo,
comment_id: botComment.id,
body: newComment,
});
} else {
// Create a new comment
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: newComment,
});
}
23 changes: 13 additions & 10 deletions benchmarks/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
// 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
// defaults to 10 min
Expand All @@ -69,13 +70,6 @@
// to the current version of Python used to run `asv`.
"pythons": ["3.11"],

// The list of conda channel names to be searched for benchmark
// dependency packages in the specified order
"conda_channels": ["conda-forge"],

// A conda environment file that is used for environment creation.
"conda_environment_file": "../ci/asv.yml",

// The matrix of dependencies to test. Each key of the "req"
// requirements dictionary is the name of a package (in PyPI) and
// the values are version numbers. An empty list or empty string
Expand All @@ -96,10 +90,19 @@
// new environments. A value of ``null`` means that the variable
// will not be set for the current combination.
//
"matrix": {
"python": [""],
"matrix": {
"setuptools_scm": [""],
"xarray": [""],
"netcdf4": [""],
"pip+pyfma": [""]
},


"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
12 changes: 6 additions & 6 deletions benchmarks/quad_hexagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def time_open_grid(self):
"""Time to open a `Grid`"""
ux.open_grid(grid_path)

def mem_open_grid(self):
"""Memory Occupied by a `Grid`"""
return ux.open_grid(grid_path)
# def mem_open_grid(self):
# """Memory Occupied by a `Grid`"""
# return ux.open_grid(grid_path)

def peakmem_open_grid(self):
"""Peak memory usage of a `Grid`"""
Expand All @@ -27,9 +27,9 @@ def time_open_dataset(self):
"""Time to open a `UxDataset`"""
ux.open_dataset(grid_path, data_path)

def mem_open_dataset(self):
"""Memory occupied by a `UxDataset`"""
return ux.open_dataset(grid_path, data_path)
# def mem_open_dataset(self):
# """Memory occupied by a `UxDataset`"""
# return ux.open_dataset(grid_path, data_path)

def peakmem_open_dataset(self):
"""Peak memory usage of a `UxDataset`"""
Expand Down
8 changes: 6 additions & 2 deletions ci/environment.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
name: uxarray_build
channels:
- conda-forge
- nodefaults
dependencies:
- antimeridian
- cartopy
- dask
- datashader
- gmpy2
- h5netcdf
- hdf5
- holoviews
- matplotlib-base
- matplotlib-inline
- netcdf4
- numba
- numpy
- numpy<2
- pandas<2.1.0
- pathlib
- pre_commit
- pyarrow
- pytest
- pip
- pytest-cov
- requests
- scikit-learn
Expand All @@ -25,5 +30,4 @@ dependencies:
- spatialpandas
- xarray
- pip:
- antimeridian
- pyfma

0 comments on commit 07813fa

Please sign in to comment.