Skip to content

ReadoutMitigationConfig

from cascaqit import ReadoutMitigationConfig

ReadoutMitigationConfig

ReadoutMitigationConfig(
    calibration: ReadoutCalibration,
    method: Literal[
        "tensor_product_linear_inverse"
    ] = "tensor_product_linear_inverse",
    max_condition_number: float = 100.0,
    schema_version: str = READOUT_MITIGATION_SCHEMA_VERSION,
)

Enable per-qubit linear-inverse readout mitigation for finite-shot Pauli estimates. calibration must be an explicit ReadoutCalibration; method currently supports only tensor_product_linear_inverse. max_condition_number must be finite and positive, defaulting to 100. It limits both individual matrices and the full tensor-product response. Singular matrices, nonfinite condition numbers and values above the limit are rejected at construction.

At execution, the calibration logical_order must exactly match the measured program, including order. The estimator transforms observable sample weights using g = A**(-T) f and retains covariance within a group. Backend raw counts are preserved. With finite samples, corrected weights can be negative and Pauli estimates can lie outside [-1, 1]; clipping them as if they were invalid raw probabilities changes the estimator.

Inversion can amplify variance. Error reduction depends on calibration accuracy, applicability and sample size. This does not remove gate or simulation errors, nor automatically account for uncertainty in the calibration itself.

from cascaqit import (HamiltonianTerm, NoiseChannel, NoiseModel, PauliHamiltonian,
                      PauliMeasurementConfig, PauliZ, ReadoutCalibration,
                      ReadoutMitigationConfig, VQE)

vqe = VQE(PauliHamiltonian("z", (HamiltonianTerm("z", 1.0, PauliZ("q0")),),
                           logical_order=("q0",)))
noise = NoiseModel("readout", (NoiseChannel.readout(0.1, p10=0.05),))
calibration = ReadoutCalibration.from_probabilities(
    logical_order=("q0",), p01=0.1, p10=0.05, source="teaching_simulation")
config = ReadoutMitigationConfig(calibration)
raw = vqe.evaluate_sampled((0.3, 0.1), seed=7, noise=noise,
                          measurement=PauliMeasurementConfig(shots_per_group=64))
corrected = vqe.evaluate_sampled((0.3, 0.1), seed=7, noise=noise,
    measurement=PauliMeasurementConfig(shots_per_group=64, mitigation=config))
assert raw.group_results[0].counts == corrected.group_results[0].counts
assert corrected.mitigated_energy is not None
assert corrected.raw_energy == raw.energy

from_dict

from_dict(
    data: Mapping[str, Any],
) -> ReadoutMitigationConfig

Restore ReadoutMitigationConfig from a dictionary. The nested calibration is required. Restoration verifies its digest, matrix invertibility and condition-number limit. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.

from_json

from_json(text: str) -> ReadoutMitigationConfig

Parse a JSON object and call from_dict(), returning ReadoutMitigationConfig. Invalid JSON raises a parsing error; a non-object root raises TypeError.

to_dict

to_dict() -> dict[str, Any]

Return a JSON-compatible dictionary, serializing nested objects and converting tuples to arrays. This stores the declaration, not an execution result.

to_json

to_json(*, indent: int | None = None) -> str

Return a JSON string without writing a file. indent=None uses compact formatting; supply an indentation width for readable output.

stable_hash

stable_hash() -> str

Return the SHA-256 hex digest of canonical JSON. Fields, identifiers and metadata can affect it. Use it to compare saved content, not to decide physical equivalence.