Skip to content
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

Setup Continuous Benchmarking workflow with pytest-codspeed #2908

Merged
merged 39 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
32d92d7
Setup Continuous Benchmarking workflow with pytest-codspeed
weiji14 Dec 23, 2023
2fabfb8
Try fetching all history for setuptools-scm
weiji14 Dec 23, 2023
bf5499c
List installed packages after make install step
weiji14 Dec 23, 2023
fde1048
Try bash -el -c which python
weiji14 Dec 23, 2023
f39abfb
Try using mostly PyPI packages, with GMT from conda-forge
weiji14 Dec 23, 2023
6eddb0b
Just install pygmt and dependencies in the benchmark step
weiji14 Dec 23, 2023
7d431b4
Install setuptools
weiji14 Dec 23, 2023
b527c9d
Upgrade version of pip and setuptools
weiji14 Dec 23, 2023
31a7567
Try plain setuptools
weiji14 Dec 23, 2023
5ca4565
Try to find GMT install path
weiji14 Dec 23, 2023
1ad03e9
Try installing GMT with bundled conda
weiji14 Dec 23, 2023
1b67ca7
Update GMT_LIBRARY_PATH to /usr/share/miniconda/envs/pygmt/lib
weiji14 Dec 23, 2023
6d2fb32
List contents of /usr/share/miniconda/envs/pygmt/lib/
weiji14 Dec 24, 2023
8bb1665
Back to installing dependencies with conda instead of pip
weiji14 Dec 24, 2023
351f8f2
Still need to install pytest-codspeed from PyPI
weiji14 Dec 24, 2023
e664973
Activate base environment rather than pygmt environment
weiji14 Dec 24, 2023
992f914
Just use default python from setup-miniconda
weiji14 Dec 24, 2023
2d38ecb
Install setuptools via PyPI and use GMT_LIBRARY_PATH from base env
weiji14 Dec 24, 2023
44533a5
Typo
weiji14 Dec 24, 2023
f0aba1a
Still need to upgrade setuptools version
weiji14 Dec 24, 2023
c5a8338
Try using conda's python rather than system python
weiji14 Dec 24, 2023
c4cef5c
Run tests with conda python instead of system python
weiji14 Dec 24, 2023
b91c1df
Actually use conda python to run pytest
weiji14 Dec 24, 2023
a566eb8
Install pytest-mpl from conda-forge
weiji14 Dec 24, 2023
3df918f
Run pytest with --pyargs pygmt
weiji14 Dec 24, 2023
4a0af5e
Pin to Python 3.12
weiji14 Dec 24, 2023
cd6884a
Try using CodSpeedHQ/action@v2 instead of 2.0.2
weiji14 Dec 24, 2023
1b9316f
Add shield.io badge for CodSpeed
weiji14 Dec 24, 2023
37015d7
Set CODSPEED_TOKEN
weiji14 Dec 24, 2023
f115206
Revert setup CODSPEED_TOKEN
weiji14 Dec 24, 2023
c92fcb2
Document benchmarks.yml workflow in docs/maintenance.md
weiji14 Dec 24, 2023
c8d1965
Run benchmarks when a release is published
weiji14 Dec 24, 2023
7bf09b9
Add benchmarks.yml to bump_gmt_checklist.md
weiji14 Dec 24, 2023
31eb3da
Pin to CodSpeedHQ/[email protected]
weiji14 Dec 24, 2023
9c04e3f
Only benchmark test_basemap for now
weiji14 Dec 24, 2023
f45b727
Preprend $CONDA/bin to $GITHUB_PATH
weiji14 Dec 24, 2023
5145649
Use make commands instead of calling $CONDA/bin/python
weiji14 Dec 25, 2023
0a254f8
Revert back to using python -m pytest
weiji14 Dec 25, 2023
dedfa7a
Only run when non-test PyGMT source files and benchmarks.yml is modified
weiji14 Dec 25, 2023
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
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bump_gmt_checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ assignees: ''
- [ ] Bump the GMT version in CI (1 PR)
- [ ] Update `environment.yml`
- [ ] Update `ci/requirements/docs.yml`
- [ ] Update `.github/workflows/benchmarks.yml`
- [ ] Update `.github/workflows/cache_data.yaml`
- [ ] Update `.github/workflows/ci_doctests.yaml`
- [ ] Update `.github/workflows/ci_docs.yml`
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Run performance benchmarks
#
# Continuous benchmarking using pytest-codspeed. Measures the execution speed
# of tests marked with @pytest.mark.benchmark decorator.

