tlo.progressbar module

Progress bar for visualising progress of simulation runs.

class ProgressBar(n_step: int, description: Optional[str] = None, n_col: int = 10, unit: str = 'step', min_refresh_time: float = 1.0)[source]

Bases: object

Iterable object for tracking progress of an iterative task.

Implements both string and HTML representations to allow richer display in interfaces which support HTML output, for example Jupyter notebooks or interactive terminals.

GLYPHS = ' ▏▎▍▌▋▊▉█'

Characters used to create string representation of progress bar.

property n_step

Total number of steps in task.

property description

“Description of task being tracked.

property step

Progress step count.

property prop_complete

Proportion complete (float value in [0, 1]).

property perc_complete

Percentage complete formatted as string.

property elapsed_time

Elapsed time formatted as string.

property iter_rate

Mean iteration rate if ≥ 1 unit/s or reciprocal s/unit as string.

property est_remaining_time

Estimated remaining time to completion formatted as string.

property n_block_filled

Number of filled blocks in progress bar.

property n_block_empty

Number of empty blocks in progress bar.

property prop_partial_block

Proportion filled in partial block in progress bar.

property filled_blocks

Filled blocks string.

property empty_blocks

Empty blocks string.

property partial_block

Partial block character.

property progress_bar

Progress bar string.

property bar_color

CSS color property for HTML progress bar.

property stats

Comma-delimited string list of statistic key=value pairs.

property prefix

Text to prefix progress bar with.

property postfix

Text to postfix progress bar with.

reset()[source]

Reset progress bar state.

update(step: int, stats_dict: Optional[Dict] = None, refresh: bool = True)[source]

Update progress bar state.

Parameters
  • step – New value for step counter.

  • stats_dict – Dictionary of statistic key-value pairs to use to update postfix stats.

  • refresh – Whether to refresh display.

refresh()[source]

Refresh visual display(s) of progress bar.

start()[source]

Start tracking progress of task.

stop()[source]

Stop tracking progress of task.

class StreamDisplay(io: Optional[TextIO] = None)[source]

Bases: object

Base class for using I/O streams as an updatable display.

close()[source]
update(obj)[source]

Update display with string representation of obj.

class AnsiStreamDisplay(io: Optional[TextIO] = None)[source]

Bases: tlo.progressbar.StreamDisplay

Use I/O stream which supports ANSI escape sequences as an updatable display.

update(obj)[source]

Update display with string representation of obj.

class BasicStreamDisplay(io: Optional[TextIO] = None)[source]

Bases: tlo.progressbar.StreamDisplay

Use I/O stream without ANSI escape sequence support as an updatable display.

update(obj)[source]

Update display with string representation of obj.