bartz.mcmcloop.TqdmCallback

class bartz.mcmcloop.TqdmCallback(bar_id, update_every, report_every, accumulator)[source]

tqdm progress-bar callback for run_mcmc, create it with from_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 tqdm bar registry.

update_every: Int32[Array, '']

The bar position is refreshed every update_every MCMC iterations.

report_every: Int32[Array, ''] | None

The acceptance statistics are refreshed every report_every MCMC iterations, None to 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 tqdm progress-bar callback for run_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 every update_every MCMC iterations, and at the first one (tqdm further throttles the actual redraw rate on its own).

  • report_every (int | None, default: 100) – The acceptance statistics shown next to the bar are refreshed every report_every MCMC iterations, None to omit them.

  • average (bool, default: True) – If True, the statistics shown are averaged over the iterations since the previous refresh; if False, they reflect the current iteration only. Ignored when report_every is None.

  • **tqdm_kwargs (Any) – Additional keyword arguments forwarded to the tqdm.tqdm constructor, e.g., desc, file, or disable.

Returns:

TqdmCallback – A callback to pass as the callback argument of run_mcmc.

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 from_state call closes it, so a subsequent run starts from a clean line.

The callback drives a single bar for a single run_mcmc call: it is not reusable nor resumable, and in a further run_mcmc call it shows no bar. Create a new one for each call.

Examples

>>> run_mcmc(key, state, ..., callback=TqdmCallback.from_state(state, ...))
__call__(*, state, i_total, n_burn, n_save, n_skip, **_)[source]

Advance a tqdm progress bar during the MCMC.

Return type:

tuple[State, TqdmCallback]