Repository navigation
Closed
Labels
Milestone
Description
At the moment our command line logging during posterior sampling is not consistent:
for NPE / direct posteriors which we usually sample using accept and reject sampling within prior bounds, we just show the number of posterior samples:
sbi/sbi/samplers/rejection/rejection.py
Lines 119 to 123 in 49e091f
| pbar = tqdm( | |
| disable=not show_progress_bars, | |
| total=num_samples, | |
| desc=f"Drawing {num_samples} posterior samples", | |
| ) |
for MCMC based posteriors, we do
sbi/sbi/samplers/mcmc/slice_numpy.py
Lines 441 to 445 in 49e091f
| if self.verbose: | |
| pbar = tqdm( | |
| range(self.num_chains * (num_samples + self.tuning)), | |
| desc=f"Running vectorized MCMC with {self.num_chains} chains", | |
| ) |
Problems:
- this is inconsistent and should have more information for the user.
- the logging can be confusing when using batched sampling because it just shows the number of samples (NPE, no info about the number of x in batch) or the number of chains (MCMC, no info about how many xs, how many samples per x).
see also #1388
One idea would be to have a function that builds an logging message given num samples, num x, num chains etc, and to re-use it across sampling algorithms.
Activity
Pratyusha-DS13 commentedon Mar 22, 2026
Hi! I’d like to work on this issue.
From my understanding, the goal is to make logging during posterior sampling more consistent and informative across different methods.
To start, I was thinking of:
Does this approach sound good, or would you recommend focusing on a specific part first?
Thanks!
janfb commentedon Mar 23, 2026
Hi @Pratyusha-DS13 , yes, this sounds like a good general approach to these kind of issues.
You are welcome to look into this, let's continue discussing the problem and a potential fix here under the issue.
Pratyusha-DS13 commentedon Mar 23, 2026
After reading through the code, here's a fuller picture of the current logging across all slice samplers:
SliceSampler.gen()—trangewith"Generating samples"(no count, no context)SliceSampler._tune_bracket_width()—trangewith"Tuning bracket width..."(fine as-is)SliceSamplerSerial.run()— showsnum_chainsandnum_workers, but notnum_samplesSliceSamplerVectorized.run()— showsnum_chainsonly, missingnum_samplesandnum_samples_per_chainMy proposed fix is a small shared helper, e.g.:
Then each sampler calls this instead of its own string. This keeps things consistent without a big refactor.
A couple of questions:
SliceSampler.gen()also shown_samplesin its description, or is thetrangetotal sufficient there?sbi/utils/logging.py, or somewhere closer to the samplers?Happy to open a draft PR with these changes if the direction looks good.
janfb commentedon Sep 30, 2026
Hi @Pratyusha-DS13, thanks for the careful look at the slice sampler bars, and sorry that your proposal stayed without a reply for so long.
In the meantime, PR #1922 reworked the progress bars of most samplers, so the code changed quite a bit. Your survey was useful: it showed that the MCMC case needs information that only the MCMC posterior has, namely the samples and chains per observation for batched sampling. The fix touched these posterior internals, so I ended up implementing it myself together with the other samplers.
The PR is #2023. It uses one shared helper for all samplers, very close to what you suggested. Thanks again for your input here.
Cheers, Jan
feat: consistent sampling progress bar descriptions (#2023)