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
|
Wrap a per-step |
|
Turn the |
Classes
Sink that draws nothing; the default of |
|
|
Destination for execution progress, given to |
|
A single progress bar opened by |
|
Sink that draws each stage as a tqdm bar. |
- class Stage[source]¶
Bases:
ABCA single progress bar opened by
Progress.stage().
- class Progress[source]¶
Bases:
ABCDestination for execution progress, given to
LocalBackend.execute()asprogress.Subclasses implement
stage().NoProgressdraws nothing andTqdmProgressdraws 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()
- class NoProgress[source]¶
Bases:
ProgressSink that draws nothing; the default of
LocalBackend.execute().Its stages ignore
Stage.step()andStage.finish().
- class TqdmProgress(*, leave=False)[source]¶
Bases:
ProgressSink 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.
- to_progress(progress)[source]¶
Turn the
progressargument ofLocalBackend.execute()into aProgress.- Parameters:
progress – A
Progress, returned as it is, or a bool:TruegivesTqdmProgress,FalsegivesNoProgress.- Returns:
The
Progresssink.- Raises:
TypeError – For any other type.
- Return type:
- execution_progress_callback(progress, user, box)[source]¶
Wrap a per-step
callbackso the execution bar advances on each step the backend reports, then forwards touserunchanged.Backends report a step by calling
callback(i, total):iis the 1-based step index andtotalthe step count (orNonewhen unknown). The stage is opened lazily on the first step so its total comes from the backend.boxis a one-element list that receives the stage so the driver can close it once evolution returns.