GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Setup Continuous Benchmarking workflow with pytest-codspeed by weiji14 · Pull Request #2908 · GenericMappingTools/pygmt

Conversation

@weiji14

@weiji14 weiji14 commented Dec 23, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Description of proposed changes

Measuring the execution speed of tests to track performance of PyGMT functions over time.

Using pytest-codspeed to do the benchmarking, with the help of https://github.com/CodSpeedHQ/action. Decorated test_basemap with @pytest.mark.benchmark to see if the benchmarking works.

Note: Running the benchmarks on Python 3.12 to enable flame graph generation, available with pytest-codspeed>=2.0.0 - see https://docs.codspeed.io/features/trace-generation.

References:

  • https://codspeed.io/blog/introducing-codspeed
  • https://docs.codspeed.io/benchmarks/python#running-the-benchmarks-in-your-ci

Relates to #2730 (comment), addresses #2910.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@weiji14
Setup Continuous Benchmarking workflow with pytest-codspeed
32d92d7
Measuring the execution speed of tests to track performance of PyGMT functions over time. Using pytest-codspeed, see https://docs.codspeed.io/benchmarks/python#running-the-benchmarks-in-your-ci. Decorated a couple of unit tests with @pytest.mark.benchmark to see if the benchmarking works.
@weiji14 weiji14 added the maintenance Boring but important stuff for the core devs label Dec 23, 2023
@weiji14 weiji14 added this to the 0.11.0 milestone Dec 23, 2023
@weiji14 weiji14 self-assigned this Dec 23, 2023
weiji14 added 8 commits December 23, 2023 19:53
@weiji14
Try fetching all history for setuptools-scm
2fabfb8
@weiji14
List installed packages after make install step
bf5499c
To debug why import pygmt doesn't work.
@weiji14
Try bash -el -c which python
fde1048
Might need to launch into the correct shell first. Also running pip list to double check if dependencies are installed ok.
@weiji14
Try using mostly PyPI packages, with GMT from conda-forge
f39abfb
Seeing if it's possible to avoid using conda shell.
@weiji14
Just install pygmt and dependencies in the benchmark step
6eddb0b
Do everything in the same shell, but point to the GMT installation in /home/runner/micromamba/envs/pygmt/lib/
@weiji14
Install setuptools
7d431b4
Try to prevent `ERROR: Project file:///home/runner/work/pygmt/pygmt has a 'pyproject.toml' and its build backend is missing the 'build_editable' hook. Since it does not have a 'setup.py' nor a 'setup.cfg', it cannot be installed in editable mode. Consider using a build backend that supports PEP 660`.
@weiji14
Upgrade version of pip and setuptools
b527c9d
Need newer setuptools greater than 64.
@weiji14
Try plain setuptools
31a7567
Action might not like the single quotes.
@weiji14
weiji14 force-pushed the continuous-benchmarking branch from a19bdf2 to 31a7567 Compare December 23, 2023 08:13
weiji14 added 17 commits December 23, 2023 21:21
@weiji14
Try to find GMT install path
5ca4565
Should be /home/runner/micromamba/envs/pygmt/lib/, but don't know what's happening in the CodSpeedHQ/action shell.
@weiji14
Try installing GMT with bundled conda
1ad03e9
Maybe best to use the bundled conda with GitHub Actions?
@weiji14
Update GMT_LIBRARY_PATH to /usr/share/miniconda/envs/pygmt/lib
1b67ca7
New place where GMT is installed by miniconda.
@weiji14
List contents of /usr/share/miniconda/envs/pygmt/lib/
6d2fb32
See if libgmt.so is in this folder.
@weiji14
Back to installing dependencies with conda instead of pip
8bb1665
Trying to workaround `Error loading GMT shared library at '/usr/share/miniconda/envs/pygmt/lib/libgmt.so'.
  /lib/x86_64-linux-gnu/libcrypto.so.3: version `OPENSSL_3.2.0' not found (required by /usr/share/miniconda/envs/pygmt/lib/././libssl.so.3)`
