bartz.mcmcloop.make_tqdm_callback¶
- bartz.mcmcloop.make_tqdm_callback(state, *, update_every=1, report_every=100, average=True, **tqdm_kwargs)[source]¶
Prepare a
tqdmprogress-bar callback forrun_mcmc.The callback shows a progress bar that advances with the MCMC iterations, optionally annotated with the proposal acceptance statistics.
- Parameters:
state (
State) – The MCMC state to use the callback with, used to determine device sharding.update_every (
int, default:1) – The bar position is refreshed everyupdate_everyMCMC iterations (tqdmfurther throttles the actual redraw rate on its own).report_every (
int|None, default:100) – The acceptance statistics shown next to the bar are refreshed everyreport_everyMCMC iterations,Noneto omit them.average (
bool, default:True) – IfTrue, the statistics shown are averaged over the iterations since the previous refresh; ifFalse, they reflect the current iteration only. Ignored whenreport_everyisNone.**tqdm_kwargs (
Any) – Additional keyword arguments forwarded to thetqdm.tqdmconstructor, e.g.,desc,file, ordisable.
- Returns:
dict[str,Any] – A dictionary with the arguments to pass torun_mcmcas keyword arguments to set up the callback.
Notes
Works with chains sharded across multiple devices. If the run is interrupted (e.g. with ^C), the bar is left as-is; the next
make_tqdm_callbackcall closes it, so a subsequent run starts from a clean line.Examples
>>> run_mcmc(key, state, ..., **make_tqdm_callback(state, ...))