RichProgressBarWrapper#

class braintools.trainer.RichProgressBarWrapper(**kwargs)#

Progress bar wrapper using rich.

Provides beautiful progress bars with rich library features.

Parameters:

**kwargs – Additional arguments passed to rich Progress.

Examples

Keyword arguments go to rich.progress.Progress; here it renders to an in-memory console:

>>> import io
>>> from rich.console import Console
>>> import braintools
>>> buf = io.StringIO()
>>> pbar = braintools.trainer.RichProgressBarWrapper(console=Console(file=buf))
>>> pbar.start(total=3, desc='Training')
>>> pbar.update(3)
>>> pbar.set_postfix({'loss': 0.5})
>>> pbar.close()
>>> 'Training loss=0.5000' in buf.getvalue()
True
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.