@weiji14
Still need to install pytest-codspeed from PyPI
351f8f2
Missing conda-forge package for pytest-codspeed.
@weiji14
Activate base environment rather than pygmt environment
e664973
@weiji14
Just use default python from setup-miniconda
992f914
Instead of setting Python 3.12 explicitly.
@weiji14
Install setuptools via PyPI and use GMT_LIBRARY_PATH from base env
2d38ecb
@weiji14
Typo
44533a5
@weiji14
Still need to upgrade setuptools version
f0aba1a
@weiji14
Try using conda's python rather than system python
c5a8338
@weiji14
Run tests with conda python instead of system python
c4cef5c
Don't use `make test`, which seems to use the system python in `/usr/bin/python` rather than `/usr/share/miniconda/bin/python`.
@weiji14
Actually use conda python to run pytest
b91c1df
Also split the PyGMT build step into a separate step, now that we're confident all the packages are installed using conda's python/pip.
@weiji14
Install pytest-mpl from conda-forge
a566eb8
Also tidy up some stray bits
@weiji14
Run pytest with --pyargs pygmt
3df918f
Try to avoid collecting tests in the examples/ folder.
@weiji14
Pin to Python 3.12
4a0af5e
@seisman

seisman commented Dec 24, 2023

Copy link
Copy Markdown
Member

So which tests should we benchmark (and should we mark all those tests with @pytest.mark.benchmark in this PR or a follow-up one)?

I think we should focus on benchmarking low-level functions rather than modules' wrappers, since the low-level functions are heavily used in everywhere and most wrappers have very simple and similar code structures.

For example, most plotting modules have very simple code like the one in Figure.basemap

    kwargs = self._preprocess(**kwargs)                                         
    with Session() as lib:                                                      
        lib.call_module(module="basemap", args=build_arg_string(kwargs))

so we just need to benchmark one basemap test (e.g., test_basemap()) and don't need to benchmark other basemap's tests and other plotting methods (e.g., Figure.coast). Of course, there are few exceptions, for example, Figure.meca, Figure.plot, Figure.plot3d, Figure.text are among the complicated wrappers and should be benchmarked.

Similarly, for table-processing and grid-processing functions, benchmarking pygmt.select and pygmt.grdfill should be enough.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

weiji14 and others added 4 commits December 25, 2023 11:50
@weiji14
Document benchmarks.yml workflow in docs/maintenance.md
c92fcb2
@weiji14
Run benchmarks when a release is published
c8d1965
@weiji14
Add benchmarks.yml to bump_gmt_checklist.md
7bf09b9
@weiji14 @seisman
Pin to CodSpeedHQ/[email protected]
31eb3da
Co-Authored-By: Dongdong Tian <[email protected]>
@weiji14

weiji14 commented Dec 24, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Need to mention the new workflow in:

* `doc/maintenance.md`
* `.github/ISSUE_TEMPLATE/bump_gmt_checklist.md`

Ok, done at c92fcb2 and 7bf09b9

* `.github/ISSUE_TEMPLATE/release_checklist.md` (maybe unnecessary in this file)

Probably not needed in the checklist, but I added a trigger at c8d1965 so that the benchmarks will be run when a release is published.

So which tests should we benchmark (and should we mark all those tests with @pytest.mark.benchmark in this PR or a follow-up one)?

I think we should focus on benchmarking low-level functions rather than modules' wrappers, since the low-level functions are heavily used in everywhere and most wrappers have very simple and similar code structures.

