QEMProtocol

class QEMProtocol[source]

Bases: ABC

Abstract base class for Quantum Error Mitigation protocols.

Subclasses implement two methods that mirror the pipeline’s expand/reduce lifecycle:

  • expand — given a Qiskit DAGCircuit and the observable tuple being measured, return the DAGs to execute on quantum hardware and a QEMContext carrying any classically- computed side-channel data needed during postprocessing.

  • reduce — given the context from expand and the quantum results, produce a list[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 reduce calls 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 that introspect() 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 dag is consumed by this method: implementations may mutate it, and callers must not retain it expecting the original state. This matches the broader pipeline convention for consumes_dag_bodies stages (see BundleStage).

Parameters:
  • dag (DAGCircuit) – Circuit to mitigate.

  • observable (tuple[SparsePauliOp, ...] | None) – tuple[SparsePauliOp, ...] (one entry per expectation value being measured), or None.

Return type:

tuple[tuple[DAGCircuit, ...], dict]

post_reduce(contexts)[source]

Hook called after all per-group reduce calls in an evaluation.

Protocols can override this to inspect the collected contexts and emit summary diagnostics (e.g. signal-destruction warnings).

Return type:

None

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_results is ordered along the QEM axis; each entry is itself a list[float] of per-observable expectation values from MeasurementStage.

Implementations may use context["dag_indices"] (when present) to select the relevant positions in quantum_results.

Return type:

list[float]