Configure error mitigation
Error mitigation techniques allow users to mitigate circuit errors by modeling the device noise at the time of execution. This typically results in quantum pre-processing overhead related to model training and classical post-processing overhead to mitigate errors in the raw results by using the generated model.
The Estimator primitive supports several error mitigation techniques, including TREX, ZNE, PEC, and PEA. See Error mitigation and suppression techniques for an explanation of each. When using primitives, you can turn on or off individual methods. See the Custom error settings section for details.
Sampler does not support error mitigation, but you can use the mthree (matrix-free measurement mitigation) package to perform error mitigation locally.
Estimator also supports resilience_level
. The resilience level specifies how much resilience to build against
errors. Higher levels generate more accurate results, at the expense of
longer processing times. Resilience levels can be used to configure the
cost/accuracy trade-off when applying error mitigation to your primitive
query. Error mitigation reduces errors (bias) in results by processing
the outputs from a collection, or ensemble, of related circuits. The
degree of error reduction depends on the method applied. The resilience
level abstracts the detailed choice of error mitigation method to allow
users to reason about the cost/accuracy trade that is appropriate to
their application.
Given this, each level corresponds to a method or methods with increasing level of quantum sampling overhead to enable you experiment with different time-accuracy tradeoffs. The following table shows you which levels and corresponding methods are available for each of the primitives.
Error mitigation is task-specific, so the techniques you can apply vary based whether you are sampling a distribution or generating expectation values.
Estimator supports the following resilience levels. Sampler does not support resilience levels.
Resilience Level | Definition | Technique |
---|---|---|
0 | No mitigation | None |
1 [Default] | Minimal mitigation costs: Mitigate error associated with readout errors | Twirled Readout Error eXtinction (TREX) measurement twirling |
2 | Medium mitigation costs. Typically reduces bias in estimators, but is not guaranteed to be zero-bias. | Level 1 + Zero Noise Extrapolation (ZNE) and gate twirling |
Resilience levels are currently in beta so sampling overhead and solution quality will vary from circuit to circuit. New features, advanced options, and management tools will be released on a rolling basis. Specific error mitigation methods are not guaranteed to be applied at each resilience level.
Configure Estimator with resilience levels
You can use resilience levels to specify error mitigation techniques, or you can set custom techniques individually as described in Custom error settings.
Resilience Level 0
No error mitigation is applied to the user program.
Resilience Level 1
Level 1 applies readout error mitigation and measurement twirling by applying a model-free technique known as Twirled Readout Error eXtinction (TREX). It reduces measurement error by diagonalizing the noise channel associated with measurement by randomly flipping qubits through X gates immediately before measurement. A rescaling term from the diagonal noise channel is learned by benchmarking random circuits initialized in the zero state. This allows the service to remove bias from expectation values that result from readout noise. This approach is described further in Model-free readout-error mitigation for quantum expectation values.
Resilience Level 2
Level 2 applies the error mitigation techniques included in level 1 and also applies gate twirling and uses the Zero Noise Extrapolation method (ZNE). ZNE computes an expectation value of the observable for different noise factors (amplification stage) and then uses the measured expectation values to infer the ideal expectation value at the zero-noise limit (extrapolation stage). This approach tends to reduce errors in expectation values, but is not guaranteed to produce an unbiased result.
The overhead of this method scales with the number of noise factors. The default settings sample the expectation value at three noise factors, leading to a roughly 3x overhead when employing this resilience level.
In Level 2, the TREX method randomly flips qubits through X gates immediately before measurement, and flips the corresponding measured bit if an X gate was applied. This approach is described further in Model-free readout-error mitigation for quantum expectation values.
Example
The EstimatorV2
interface lets users seamlessly work with the variety of
error mitigation methods to reduce error in expectation values of
observables. The following code uses Zero Noise Extrapolation and readout error mitigation by simply
setting resilience_level 2
.
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
# Setting options during primitive initialization
estimator = Estimator(backend, options={"resilience_level": 2})
Custom error settings
You can turn on and off individual error mitigation and suppression methods, including dynamical decoupling, gate and measurement twirling, measurement error mitigation, PEC, and ZNE. See Error mitigation and suppression techniques for an explanation of each.
- Not all options are available for both primitives. See the available options table for the list of available options.
- Not all methods work together on all types of circuits. See the feature compatibility table for details.
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
estimator = Estimator(backend)
options = estimator.options
# Turn on gate twirling.
options.twirling.enable_gates = True
# Turn on measurement error mitigation.
options.resilience.measure_mitigation = True
print(f">>> gate twirling is turned on: {estimator.options.twirling.enable_gates}")
print(f">>> measurement error mitigation is turned on: {estimator.options.resilience.measure_mitigation}")
from qiskit_ibm_runtime import SamplerV2 as Sampler
# Estimator and Sampler have different options
options = sampler.options
options.dynamical_decoupling.enable = True
# Turn on gate twirling. Requires qiskit_ibm_runtime 0.23.0 or later.
options.twirling.enable_gates = True
print(f">>> dynamical decoupling is turned on: {sampler.options.dynamical_decoupling.enable}")
print(f">>> gate twirling is turned on: {sampler.options.twirling.enable_gates}")
Turn off all error mitigation
For instructions to turn off all error mitigation, see the Turn off all error suppression and mitigation section.
Next steps
- Walk through an example that uses error mitigation in the Cost function lesson in IBM Quantum Learning.
- Learn more about error mitigation and error suppression techniques.
- Configure error suppression.
- Explore other options.
- Decide what execution mode to run your job in.