Let me open up a separate issue to discuss this, and also to track which unit tests we should benchmark. Edit: see #2910.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weiji14 weiji14 mentioned this pull request Dec 24, 2023
Benchmark performance of PyGMT functions #2910
Closed
weiji14 added 5 commits December 25, 2023 12:45
@weiji14
Only benchmark test_basemap for now
9c04e3f
Remove markers for test_blockmean_input_dataframe and test_grd2xyz.
@weiji14
Preprend $CONDA/bin to $GITHUB_PATH
f45b727
See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path and https://github.com/actions/starter-workflows/blob/c31fe3d5d44d7cb4c912f4c3213f7b4610f13ea2/ci/python-package-conda.yml#L19-L20
@weiji14
Use make commands instead of calling $CONDA/bin/python
5145649
The default Python used now should be the conda one instead of the system one.
@weiji14
Revert back to using python -m pytest
0a254f8
Default `make test` requires the use of pytest-cov and pytest-doctestplus
@weiji14
Only run when non-test PyGMT source files and benchmarks.yml is modified
dedfa7a
Trigger the benchmark run when files in `pygmt/clib`, `pygmt/datasets`, `pygmt/helpers`, `pygmt/src` and `pygmt/*.py` are modified (i.e. except `pygmt/tests/**`), and also when .github/workflows/benchmarks.yml is modified.
seisman
seisman approved these changes Dec 25, 2023
View reviewed changes

@seisman seisman left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@weiji14
weiji14 marked this pull request as ready for review December 25, 2023 06:06
@weiji14

weiji14 commented Dec 25, 2023

Copy link
Copy Markdown
Member Author

Thanks for reviewing @seisman! I'll merge this now and open a follow-up PR for marking more unit tests with @pytest.mark.benchmark. We can discuss more in #2910 too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weiji14
weiji14 merged commit 013014b into main Dec 25, 2023
@weiji14
weiji14 deleted the continuous-benchmarking branch December 25, 2023 06:33
@weiji14 weiji14 mentioned this pull request Dec 25, 2023
Mark unit tests with @pytest.mark.benchmark part 1 #2911
Merged
7 tasks
@seisman

seisman commented Dec 25, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

The Tests workflow (https://github.com/GenericMappingTools/pygmt/actions/runs/7319763038/job/19937998567) now has the following warnings because pytest-benchmark is not installed in these workflows:

  /home/runner/work/pygmt/pygmt/pygmt/tests/test_basemap.py:8: PytestUnknownMarkWarning: Unknown pytest.mark.benchmark - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    @pytest.mark.benchmark

I believe we need to silence these warnings.

weiji14 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weiji14 weiji14 mentioned this pull request Dec 25, 2023
Silence PytestUnknownMarkWarning by setting marker for pytest-benchmark #2912
Merged
7 tasks
@weiji14

weiji14 commented Dec 25, 2023

Copy link
Copy Markdown
Member Author

The Tests workflow (https://github.com/GenericMappingTools/pygmt/actions/runs/7319763038/job/19937998567) now has the following warnings because pytest-benchmark is not installed in these workflows:

Ok, opened #2912 for this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weiji14

weiji14 commented Dec 25, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

By the way, can you change the CodSpeed settings to only make PR comments when there is a performance improvement or regression (still don't have permissions)? This should reduce noise like #2907 (comment) when there's no noticeable change (we can still see the report in the 'Checks' tab if needed).

image

Also, maybe reduce the regression threshold to 5%?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seisman

seisman commented Dec 25, 2023

Copy link
Copy Markdown
Member

By the way, can you change the CodSpeed settings to only make PR comments when there is a performance improvement or regression (still don't have permissions)? This should reduce noise like #2907 (comment) when there's no noticeable change (we can still see the report in the 'Checks' tab if needed).

Done.

weiji14 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Dec 27, 2023
CI: Download cached remote files in benchmarks.yml #2923
Merged
Update maintainers guides #2916
Merged
Mark unit tests with @pytest.mark.benchmark part 2 #2924
Merged
Performance benchmarks xarray-contrib/xbatcher#42
Open
@seisman seisman mentioned this pull request Jan 2, 2024
CI: Remove the pytest-benchmark plugin from the benchmarks workflow #2947
Merged
@seisman seisman mentioned this pull request May 14, 2024
CI: Replace conda-incubator/setup-miniconda with mamba-org/setup-micromamba in the Benchmarks workflow #3248
Merged
@seisman seisman mentioned this pull request Nov 19, 2024
Document Continuous Benchmarking in Maintainers Guides #3631
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@seisman seisman seisman approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@weiji14 weiji14

Labels

maintenance Boring but important stuff for the core devs

Projects

None yet

Milestone

0.11.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@weiji14 @seisman
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.