name: Benchmarks

on:
# Run on pushes to the main branch
push:
branches: [ main ]
paths:
- 'pygmt/**/*.py'
- '!pygmt/tests/**'
- '.github/workflows/benchmarks.yml'
pull_request:
seisman marked this conversation as resolved.
Show resolved Hide resolved
paths:
- 'pygmt/**/*.py'
- '!pygmt/tests/**'
- '.github/workflows/benchmarks.yml'
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:
release:
types:
- published

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
benchmarks:
runs-on: ubuntu-22.04
defaults:
run:
shell: bash -l {0}

steps:
# Checkout current git repository
- name: Checkout
uses: actions/[email protected]
with:
# fetch all history so that setuptools-scm works
fetch-depth: 0

# Install Miniconda with conda-forge dependencies
- name: Setup Miniconda
uses: conda-incubator/[email protected]
with:
auto-activate-base: true
activate-environment: "" # base environment
channels: conda-forge,nodefaults
channel-priority: strict

# Install GMT and dependencies from conda-forge
- name: Install dependencies
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
# Preprend $CONDA/bin to $PATH so that conda's python is used over system python
echo $CONDA/bin >> $GITHUB_PATH
conda install --solver=libmamba gmt=6.4.0 python=3.12 \
numpy pandas xarray netCDF4 packaging \
pytest pytest-benchmark pytest-mpl
python -m pip install -U pytest-codspeed setuptools

# Install the package that we want to test
- name: Install the package
run: make install

# Run the benchmark tests
- name: Run benchmarks
uses: CodSpeedHQ/[email protected]
with:
weiji14 marked this conversation as resolved.
Show resolved Hide resolved
run: |
python -c "import pygmt; pygmt.show_versions()"
PYGMT_USE_EXTERNAL_DISPLAY="false" python -m pytest -r P --pyargs pygmt --codspeed
env:
GMT_LIBRARY_PATH: /usr/share/miniconda/lib/
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ PyGMT
.. image:: https://codecov.io/gh/GenericMappingTools/pygmt/branch/main/graph/badge.svg?token=78Fu4EWstx
:alt: Test coverage status
:target: https://app.codecov.io/gh/GenericMappingTools/pygmt
.. image:: https://img.shields.io/endpoint?url=https://codspeed.io/badge.json
:alt: CodSpeed Performance Benchmarks
:target: https://codspeed.io/GenericMappingTools/pygmt
.. image:: https://img.shields.io/pypi/pyversions/pygmt.svg?style=flat-square
:alt: Compatible Python versions.
:target: https://pypi.python.org/pypi/pygmt
Expand Down
2 changes: 2 additions & 0 deletions doc/maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ workflow files for more details.
12. `format-command.yml`: Format the codes using slash command
13. `dvc-diff.yml`: Report changes in test images
14. `slash-command-dispatch.yml`: Support slash commands in pull requests
15. `benchmarks.yml`: Benchmarks the execution speed of tests to track performance of PyGMT functions


## Continuous Documentation

Expand Down
1 change: 1 addition & 0 deletions pygmt/tests/test_basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pygmt import Figure


@pytest.mark.benchmark
@pytest.mark.mpl_image_compare
def test_basemap():
"""
Expand Down
Loading