Skip to content

Add tests to limit sphinx gallery example execution times#7386

Merged
tkoyama010 merged 27 commits intomainfrom
test/sphinx-gallery
May 1, 2025
Merged

Add tests to limit sphinx gallery example execution times#7386
tkoyama010 merged 27 commits intomainfrom
test/sphinx-gallery

Conversation

@user27182
Copy link
Copy Markdown
Contributor

Overview

Sphinx gallery generates an xml file with computation times, see https://sphinx-gallery.github.io/stable/configuration.html#junit-xml

This PR parses this xml file and generates pytest cases. The tests fail if they exceed the specified maximum allowed time.

@user27182 user27182 marked this pull request as draft April 8, 2025 07:23
@pyvista-bot pyvista-bot added the documentation Anything related to the documentation/website label Apr 8, 2025
@user27182 user27182 added testing Anything related to CI testing maintenance Low-impact maintenance activity labels Apr 8, 2025
@pyvista-bot
Copy link
Copy Markdown
Contributor

pyvista-bot commented Apr 8, 2025

@pyvista-bot pyvista-bot temporarily deployed to pull request April 8, 2025 10:30 Inactive
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.15%. Comparing base (02e65c5) to head (79d0f48).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7386   +/-   ##
=======================================
  Coverage   96.15%   96.15%           
=======================================
  Files         149      149           
  Lines       30704    30704           
  Branches     4026     4026           
=======================================
  Hits        29524    29524           
  Misses        567      567           
  Partials      613      613           

@user27182
Copy link
Copy Markdown
Contributor Author

new tests are working, see https://github.com/pyvista/pyvista/actions/runs/14337838724/job/40189412437?pr=7386#step:14:328

FAILED tests/doc/tst_doc_images.py::test_gallery_example_execution_time[backface_props] - AssertionError: Sphinx gallery example 'Setting Backface Properties' from file
  	../../examples/02-plot/backface_props.py
  has an execution time: 385.58251428604126 seconds
  which exceeds the maximum allowed: 60.0 seconds.
assert 385.58251428604126 < 60.0
FAILED tests/doc/tst_doc_images.py::test_gallery_example_execution_time[depth_of_field] - AssertionError: Sphinx gallery example 'Depth of Field Plotting' from file
  	../../examples/02-plot/depth_of_field.py
  has an execution time: 792.1083476543427 seconds
  which exceeds the maximum allowed: 60.0 seconds.
assert 792.1083476543427 < 60.0
FAILED tests/doc/tst_doc_images.py::test_gallery_example_execution_time[edl] - AssertionError: Sphinx gallery example 'Eye Dome Lighting' from file
  	../../examples/02-plot/edl.py
  has an execution time: 70.12101650238037 seconds
  which exceeds the maximum allowed: 60.0 seconds.
assert 70.12101650238037 < 60.0
FAILED tests/doc/tst_doc_images.py::test_gallery_example_execution_time[pbr] - AssertionError: Sphinx gallery example 'Physically Based Rendering' from file
  	../../examples/02-plot/pbr.py
  has an execution time: 765.3375141620636 seconds
  which exceeds the maximum allowed: 60.0 seconds.
assert 765.3375141620636 < 60.0
FAILED tests/doc/tst_doc_images.py::test_gallery_example_execution_time[planets] - AssertionError: Sphinx gallery example '3D Earth and Celestial Bodies' from file
  	../../examples/99-advanced/planets.py
  has an execution time: 620.1809523105621 seconds
  which exceeds the maximum allowed: 60.0 seconds.
assert 620.1809523105621 < 60.0

Thinking of setting the limit to 900 seconds (15 minutes) for now, though we can probably make it 360 (6 minutes) once #7357 lands.

@pyvista-bot pyvista-bot temporarily deployed to pull request April 8, 2025 23:41 Inactive
@user27182 user27182 marked this pull request as ready for review April 8, 2025 23:42
@user27182 user27182 requested a review from banesullivan as a code owner April 8, 2025 23:42
@pyvista-bot pyvista-bot temporarily deployed to pull request April 9, 2025 03:30 Inactive
@pyvista-bot pyvista-bot temporarily deployed to pull request April 9, 2025 19:28 Inactive
@pyvista-bot pyvista-bot temporarily deployed to pull request April 10, 2025 01:15 Inactive
@pyvista-bot pyvista-bot temporarily deployed to pull request April 10, 2025 20:37 Inactive

