Circuits

The divi.circuits module provides circuit abstractions for quantum program generation, execution, and error mitigation.

Warning

Developer-Facing Classes: The core circuit class MetaCircuit is intended for advanced users and developers. Most users should interact with circuits through higher-level APIs in the divi.qprog module.

Core

Functions

build_template(qasm_body, symbol_names)

Split a QASM string at symbol boundaries into a QASMTemplate.

dag_to_qasm_body(dag[, precision])

Emit a body-only parametric OpenQASM 2.0 string from a DAG.

measurement_qasms_from_groups(...[, measure_all])

Emit body-only measurement QASM per commuting observable group.

qnode_to_meta(qnode, *[, arg_shapes, precision])

Convert a QNode directly to a MetaCircuit.

qscript_to_meta(qscript[, precision, ...])

Shared helper: convert a PennyLane QuantumScript to a MetaCircuit.

render_template(template, formatted_values)

Render a QASMTemplate with concrete parameter values.

Classes

MetaCircuit(circuit_bodies[, parameters, ...])

Logical circuit IR.

QASMTemplate(fragments, slot_indices)

Pre-split QASM body for fast parameter substitution.

TemplateEntry(template_qasm, ...)

One parametric circuit ready for backend-side substitution.

Variables

DEFAULT_PRECISION

int([x]) -> integer int(x, base=10) -> integer

AxisLabel

Built-in immutable sequence.

QASMTag

Built-in immutable sequence.

Error Mitigation Protocols

Divi provides quantum error mitigation (QEM) capabilities to improve the accuracy of quantum computations in the presence of noise. All protocols inherit from QEMProtocol.

Functions

global_fold(dag, scale)

Apply GlobalFoldPass and return (folded_dag, effective_scale).

local_fold(dag, scale, *[, selection, ...])

Apply LocalFoldPass and return (folded_dag, effective_scale).

Classes

QEMProtocol()

Abstract base class for Quantum Error Mitigation protocols.

ZNE(scale_factors[, folding_fn, extrapolator])

Zero Noise Extrapolation.

ZNEExtrapolator(*args, **kwargs)

Structural type for zero-noise extrapolation.

LinearExtrapolator()

Fit a line y = a + b·s and return a (the intercept at s=0).

RichardsonExtrapolator()

Richardson (Lagrange) extrapolation through all N points to s=0.

GlobalFoldPass(scale_factor)

Global unitary folding with fractional scale-factor support.

LocalFoldPass(scale_factor[, selection, ...])

Per-gate folding with fractional scale-factor support.

Variables

FoldingFn

Type for the folding callable — given a DAGCircuit and a requested scale_factor, return (folded_dag, effective_scale).

Quantum Enhanced Pauli Propagation (QuEPP)

Quantum Enhanced Pauli Propagation (QuEPP) error mitigation protocol.

Implements the hybrid classical-quantum error mitigation scheme from Majumder et al. (arXiv:2603.14485). QuEPP decomposes a quantum circuit into alternating Clifford layers and non-Clifford Pauli rotations via Clifford Perturbation Theory (CPT). Low-order Pauli paths are simulated classically; the residual is corrected using noisy quantum execution with an empirical rescaling factor.

The decomposition uses the paper’s Heisenberg-picture back-propagation with weights cos(θ)/sin(θ) and R_P(π/2) Clifford replacements. The observable is tracked as a Pauli string; gates that commute with the current observable contribute weight 1 (no branching), which can dramatically reduce path count.

Classes

QuEPP([truncation_order, ...])

Quantum Enhanced Pauli Propagation (QuEPP) error mitigation.