mimiqcircuits.backends.progress

Progress reporting for LocalBackend.execute().

The execute driver and backends open named stages and advance them; the concrete sink decides whether and how to render. NoProgress is the zero-cost default; TqdmProgress draws bars with tqdm.

A sink is driven through three verbs, all no-ops on NoProgress:

  • progress.stage(name, total=...) opens a bar and returns a stage.

  • stage.step(n=1) advances it.

  • stage.finish() closes it.

The driver owns the trajectory bar and, on the single-evolve path, an execution bar fed by the backend’s per-step callback. A backend with a countable compression step emits its own stage by overriding LocalBackend.compile_progress().

Functions

execution_progress_callback(progress, user, box)

Wrap a per-step callback so the execution bar advances on each step the backend reports, then forwards to user unchanged.

to_progress(progress)

Turn the progress argument of LocalBackend.execute() into a Progress.

Classes

NoProgress()

Sink that draws nothing; the default of LocalBackend.execute().

Progress()

Destination for execution progress, given to LocalBackend.execute() as progress.

Stage()

A single progress bar opened by Progress.stage().

TqdmProgress(*[, leave])

Sink that draws each stage as a tqdm bar.

class Stage[source]

Bases: ABC

A single progress bar opened by Progress.stage().

Subclasses implement step() and finish().

abstract step(n=1)[source]

Advance the bar by n steps.

abstract finish()[source]

Close the bar.

class Progress[source]

Bases: ABC

Destination for execution progress, given to LocalBackend.execute() as progress.

Subclasses implement stage(). NoProgress draws nothing and TqdmProgress draws tqdm bars.

Examples

A sink that prints every stage it is asked to open.

>>> from mimiqcircuits import *
>>> from mimiqcircuits.backends import NoProgress, Progress
>>> class PrintProgress(Progress):
...     def stage(self, name, *, total=None):
...         print(f"{name}: {total} steps")
...         return NoProgress().stage(name, total=total)
>>> bar = PrintProgress().stage("trajectories", total=100)
trajectories: 100 steps
>>> bar.step()
>>> bar.finish()
abstract stage(name, *, total=None)[source]

Open a stage.

Parameters:
  • name (str) – Name of the stage, such as "trajectories", "execute" or "compression".

  • total – Number of steps, or None when unknown.

Returns:

The Stage to advance and close.

Return type:

Stage

class NoProgress[source]

Bases: Progress

Sink that draws nothing; the default of LocalBackend.execute().

Its stages ignore Stage.step() and Stage.finish().

stage(name, *, total=None)[source]

Open a stage.

Parameters:
  • name (str) – Name of the stage, such as "trajectories", "execute" or "compression".

  • total – Number of steps, or None when unknown.

Returns:

The Stage to advance and close.

Return type:

Stage

class TqdmProgress(*, leave=False)[source]

Bases: Progress

Sink that draws each stage as a tqdm bar.

execute(progress=True) uses it with the default arguments.

Parameters:

leave (bool) – Keep each bar on screen after its stage finishes. The default, False, clears it, so successive stages do not pile up.

stage(name, *, total=None)[source]

Open a stage.

Parameters:
  • name (str) – Name of the stage, such as "trajectories", "execute" or "compression".

  • total – Number of steps, or None when unknown.

Returns:

The Stage to advance and close.

Return type:

Stage

to_progress(progress)[source]

Turn the progress argument of LocalBackend.execute() into a Progress.

Parameters:

progress – A Progress, returned as it is, or a bool: True gives TqdmProgress, False gives NoProgress.

Returns:

The Progress sink.

Raises:

TypeError – For any other type.

Return type:

Progress

execution_progress_callback(progress, user, box)[source]

Wrap a per-step callback so the execution bar advances on each step the backend reports, then forwards to user unchanged.

Backends report a step by calling callback(i, total): i is the 1-based step index and total the step count (or None when unknown). The stage is opened lazily on the first step so its total comes from the backend. box is a one-element list that receives the stage so the driver can close it once evolution returns.