# Same value as `sphinx_gallery_conf['junit']` in `conf.py`
SPHINX_GALLERY_CONF_JUNIT = Path('sphinx-gallery') / 'junit-results.xml'
SPHINX_GALLERY_EXAMPLE_MAX_TIME = 900.0 # Measured in seconds
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This needs to be set to a reasonable value. From #7397 , the slowest example takes about 2 minutes:
https://67f84843a3147b162189bc78--pyvista-dev.netlify.app/sg_execution_times.html

But I think this is too long. Should we aim to make this 30 seconds? (Plus fudge-factor so maybe warning after 30, fail after 45 seconds?). We can allow exceptions for the few examples that currently exceed this, but put a hard cap on new ones

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the idea of enforcing a default time that is quite fast and then a list of slow execution examples that is opt-in via list. I don't think we should exempt them completely, otherwise we may get regressions that creep into those examples making them take longer. This way new examples are by default checked to be fast. If they aren't we can assess whether it should be trimmed down for execution speed or added to the list.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like the idea of enforcing a default time that is quite fast and then a list of slow execution examples that is opt-in via list.

If we define "quite fast" to be 10 seconds, I think we can shave about 20 minutes from the build time by skipping any examples that take longer than this to run.

I don't think we should exempt them completely, otherwise we may get regressions that creep into those examples making them take longer.

We can maybe add a new CI env var and corresponding GitHub label SKIP_SLOW to opt-in to skip these? We can couple this with #7392, where the package pytest-fail-slow can be used to mark tests as slow (and optionally skip them). And maybe mirror how the cache labels works, and have skip-slow-doctest, skip-slow-unittest, skip-slow-gallery, etc. labels for controlling this.

This way new examples are by default checked to be fast. If they aren't we can assess whether it should be trimmed down for execution speed or added to the list.

I agree, slow examples should first fail and require adjustments of some kind to make them pass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The suggestions above are good and I think more needs to be done to make this all work as we'd like it to. But for this PR, is it OK if we at least enable the tests as-is for now, and simply place a hard limit of maybe 150 seconds (30 seconds slower than the slowest example) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coming back to this, it seems fine to me to get this in to avoid future problems and then refine later. Will do another review.

@pyvista-bot pyvista-bot temporarily deployed to pull request April 13, 2025 15:12 Inactive
@pyvista-bot pyvista-bot temporarily deployed to pull request April 14, 2025 07:14 Inactive
@pyvista-bot pyvista-bot temporarily deployed to pull request April 23, 2025 17:11 Inactive
@pyvista-bot pyvista-bot temporarily deployed to pull request April 24, 2025 18:48 Inactive
Copy link
Copy Markdown
Contributor

@MatthewFlamm MatthewFlamm left a comment

Choose a reason for hiding this comment

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

LGTM.

IMO it would be better to have the functionality to limit test gallery example execution time with fine grained control (exclusions or time overrides for specific examples) in sphinx-gallery directly.

@user27182
Copy link
Copy Markdown
Contributor Author

LGTM.

IMO it would be better to have the functionality to limit test gallery example execution time with fine grained control (exclusions or time overrides for specific examples) in sphinx-gallery directly.

That's a good idea. Would also be nice if it worked with abort_build_on_first_fail such that the build fails early instead of having to wait until after the build completes to find that an example took too long.

@pyvista-bot pyvista-bot temporarily deployed to pull request April 30, 2025 01:58 Inactive
@tkoyama010 tkoyama010 enabled auto-merge (squash) April 30, 2025 20:11
@pyvista-bot pyvista-bot temporarily deployed to pull request April 30, 2025 22:47 Inactive
@tkoyama010 tkoyama010 merged commit e65ae9d into main May 1, 2025
37 checks passed
@tkoyama010 tkoyama010 deleted the test/sphinx-gallery branch May 1, 2025 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Anything related to the documentation/website maintenance Low-impact maintenance activity testing Anything related to CI testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants