mici.progressbars module#

Progress bar classes for tracking progress of chains.

class mici.progressbars.DummyProgressBar(sequence, description, position=(0, 1))[source]#

Bases: ProgressBar

Placeholder progress bar which does not display progress updates.

Parameters:
  • sequence (Collection) – Sequence to iterate over. Must be iterable _and_ have a defined length such that len(sequence) is valid.

  • description (str | None) – Description of task to prefix progress bar with.

  • position (tuple[int, int]) – Tuple specifying position of progress bar within a sequence with first entry corresponding to zero-indexed position and the second entry the total number of progress bars.

property n_iter: int#
property sequence: Collection#

Sequence iterated over.

update(iter_count, iter_dict, *, refresh=True)[source]#

Update progress bar state.

Parameters:
  • iter_count (int) – New value for iteration counter.

  • iter_dict (dict[str, float] | None) – Dictionary of iteration statistics key-value pairs to use to update postfix stats.

  • refresh (bool) – Whether to refresh display(s).

Return type:

None

class mici.progressbars.FileDisplay(position=(0, 1), file=None)[source]#

Bases: object

Use file which supports ANSI escape sequences as an updatable display.

Parameters:
  • position (tuple[int, int]) – Tuple specifying position of display line within a sequence lines with first entry corresponding to zero-indexed line and the second entry the total number of lines.

  • file (TextIO | None) – File object to write updates to. Must support ANSI escape sequences x1b[A} (cursor up) and \x1b[B (cursor down) for manipulating write position. Defaults to sys.stdout if None.

CURSOR_DOWN = '\x1b[B'#

ANSI escape sequence to move cursor down one line.

CURSOR_UP = '\x1b[A'#

ANSI escape sequence to move cursor up one line.

update(obj)[source]#

Update display with string representation of object.

Parameters:

obj (Any) – Object to display.

Return type:

None

class mici.progressbars.LabelledSequenceProgressBar(labelled_sequence, description=None, position=(0, 1), displays=None)[source]#

Bases: ProgressBar

Iterable object for tracking progress of a sequence of labelled tasks.

Parameters:
  • labelled_sequence (dict[str, Any]) – Ordered dictionary with string keys corresponding to labels for stages represented by sequence and values the entries in the sequence being iterated over.

  • description (str | None) – Description of task to prefix progress bar with.

  • position (tuple[int, int]) – Tuple specifying position of progress bar within a sequence with first entry corresponding to zero-indexed position and the second entry the total number of progress bars.

  • displays (Collection | None) – List of objects to use to display visual representation(s) of progress bar. Each object much have an update method which will be passed a single argument corresponding to the current progress bar.

property completed_labels: list[str]#

Labels corresponding to completed iterations.

property counter: int#

Progress iteration count.

property current_label: str#

Label corresponding to current iteration.

property description: str#

Description of task being tracked.

property n_iter: int#
property postfix: str#

Text to postfix progress bar with.

property prefix: str#

Text to prefix progress bar with.

property progress_bar: str#

Progress bar string.

refresh()[source]#

Refresh visual display(s) of status bar.

Return type:

None

reset()[source]#

Reset progress bar state.

Return type:

None

property sequence: Collection#

Sequence iterated over.

property stats: str#

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

property unstarted_labels: list[str]#

Labels corresponding to unstarted iterations.

update(iter_count, iter_dict=None, *, refresh=True)[source]#

Update progress bar state.

Parameters:
  • iter_count (int) – New value for iteration counter.

  • iter_dict (dict[str, float] | None) – Dictionary of iteration statistics key-value pairs to use to update postfix stats.

  • refresh (bool) – Whether to refresh display(s).

Return type:

None

class mici.progressbars.ProgressBar(sequence, description, position=(0, 1))[source]#

Bases: ABC

Base class defining expected interface for progress bars.

Parameters:
  • sequence (Collection) – Sequence to iterate over. Must be iterable _and_ have a defined length such that len(sequence) is valid.

  • description (str | None) – Description of task to prefix progress bar with.

  • position (tuple[int, int]) – Tuple specifying position of progress bar within a sequence with first entry corresponding to zero-indexed position and the second entry the total number of progress bars.

property n_iter: int#
property sequence: Collection#

Sequence iterated over.

abstract update(iter_count, iter_dict, *, refresh=True)[source]#

Update progress bar state.

Parameters:
  • iter_count (int) – New value for iteration counter.

  • iter_dict (dict[str, float] | None) – Dictionary of iteration statistics key-value pairs to use to update postfix stats.

  • refresh (bool) – Whether to refresh display(s).

Return type:

None

class mici.progressbars.SequenceProgressBar(sequence, description=None, position=(0, 1), displays=None, n_col=10, unit='it', min_refresh_time=0.25)[source]#

Bases: ProgressBar

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.

Parameters:
  • sequence (Collection) – Sequence to iterate over. Must be iterable and have a defined length such that len(sequence) is valid.

  • description (str | None) – Description of task to prefix progress bar with.

  • position (tuple[int, int]) – Tuple specifying position of progress bar within a sequence with first entry corresponding to zero-indexed position and the second entry the total number of progress bars.

  • displays (Collection | None) – List of objects to use to display visual representation(s) of progress bar. Each object much have an update method which will be passed a single argument corresponding to the current progress bar.

  • n_col (int) – Number of columns (characters) to use in string representation of progress bar.

  • unit (str) – String describing unit of per-iteration tasks.

  • min_referesh_time – Minimum time in seconds between each refresh of progress bar visual representation.

  • min_refresh_time (float)

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

Characters used to create string representation of progress bar.

property bar_color: str#

CSS color property for HTML progress bar.

property counter: int#

Progress iteration count.

property description: str#

Description of task being tracked.

property elapsed_time: str#

Elapsed time formatted as string.

property empty_blocks: str#

Empty blocks string.

property est_remaining_time: str#

Estimated remaining time to completion formatted as string.

property filled_blocks: str#

Filled blocks string.

property iter_rate: str#

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

property n_block_empty: int#

Number of empty blocks in progress bar.

property n_block_filled: int#

Number of filled blocks in progress bar.

property n_iter: int#
property partial_block: str#

Partial block character.

property perc_complete: str#

Percentage complete formatted as string.

property postfix: str#

Text to postfix progress bar with.

property prefix: str#

Text to prefix progress bar with.

property progress_bar: str#

Progress bar string.

property prop_complete: float#

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

property prop_partial_block: float#

Proportion filled in partial block in progress bar.

refresh()[source]#

Refresh visual display(s) of progress bar.

Return type:

None

reset()[source]#

Reset progress bar state.

Return type:

None

property sequence: Collection#

Sequence iterated over.

property stats: str#

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

update(iter_count, iter_dict=None, *, refresh=True)[source]#

Update progress bar state.

Parameters:
  • iter_count (int) – New value for iteration counter.

  • iter_dict (dict[str, float] | None) – Dictionary of iteration statistics key-value pairs to use to update postfix stats.

  • refresh (bool) – Whether to refresh display(s).

Return type:

None

class mici.progressbars.UpdateableDisplay(*args, **kwargs)[source]#

Bases: Protocol

Updateable display.

update(obj)[source]#

Update display with representation of object.

Parameters:

obj (Any)

Return type:

None