Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix progressbar with nested compound step samplers #7776

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented May 5, 2025

Alternative to #7730 that fixes #7721 and fixes #7724

@github-actions github-actions bot added the bug label May 5, 2025
Copilot

This comment was marked as outdated.

@aloctavodia
Copy link
Member

Currently, PyMC-BART works without this. However, a recent PR, which allows multiple BART RVs, fails without this. I have not tried with the alternative #7730.

@jessegrabowski jessegrabowski requested a review from Copilot July 9, 2025 15:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors and centralizes progress bar functionality, updates sampling step methods to use the new API, and adds a regression test for nested compound samplers.

  • Move CustomProgress, RecolorOnFailureBarColumn, ProgressBarManager, and related logic from pymc/util.py into a new pymc/progress_bar.py module.
  • Update all imports to point to pymc.progress_bar and adjust references to the new _make_progressbar_update_functions API.
  • Add an integration test (test_progressbar_nested_compound) to guard against regressions in nested CompoundStep progress bars.

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_progress_bar.py Add regression test for nested compound-step sampling progress.
pymc/variational/inference.py Update imports to use new CustomProgress location.
pymc/util.py Remove old progress-bar classes and imports.
pymc/tuning/starting.py Update progress-bar import to new module.
pymc/step_methods/slicer.py Rename update-stats API to _make_progressbar_update_functions.
pymc/step_methods/metropolis.py Rename and adjust update-stats API.
pymc/step_methods/hmc/*.py Rename and adjust update-stats API in HMC and NUTS.
pymc/step_methods/compound.py Rename and aggregate update-stat functions.
pymc/smc/sampling.py Update progress-bar import.
pymc/sampling/*.py Update progress-bar imports in various sampling pathways.
pymc/progress_bar.py New module consolidating progress-bar logic and classes.
.github/workflows/tests.yml Include the new test file in CI.
Comments suppressed due to low confidence (1)

pymc/progress_bar.py:37

  • [nitpick] Consider adding unit tests for CustomProgress (e.g., toggling disable and include_headers) to verify that tasks are added, updated, or suppressed as expected.
class CustomProgress(Progress):

Copy link

codecov bot commented Jul 9, 2025

Codecov Report

Attention: Patch coverage is 85.92233% with 29 lines in your changes missing coverage. Please review.

Project coverage is 92.88%. Comparing base (ae43026) to head (6748186).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pymc/progress_bar.py 83.55% 25 Missing ⚠️
pymc/step_methods/hmc/nuts.py 20.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7776      +/-   ##
==========================================
- Coverage   92.92%   92.88%   -0.04%     
==========================================
  Files         107      108       +1     
  Lines       18299    18313      +14     
==========================================
+ Hits        17004    17010       +6     
- Misses       1295     1303       +8     
Files with missing lines Coverage Δ
pymc/backends/arviz.py 95.78% <100.00%> (+0.01%) ⬆️
pymc/sampling/forward.py 96.75% <100.00%> (+0.01%) ⬆️
pymc/sampling/mcmc.py 91.37% <100.00%> (+0.01%) ⬆️
pymc/sampling/parallel.py 87.12% <100.00%> (+0.04%) ⬆️
pymc/sampling/population.py 70.83% <100.00%> (ø)
pymc/smc/sampling.py 99.30% <100.00%> (+<0.01%) ⬆️
pymc/step_methods/compound.py 97.87% <100.00%> (-0.02%) ⬇️
pymc/step_methods/hmc/base_hmc.py 92.25% <100.00%> (+0.34%) ⬆️
pymc/step_methods/hmc/hmc.py 94.59% <100.00%> (+1.04%) ⬆️
pymc/step_methods/metropolis.py 93.13% <100.00%> (-0.10%) ⬇️
... and 6 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

@ricardoV94 can you give the changes i pushed a final once over then we can merge this

@ricardoV94
Copy link
Member Author

@aloctavodia can you check if this also fixes the problem on your end?

Comment on lines 819 to 821
# Tune is always False, because this step does not have any tunable parameters.
stats = {"tune": False}
return q, [stats]
Copy link
Member Author

Choose a reason for hiding this comment

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

Why is it a dict inside a list, and why not just an empty dict?

Copy link
Member

Choose a reason for hiding this comment

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

  1. All step samplers return a dict inside a list, idk
  2. Because the CategoricalGibbsMetropolis has tune declared in its stats_dtypes_shapes, which I interpreted as a promise to return tune from its step function. It's incorrect that it wasn't doing this before.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I would just remove it but fine. Weird thing for the dict inside a list xD, open an issue to stop doing that?

Copy link
Member

Choose a reason for hiding this comment

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

technically It's your PR. I think removing the stats_dtypes_shapes is also a good way to go.

We still need to return an empty dictionary though, otherwise the zip(update_stats_fns, stats) fails (because there is always an update function, but sometimes no stats)

Copy link
Member Author

Choose a reason for hiding this comment

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

The shape is used by mcbackend I thing

Copy link
Member Author

Choose a reason for hiding this comment

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

empty dict is fine?

Copy link
Member Author

Choose a reason for hiding this comment

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

No need to do in this PR though

@ricardoV94 ricardoV94 marked this pull request as ready for review July 9, 2025 16:04
@ricardoV94
Copy link
Member Author

@jessegrabowski I cleanup a bit the PR, if tests pass I think we're good. Wanna take a last look?

Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

One docstring out of date, and a small issue I want to bring to your attention.

@ricardoV94
Copy link
Member Author

Oops my PR got merged stale and a test is failing

@ricardoV94
Copy link
Member Author

The other failure is ours

@jessegrabowski
Copy link
Member

There was a test with a hardcoded list of expected stats. It should pass now (not sure about the pre-commit problem)

@ricardoV94
Copy link
Member Author

pre-commit seems legit

@aloctavodia
Copy link
Member

I can confirm that this fixes the problem in PyMC-BART

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Progress bar throws error when nested CompoundSteps are present. BUG: Indexing TypeError when sampling with missing observations
3 participants