Configure noise management with Estimator
Package versions
The code on this page was developed using the following requirements. We recommend using these versions or newer.
qiskit-ibm-runtime~=0.47.0
There are several ways to manage noise, typically by using various error mitigation and error suppression techniques to avoid errors before they happen. These techniques usually cause pre-processing overhead. Therefore, it is important to achieve a balance between perfecting your results and ensuring that your job completes in a reasonable amount of time.
Estimator supports the following noise management techniques. See Error mitigation and suppression techniques for an explanation of each. See the Custom noise management settings section for an example of enabling these techniques.
Dynamical decoupling
How to enable: options.dynamical_decoupling.enable = True
API Reference: DynamicalDecouplingOptions
Notable options: sequence_type
Pauli twirling
How to enable: options.twirling.enable_gates = True
API Reference: TwirlingOptions
Notable options: num_randomizations, shots_per_randomization
TREX
How to enable: options.resilience.measure_mitigation = True
API Reference: MeasureNoiseLearningOptions
Notable options:
ZNE
How to enable: options.resilience.zne_mitigation = True
API Reference: ZneOptions
Notable options: noise_factors, extrapolator
PEA
How to enable: (Must also enable ZNE) options.resilience.zne_mitigation = True and options.resilience.zne.amplifier = "pea"
API Reference: ZneOptions
Notable options: noise_factors, extrapolator
PEC
How to enable: options.resilience.pec_mitigation = True
API Reference: PecOptions
Notable options: max_overhead
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 noise management to your primitive
query. Noise management 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 noise management 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.
| Resilience Level | Description | 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 noise management methods are not guaranteed to be applied at each resilience level.
Configure Estimator with resilience levels
You can use resilience levels to specify noise management techniques, or you can set custom techniques individually as described in Custom noise management settings.
Any options you manually specify in addition to the resilience level are applied in addition to the base set of options defined by the resilience level. Therefore, in principle, you could set the resilience level to 1, but then turn off measurement mitigation, although this is not advised.
For example, setting the resilience level to 0 turns off zne_mitigation, but estimator.options.resilience.zne_mitigation = True overrides that value.
Example
The following code enables ZNE, TREX, and gate twirling by
setting resilience_level 2.
# Added by doQumentation — installs the packages this notebook needs if they are missing
import importlib.util
_needed = {"qiskit_ibm_runtime": "qiskit-ibm-runtime"}
_missing = [pip for module, pip in _needed.items()
if importlib.util.find_spec(module) is None]
# One at a time, so a package that fails to install does not block the others
for _pip in _missing:
%pip install -q {_pip}
if not _missing:
print("\u2713 All required packages are installed")
from qiskit_ibm_runtime import QiskitRuntimeService
# Legacy server-side primitive before qiskit-ibm-runtime 0.50.0
# from qiskit_ibm_runtime import Estimator
# Client-side primitive introduced in qiskit-ibm-runtime 0.50.0
from qiskit_ibm_runtime.executor_estimator import Estimator
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
# Setting options during primitive initialization
estimator = Estimator(backend, options={"resilience_level": 2})
Custom noise management settings
You can turn on and off individual noise management methods by using the Estimator options.
- Not all options work together on all types of circuits. See the feature compatibility table for details.
- If you are using the new client-side Estimator introduced in
qiskit-ibm-runtimev0.50.0, a separate noise-learning job is required to use PEA and PEC. See Migrate from server-side to client-side Sampler and Estimator for more information.
Full example with multiple options
from qiskit_ibm_runtime import QiskitRuntimeService
# Legacy server-side primitive before qiskit-ibm-runtime 0.50.0
# from qiskit_ibm_runtime import Estimator
# Client-side primitive introduced in qiskit-ibm-runtime 0.50.0
from qiskit_ibm_runtime.executor_estimator import 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: "
f"{estimator.options.twirling.enable_gates}"
)
>>> gate twirling is turned on: True
>>> measurement error mitigation is turned on: True
Turn off all error mitigation
For instructions to turn off all error mitigation see the Turn off all error suppression and mitigation section in the Estimator options guide.
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.
- Explore Estimator options.
- Decide what execution mode to run your job in.