bartz.mcmcloop.TqdmCallback¶
- class bartz.mcmcloop.TqdmCallback(bar_id, update_every, report_every, accumulator)[source]¶
tqdmprogress-bar callback forrun_mcmc, create it withfrom_state.The callback shows a progress bar that advances with the MCMC iterations, optionally annotated with the proposal acceptance statistics.
- bar_id: Int32[Array, '']¶
Handle identifying the bar in the module-level
tqdmbar registry.
- update_every: Int32[Array, '']¶
The bar position is refreshed every
update_everyMCMC iterations.
- report_every: Int32[Array, ''] | None¶
The acceptance statistics are refreshed every
report_everyMCMC iterations,Noneto omit them.
- accumulator: StatsAccumulator¶
Running average of the reported statistics, inert unless averaging.
- classmethod from_state(state, *, update_every=1, report_every=100, average=True, **tqdm_kwargs)[source]¶
Prepare a
tqdmprogress-bar callback forrun_mcmc.- 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, and at the first one (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:
TqdmCallback– A callback to pass as thecallbackargument ofrun_mcmc.
Notes
Works with chains sharded across multiple devices, and with concurrent runs in separate threads. If the run is interrupted (e.g. with ^C), the bar is left as-is; the next
from_statecall in the same thread closes it, so a subsequent run starts from a clean line.The callback drives a single bar for a single
run_mcmccall: it is not reusable nor resumable, and in a furtherrun_mcmccall it shows no bar. Create a new one for each call.Examples
>>> run_mcmc(key, state, ..., callback=TqdmCallback.from_state(state, ...))