QuantumProgram¶
- class QuantumProgram(backend, seed=None, progress_queue=None, program_id=None, precision=8, **kwargs)[source]¶
Bases:
ABCAbstract base class for quantum programs.
- Subclasses must implement:
run(): Execute the quantum algorithm
- Variables:
backend – The quantum circuit execution backend.
_seed – Random seed for reproducible results.
_progress_queue – Queue for progress reporting.
Initialize the QuantumProgram.
- Parameters:
backend (
CircuitRunner) – Quantum circuit execution backend.seed (
int|None) – Random seed for reproducible results. Defaults to None.progress_queue (
Queue|None) – Queue for progress reporting. Defaults to None.program_id (
str|None) – Program identifier for progress reporting in batch operations. If provided along with progress_queue, enables queue-based progress reporting.precision (
int) – Decimal places for numeric parameter values in QASM emission. Higher values produce longer QASM strings; lower values shrink them at the cost of parameter resolution. Defaults toDEFAULT_PRECISION.
Attributes Summary
Decimal places used for numeric parameter values in QASM emission.
Get the total number of circuits executed.
Get the total runtime across all circuit executions.
Methods Summary
Cancel the currently running cloud job if one exists.
dry_run(*[, force_circuit_generation])Run forward pass on all pipelines and return a fan-out analysis.
Return True once the program has produced results.
run(**kwargs)Execute the quantum algorithm.
Attributes Documentation
- precision¶
Decimal places used for numeric parameter values in QASM emission.
- total_circuit_count¶
Get the total number of circuits executed.
- Returns:
Cumulative count of circuits submitted for execution.
- Return type:
- total_run_time¶
Get the total runtime across all circuit executions.
- Returns:
Cumulative execution time in seconds.
- Return type:
Methods Documentation
- cancel_unfinished_job()[source]¶
Cancel the currently running cloud job if one exists.
This method attempts to cancel the job associated with the current ExecutionResult. It is best-effort and will log warnings for any errors (e.g., job already completed, permission denied) without raising exceptions.
This is typically called by ProgramEnsemble when handling cancellation to ensure cloud jobs are cancelled before local threads terminate.
- dry_run(*, force_circuit_generation=False)[source]¶
Run forward pass on all pipelines and return a fan-out analysis.
Traverses each pipeline stage without executing circuits and collects the fan-out factor, per-stage metadata, and total circuit count into a dict of
DryRunReportobjects keyed by the names registered in_build_pipelines(). Pass the returned dict toformat_dry_run()for the pretty tree output.Uses the analytic dry path by default; see the user guide for how that trades circuit generation for multiplicative-factor bookkeeping.
- Parameters:
force_circuit_generation (
bool) – IfTrue, force every stage to run its fullexpandpath so that the trace contains real DAGs and QASM strings. Useful when inspecting actual pipeline output (e.g. debugging a stage’s circuit transformation). Defaults toFalse.- Return type:
Example
>>> from divi.pipeline import format_dry_run >>> reports = program.dry_run() >>> format_dry_run(reports) # pretty-print to stdout
- abstractmethod has_results()[source]¶
Return True once the program has produced results.
- Return type: