GeezerVison is showing github.com — Setup Continuous Benchmarking workflow with pytest-codspeed by weiji14 · Pull Request #2908 · GenericMappingTools/pygmt
Conversation
weiji14
commented
Dec 23, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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:
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.
To debug why import pygmt doesn't work.
Might need to launch into the correct shell first. Also running pip list to double check if dependencies are installed ok.
Seeing if it's possible to avoid using conda shell.
Do everything in the same shell, but point to the GMT installation in /home/runner/micromamba/envs/pygmt/lib/
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`.
Need newer setuptools greater than 64.
Action might not like the single quotes.
Should be /home/runner/micromamba/envs/pygmt/lib/, but don't know what's happening in the CodSpeedHQ/action shell.
Maybe best to use the bundled conda with GitHub Actions?
New place where GMT is installed by miniconda.
See if libgmt.so is in this folder.
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)`
Missing conda-forge package for pytest-codspeed.
Instead of setting Python 3.12 explicitly.
Don't use `make test`, which seems to use the system python in `/usr/bin/python` rather than `/usr/share/miniconda/bin/python`.
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.
Also tidy up some stray bits
Try to avoid collecting tests in the examples/ folder.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
weiji14
commented
Dec 24, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Remove markers for test_blockmean_input_dataframe and test_grd2xyz.
The default Python used now should be the conda one instead of the system one.
Default `make test` requires the use of pytest-cov and pytest-doctestplus
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.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
seisman
commented
Dec 25, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
weiji14
commented
Dec 25, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
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).

Also, maybe reduce the regression threshold to 5%?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Dec 27, 2023
Reviewers
seisman
seisman approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Labels
maintenance
Boring but important stuff for the core devs
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|