Skip to content

Enforce resampling texture for set_environment_texture with CI#7357

Merged
tkoyama010 merged 62 commits intomainfrom
maint/skip_set_environment_texture
Apr 10, 2025
Merged

Enforce resampling texture for set_environment_texture with CI#7357
tkoyama010 merged 62 commits intomainfrom
maint/skip_set_environment_texture

Conversation

@user27182
Copy link
Copy Markdown
Contributor

@user27182 user27182 commented Mar 30, 2025

Overview

This method seems to hang in CI and increases docstring tests times and doc build times considerably. See #6993 (comment)

This PR:

  • adds a new resample option to set_environment_texture to resample the texture to reduce the complexity of the rendering
  • adds a new theme config option resample_environment_texture for enabling this globally
  • adds a new theme config class 'document_build' to standardize the use of this option in CI

Doc build now takes 1hr 45 mins (down from 3 hrs)
Docstring tests now take 25 mins (down from 55 mins)

@user27182 user27182 marked this pull request as draft March 30, 2025 02:21
@pyvista-bot pyvista-bot added documentation Anything related to the documentation/website maintenance Low-impact maintenance activity labels Mar 30, 2025
@user27182
Copy link
Copy Markdown
Contributor Author

doctests run in ~19 minutes now instead of ~55 minutes. This confirms that set_environment_texture is the issue.
https://github.com/pyvista/pyvista/actions/runs/14151693064/job/39645683775?pr=7357

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.06%. Comparing base (6cafaf5) to head (bef8845).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7357   +/-   ##
=======================================
  Coverage   96.05%   96.06%           
=======================================
  Files         149      149           
  Lines       30577    30599   +22     
  Branches     4009     4012    +3     
=======================================
+ Hits        29372    29394   +22     
  Misses        572      572           
  Partials      633      633           

@pyvista-bot
Copy link
Copy Markdown
Contributor

pyvista-bot commented Mar 30, 2025

@pyvista-bot pyvista-bot temporarily deployed to pull request March 30, 2025 17:45 Inactive
@user27182
Copy link
Copy Markdown
Contributor Author

