Skip to content

fix: suppress nested progress bars via thread-local context manager #1922

Open
BHARATH0153 wants to merge 8 commits into
sbi-dev:mainfrom
BHARATH0153:fix-nested-progress-bars
Open

fix: suppress nested progress bars via thread-local context manager #1922
BHARATH0153 wants to merge 8 commits into
sbi-dev:mainfrom
BHARATH0153:fix-nested-progress-bars

Conversation

@BHARATH0153

Copy link
Copy Markdown
Contributor

closes #1811

changes

Add sbi/utils/pbar.py with thread-local nesting tracker. Outer samplers (accept_reject_sample, rejection_sample, sampling_importance_resampling) wrap proposal calls in nested_pbar_context, while downstream functions like Diffuser.run check is_nested() to suppress their own bars.

…bi-dev#1811)

Add sbi/utils/pbar.py with thread-local nesting tracker. Outer samplers
(accept_reject_sample, rejection_sample, sampling_importance_resampling)
wrap proposal calls in nested_pbar_context, while downstream functions
like Diffuser.run check is_nested() to suppress their own bars.
@BHARATH0153 BHARATH0153 changed the title fix: suppress nested progress bars via thread-local context manager (… fix: suppress nested progress bars via thread-local context manager Jul 9, 2026
@BHARATH0153
BHARATH0153 marked this pull request as draft July 9, 2026 03:47
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.99%. Comparing base (dbf432b) to head (f7cf2b0).
⚠️ Report is 21 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1922      +/-   ##
==========================================
+ Coverage   87.88%   87.99%   +0.11%     
==========================================
  Files         143      144       +1     
  Lines       13387    13677     +290     
==========================================
+ Hits        11765    12035     +270     
- Misses       1622     1642      +20     
Flag Coverage Δ
fast 81.33% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sbi/samplers/importance/sir.py 100.00% <100.00%> (ø)
sbi/samplers/rejection/rejection.py 92.62% <100.00%> (+0.18%) ⬆️
sbi/samplers/score/diffuser.py 91.93% <100.00%> (+0.13%) ⬆️
sbi/utils/__init__.py 100.00% <100.00%> (ø)
sbi/utils/pbar.py 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

@BHARATH0153
BHARATH0153 marked this pull request as ready for review July 9, 2026 03:58
@BHARATH0153

Copy link
Copy Markdown
Contributor Author

@janfb please review when you have time thanks!

@BHARATH0153

Copy link
Copy Markdown
Contributor Author

@Jocho-Smith please review your insight will be helpful thanks!

@Jocho-Smith

Copy link
Copy Markdown
Contributor

Hi @BHARATH0153 , I like the slim and precise implementation. How exactly did you test that this is leading to the desired output?

I just run this test here again: #1473 (comment)

Instead of the the current

Generating 10 posterior samples in 4 diffusion steps  
Generating 100 posterior samples in 4 diffusion steps  
66it [00:01, ...]

I see with your code

(sbi) schmidt@node-63:~/gsoc2026/sbi$ pytest -s tests/test_npse_auto_gauss_iid.py
66it [00:01, 45.03it/s] 

So no bars at all.

This might be one possible solution to resolve the confusion, however I think this is not what you aimed for here. So the confusion from the test example from the link above is that one requests 10 samples and gets 2 status bars mentioning 10 and 100 additional samples. This can be confusing, b/c users might think they got 100, when they actually get the 10 requested.

So your solution removes the bars entirely, which makes the nestedness tracking unnecessary, right?

Maybe it is helpful to look at the example code I linked and design your solution it in a way that makes it behave it in the way you want - possibly writing some more 'test scenarios'. Does that make sense? Hope it helps.

Quick note: I'll be busy the next weeks as well, so Jan might actually be faster reviewing it before I can reply the next time. Thanks for looking at it either way!

@BHARATH0153

Copy link
Copy Markdown
Contributor Author

@janfb please check the new changes when you are free thanks!

@janfb

janfb commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Hi @BHARATH0153 please note that as said in my comment below the issue that I am not able to review this in the next weeks. I will try to review it early August. Thanks for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid multiple progress bars

3 participants