QEMProtocol¶
- class QEMProtocol[source]¶
Bases:
ABCAbstract base class for Quantum Error Mitigation protocols.
Subclasses implement two methods that mirror the pipeline’s expand/reduce lifecycle:
expand— given a QiskitDAGCircuitand the observable tuple being measured, return the DAGs to execute on quantum hardware and aQEMContextcarrying any classically- computed side-channel data needed during postprocessing.reduce— given the context fromexpandand the quantum results, produce alist[float]of per-observable mitigated expectation values.
The observable flows through as a
tuple[SparsePauliOp, ...]and is forwarded unchanged to whichever stage needs its structure.Attributes Summary
Methods Summary
dry_expand(dag[, observable])Analytic counterpart to
expand()used by dry-run pipelines.expand(dag[, observable])Generate DAGs and classical context for error mitigation.
post_reduce(contexts)Hook called after all per-group
reducecalls in an evaluation.reduce(quantum_results, context)Combine quantum results with classical context into mitigated values.
Attributes Documentation
- name¶
Methods Documentation
- dry_expand(dag, observable=None)[source]¶
Analytic counterpart to
expand()used by dry-run pipelines.Must emit the same number of DAGs as
expand()would on the same input and populate any context keys thatintrospect()inspects (n_rotations,n_paths,symbolic) so dry-run reports render correctly. Implementations should skip any computation that only matters at reduction time — classical simulation, weight evaluation, deep-copying the DAG for each scale factor, etc.The default implementation falls back to
expand(), which is correct but not necessarily fast; override on expensive protocols (e.g. QuEPP’s Clifford simulation).- Return type:
tuple[tuple[DAGCircuit,...],dict]
- abstractmethod expand(dag, observable=None)[source]¶
Generate DAGs and classical context for error mitigation.
The input
dagis consumed by this method: implementations may mutate it, and callers must not retain it expecting the original state. This matches the broader pipeline convention forconsumes_dag_bodiesstages (seeBundleStage).- Parameters:
dag (
DAGCircuit) – Circuit to mitigate.observable (
tuple[SparsePauliOp,...] |None) –tuple[SparsePauliOp, ...](one entry per expectation value being measured), orNone.
- Return type:
tuple[tuple[DAGCircuit,...],dict]
- post_reduce(contexts)[source]¶
Hook called after all per-group
reducecalls in an evaluation.Protocols can override this to inspect the collected contexts and emit summary diagnostics (e.g. signal-destruction warnings).
- Return type:
- abstractmethod reduce(quantum_results, context)[source]¶
Combine quantum results with classical context into mitigated values.
Returns a
list[float]of per-observable mitigated values.quantum_resultsis ordered along the QEM axis; each entry is itself alist[float]of per-observable expectation values fromMeasurementStage.Implementations may use
context["dag_indices"](when present) to select the relevant positions inquantum_results.