I have a working fix. I am not sure how we want to roll this out. Some options:

  1. Enable this fix with an environment variable (e.g. os.environ['PYVISTA_DOWNSAMPLE_ENVIRONMENT_TEXTURE'] = 'true'). This fix is likely specific to our CI environment, so with this option we always downsample for CI purposes. We could add a github label to disable this (e.g. when building from main or for releases) but otherwise have this set true by default.
  2. Add this as a keyword option for set_environment_texture, e.g. image_lighting_sampling_rate=None. This is better because it avoids managing env variables but is not ideal because then we always need to remember to set this value (e.g. image_lighting_sampling_rate=0.1 when writing new example. This may also have limited use since it's only for specific environments.

@user27182 user27182 marked this pull request as ready for review April 1, 2025 00:07
@MatthewFlamm
Copy link
Copy Markdown
Contributor

may be resetting the theme globally and setting resample_environment_texture=False as a result,

Weird, the addition from b0657c0 should be be run before and after every example.

@MatthewFlamm
Copy link
Copy Markdown
Contributor

MatthewFlamm commented Apr 9, 2025

It seems likely to me that the theme set in doc/source/conf.py never persisted throughout the whole doc build and is now being exposed in this PR. How do the themes get reset during docstring building? There is a fixture in conftest.py in pyvista/ but this will only run during doctest.

@user27182
Copy link
Copy Markdown
Contributor Author

may be resetting the theme globally and setting resample_environment_texture=False as a result,

Weird, the addition from b0657c0 should be be run before and after every example.

Yes you're right, the gallery has before and after events which run reset_pyvista so the gallery is all good.

I had another look through conf.py and think maybe the plot directive is resetting the theme here:

pyvista/doc/source/conf.py

Lines 503 to 508 in a43b10f

pyvista_plot_setup = """
from pyvista import set_plot_theme as __s_p_t
__s_p_t('document')
del __s_p_t
"""
pyvista_plot_cleanup = pyvista_plot_setup

This is a strong signal that a new documentation-build theme from #7389 may be needed here so that we can do:

- __s_p_t('document')
+ __s_p_t('doc_build')

(assuming we call the theme 'doc_build')

@MatthewFlamm
Copy link
Copy Markdown
Contributor

I had another look through conf.py and think maybe the plot directive is resetting the theme here:

So many places that the theme has to be reset. Good find.

This is a strong signal that a new documentation-build theme from #7389 may be needed here so that we can do:

Even if there is a way to do it without the documentation-building theme, it is turning out to be a nightmare to keep all these pieces in sync, so I agree that #7389 is becoming higher priority.

@user27182 user27182 marked this pull request as ready for review April 9, 2025 17:29
@user27182
Copy link
Copy Markdown
Contributor Author

This is once again ready for review. The theme is now applied consistently for all document testing and building, and build time is < 2hrs, docstring tests about 25 mins.

The build is expected to fail once more to generate new cache images but otherwise this PR should be good to go.

@user27182
Copy link
Copy Markdown
Contributor Author

Also, these examples are still the slowest to run in CI.

new durations from https://github.com/pyvista/pyvista/actions/runs/14184108844/job/39736183963?pr=7357#step:11:8745

====================== slowest reading durations =======================
63.921 api/examples/_autosummary/pyvista.examples.downloads.download_cubemap_space_16k
63.870 api/examples/_autosummary/pyvista.examples.downloads.download_cubemap_space_4k
62.112 api/examples/_autosummary/pyvista.examples.gltf.download_damaged_helmet
61.169 api/examples/_autosummary/pyvista.examples.downloads.download_sky_box_cube_map
60.977 api/plotting/_autosummary/pyvista.Plotter.set_environment_texture

This is much better than originally reported from #6993 (comment), but still, I wonder if we should try resample=0.05 by default instead of 0.1 ?

new sampling rate is now 1/16 (0.0625), with these new build times:

====================== slowest reading durations =======================
47.300 api/examples/dataset_gallery
45.293 api/core/_autosummary/pyvista.Texture.plot
44.820 api/examples/_autosummary/pyvista.examples.downloads.download_cubemap_space_16k
44.706 api/examples/_autosummary/pyvista.examples.downloads.download_cubemap_space_4k
43.235 api/examples/_autosummary/pyvista.examples.gltf.download_damaged_helmet

These are still among the slowest examples, but I think this is OK for now. This can also be tuned later if needed once we enable testing of the durations to enforce an upper limit.

@user27182 user27182 removed the request for review from banesullivan April 9, 2025 19:24
@pyvista-bot pyvista-bot temporarily deployed to pull request April 9, 2025 21:08 Inactive
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.

Why are these images changed? They look much better, but it looks unrelated to resampling?

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.

Don't really know, but the implementation for set_environment_texture now uses SetBackground, perhaps it's related to that change? This could be related to #5813 as well, where perhaps some textures only appear red under specific circumstances.

For this particular example, download_dikhololo_night() texture is used for the environment texture. If we download that and do a simple texture.plot(), it too appears as a red rectangle. And so previously, a pure red image was being used for rendering the reflections, but now maybe we fixed this, and the environment texture is being rendered correctly with SetBackground.

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.

There is also a pure red square that is fixed in this PR, so good enough for me.

@tkoyama010 tkoyama010 enabled auto-merge (squash) April 10, 2025 14:03
@tkoyama010 tkoyama010 merged commit 81512c5 into main Apr 10, 2025
32 checks passed
@tkoyama010 tkoyama010 deleted the maint/skip_set_environment_texture branch April 10, 2025 15:26
@pyvista-bot pyvista-bot temporarily deployed to pull request April 10, 2025 16:19 Inactive
@user27182 user27182 mentioned this pull request Apr 11, 2025
@banesullivan banesullivan mentioned this pull request Apr 17, 2025
6 tasks
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants