SimpleProgressBar#

class braintools.trainer.SimpleProgressBar(width=50, refresh_rate=0.1)#

Simple text-based progress bar with no dependencies.

Provides a basic progress bar that works in any terminal.

Parameters:
  • width (int) – Width of the progress bar in characters.

  • refresh_rate (float) – Minimum time between updates in seconds.

Examples

The bar redraws itself in place with \r; here the output is captured and only the final frame is shown:

>>> import contextlib, io
>>> import braintools
>>> buf = io.StringIO()
>>> with contextlib.redirect_stdout(buf):
...     pbar = braintools.trainer.SimpleProgressBar(width=10)
...     pbar.start(total=4, desc='Training')
...     for _ in range(4):
...         pbar.update(1)
...     pbar.set_postfix({'loss': 0.25})
...     pbar.close()
>>> print(buf.getvalue().split('\r')[-1].strip())
Training: 100.0%|=========>| 4/4 [...] loss=0.2500
close()[source]#

Close the progress bar.

set_postfix(metrics)[source]#

Set postfix text with metrics.

Parameters:

metrics (Dict[str, Any]) – Metrics to display.

start(total=None, desc='', unit='it')[source]#

Start the progress bar.

Parameters:
  • total (int | None) – Total number of iterations.

  • desc (str) – Description to display.

  • unit (str) – Unit name for iterations.

update(n=1, **kwargs)[source]#

Update the progress bar.

Parameters:
  • n (int) – Number of iterations to advance.

  • **kwargs – Additional metrics to display.