\n",
" **Package versions**

\n",
"\n",
" The code on this page was developed using the following requirements.\n",
" We recommend using these versions or newer.\n",
"\n",
" ```\n",
" qiskit[all]~=1.2.4\n",
" qiskit-aer~=0.15.1\n",
" qiskit-ibm-runtime~=0.31.0\n",
" qiskit-serverless~=0.17.1\n",
" qiskit-ibm-catalog~=0.1\n",
" ```\n",
"

\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "076872c0-f8de-4aef-ae13-29078ee8564e",
"metadata": {},
"source": [
"This page provides high-level explanations of the error suppression and error mitigation techniques available through Qiskit Runtime.\n",
"\n",
"The following cell imports the Estimator primitive and creates a backend that will be used for initializing the Estimator in later code cells.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "39ef65e5",
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import EstimatorV2 as Estimator\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"service = QiskitRuntimeService()\n",
"backend = service.least_busy()"
]
},
{
"cell_type": "markdown",
"id": "ad548ef5-f1c1-4def-b551-b3ece2032065",
"metadata": {},
"source": [
"## Dynamical decoupling\n",
"\n",
"Quantum circuits are executed on IBMÂ® hardware as sequences of microwave pulses that need to be scheduled and run at precise time intervals.\n",
"Unfortunately, unwanted interactions between qubits can lead to coherent errors on idling qubits. Dynamical decoupling works by inserting pulse sequences on idling qubits to approximately cancel out the effect of these errors. Each inserted pulse sequence amounts to an identity operation, but the physical presence of the pulses has the effect of suppressing errors.\n",
"There are many possible choices of pulse sequences, and which sequence is better for each particular case remains an [active area of research](https://journals.aps.org/prapplied/abstract/10.1103/PhysRevApplied.20.064027).\n",
"\n",
"Note that dynamical decoupling is mainly useful for circuits containing gaps in which some qubits sit idle without any operations acting on them. If the operations in the circuit are packed very densely, such that all of the qubits are busy most of the time, then the addition of dynamical decoupling pulses might not improve performance. In fact, it could even worsen performance due to imperfections in the pulses themselves.\n",
"\n",
"The diagram below depicts dynamical decoupling with an XX pulse sequence. The abstract circuit on the left is mapped onto a microwave pulse schedule on the top right. The bottom right depicts the same schedule, but with a sequence of two X pulses inserted during an idle period of the first qubit.\n",
"\n",
"![Depiction of dynamical decoupling](/images/guides/error-mitigation-explanation/dd.jpg)\n",
"\n",
"Dynamical decoupling can be enabled by setting `enable` to `True` in the [dynamical decoupling options](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.DynamicalDecouplingOptions). The `sequence_type` option can be used to pick from several different pulse sequences. The default sequence type is `\"XX\"`.\n",
"\n",
"The following code cell shows how to enable dynamical decoupling for the Estimator and choose a dynamical decoupling sequence.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "cc057e3f-f592-434e-8bb2-96f901564318",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"estimator = Estimator(mode=backend)\n",
"estimator.options.dynamical_decoupling.enable = True\n",
"estimator.options.dynamical_decoupling.sequence_type = \"XpXm\""
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "56ed5785-e3a8-4dc5-8b55-ef876fccd592",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"## Pauli twirling\n",
"\n",
"Twirling, also known as [randomized compiling](https://journals.aps.org/pra/abstract/10.1103/PhysRevA.94.052325), is a widely used technique for converting arbitrary noise channels into noise channels with more specific structure.\n",
"\n",
"Pauli twirling is a special kind of twirling that uses Pauli operations. It has the effect of transforming any quantum channel into a Pauli channel. Performed alone, it can mitigate coherent noise because coherent noise tends to accumulate quadratically with the number of operations, whereas Pauli noise accumulates linearly. Pauli twirling is often combined with other error mitigation techniques that work better with Pauli noise than with arbitrary noise.\n",
"\n",
"Pauli twirling is implemented by sandwiching a chosen set of gates with randomly chosen single-qubit Pauli gates in such a way that the ideal effect of the gate remains the same. The result is that a single circuit is replaced with a random ensemble of circuits, all with the same ideal effect. When sampling the circuit, samples are drawn from multiple random instances, rather than just a single one.\n",
"\n",
"![Depiction of Pauli twirling](/images/guides/error-mitigation-explanation/pauli_twirling.png)\n",
"\n",
"Since most of the errors in current quantum hardware come from two-qubit gates, this technique is often applied exclusively to (native) two-qubit gates. The following diagram depicts some Pauli twirls for the CNOT and ECR gates. Every circuit within a row has the same ideal effect.\n",
"\n",
"![Depiction of gate twirls](/images/guides/error-mitigation-explanation/gate_twirls.png)\n",
"\n",
"Pauli twirling can be enabled by setting `enable_gates` to `True` in the [twirling options](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.TwirlingOptions). Other notable options include:\n",
"\n",
"* `num_randomizations`: The number of circuit instances to draw from the ensemble of twirled circuits.\n",
"* `shots_per_randomization`: The number of shots to sample from each circuit instance.\n",
"\n",
"The following code cell shows how to enable Pauli twirling and set these options for the estimator. None of these options are required to be set explicitly.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c3e12d44",
"metadata": {},
"outputs": [],
"source": [
"estimator = Estimator(mode=backend)\n",
"estimator.options.twirling.enable_gates = True\n",
"estimator.options.twirling.num_randomizations = 32\n",
"estimator.options.twirling.shots_per_randomization = 100"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ad9d9159-4277-4aec-bf26-da748e240f38",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"## Twirled readout error extinction (TREX)\n",
"\n",
"[Twirled readout error extinction (TREX)](https://journals.aps.org/pra/abstract/10.1103/PhysRevA.105.032620) mitigates the effect of measurement errors for the estimation of Pauli observable expectation values.\n",
"It is based on the notion of twirled measurements, which are accomplished by randomly substituting measurement gates by a sequence of (1) a Pauli X gate, (2) a measurement, and (3) classical bit flip. Just like in standard gate twirling, this sequence is equivalent to a plain measurement in the absence of noise, as depicted in the following diagram:\n",
"\n",
"![Depiction of measurement twirling](/images/guides/error-mitigation-explanation/measurement_twirling.png)\n",
"\n",
"In the presence of readout error, measurement twirling has the effect of diagonalizing the readout-error transfer matrix, making it easy to invert. Estimating the readout-error transfer matrix requires executing additional calibration circuits, which introduces a small overhead.\n",
"\n",
"TREX can be enabled by setting `measure_mitigation` to `True` in the [Qiskit Runtime resilience options](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.ResilienceOptionsV2) for Estimator. Options for measurement noise learning are described [here](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.MeasureNoiseLearningOptions). As with gate twirling, you can set the number of circuit randomizations and the number of shots per randomization.\n",
"\n",
"The following code cell shows how to enable TREX and set these options for the estimator. None of these options are required to be set explicitly.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "80c858e3",
"metadata": {},
"outputs": [],
"source": [
"estimator = Estimator(mode=backend)\n",
"estimator.options.resilience.measure_mitigation = True\n",
"estimator.options.resilience.measure_noise_learning.num_randomizations = 32\n",
"estimator.options.resilience.measure_noise_learning.shots_per_randomization = 100"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "7f345691-8330-40f5-a5c6-d6c5fb93409a",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"\n",
"\n",
"## Zero-noise extrapolation (ZNE)\n",
"\n",
"Zero-noise extrapolation (ZNE) is a technique for mitigating errors in estimating expectation values of observables. While it often improves results, it is not guaranteed to produce an unbiased result.\n",
"\n",
"ZNE consists of two stages:\n",
"\n",
"1. *Noise amplification*: The original quantum circuit is executed multiple times at different noise rates.\n",
"2. *Extrapolation*: The ideal result is estimated by extrapolating the noisy expectation value results to the zero-noise limit.\n",
"\n",
"Both the noise amplification and extrapolation stages can be implemented in many different ways. Qiskit Runtime implements noise amplification by \"digital gate folding,\" which means that two-qubit gates are replaced with equivalent sequences of the gate and its inverse. For example, replacing a unitary $U$ with $U U^\\dagger U$ would yield a noise amplification factor of 3. For the extrapolation, you can choose from one of several functional forms, including a linear fit or an exponential fit.\n",
"The image below depicts digital gate folding on the left, and the extrapolation procedure on the right.\n",
"\n",
"![Depiction of ZNE](/images/guides/error-mitigation-explanation/zne.png)\n",
"\n",
"ZNE can be enabled by setting `zne_mitigation` to `True` in the [Qiskit Runtime resilience options](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.ResilienceOptionsV2) for Estimator.\n",
"The Qiskit Runtime options for ZNE are described [here](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.ZneOptions). The following options are notable:\n",
"\n",
"* `noise_factors`: The noise factors to use for noise amplification.\n",
"* `extrapolator`: The functional form to use for the extrapolation.\n",
"\n",
"The following code cell shows how to enable ZNE and set these options for the estimator. None of these options are required to be set explicitly.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "06de4431",
"metadata": {},
"outputs": [],
"source": [
"estimator = Estimator(mode=backend)\n",
"estimator.options.resilience.zne_mitigation = True\n",
"estimator.options.resilience.zne.noise_factors = (1, 3, 5)\n",
"estimator.options.resilience.zne.extrapolator = \"exponential\""
]
},
{
"cell_type": "markdown",
"id": "e5dcab7b",
"metadata": {},
"source": [
"## Probabilistic Error Amplification (PEA)\n",
"\n",
"One of the main challenges in ZNE is to accurately amplify the noise affecting the target circuit. Gate folding provides an easy way to perform this amplification, but is potentially inaccurate and might lead to incorrect results. See the article [\"Scalable error mitigation for noisy quantum circuits produces competitive expectation values\"](https://www.nature.com/articles/s41567-022-01914-3), and specifically page 4 of the [supplementary material](https://arxiv.org/pdf/2108.09197) for details.\n",
"\n",
"PEA is a more sophisticated technique that performs preliminary experiments to reconstruct the noise and then uses this information to perform an accurate amplification. For utility-scale experiments, it is often the best choice.\n",
"\n",
"Because PEA is a ZNE noise amplification technique, you also need to enable ZNE by setting `resilience.zne_mitigation = True`. Other `resilience.zne` options can be used in addition to set extrapolators, amplification levels, and so on. PEA requires a noise model, which is automatically generated when using primitives.\n",
"\n",
"The following snippet provides an example where PEA is used to mitigate the result of an Estimator job:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4947f442",
"metadata": {},
"outputs": [],
"source": [
"estimator = Estimator(mode=backend)\n",
"estimator.options.resilience.zne_mitigation = True\n",
"estimator.options.resilience.zne.amplifier = \"pea\""
]
},
{
"cell_type": "markdown",
"id": "fcc40cb7-45b7-4248-84c4-aa7f26ba50ff",
"metadata": {},
"source": [
"\n",
"\n",
"## Probabilistic error cancellation (PEC)\n",
"\n",
"Probabilistic error cancellation (PEC) is a technique for mitigating errors in estimating expectation values of observables. Unlike ZNE, it returns an unbiased estimate of the expectation value. However, it generally incurs a greater overhead.\n",
"\n",
"In PEC, the effect of an ideal target circuit is expressed as a linear combination of noisy circuits that are actually implementable in practice:\n",
"\n",
"$$\n",
"\\mathcal{O}_{\\text{ideal}} = \\sum_{i} \\eta_i \\mathcal{O}_{noisy, i}\n",
"$$\n",
"\n",
"The output of the ideal circuit can then be reproduced by executing different noisy circuit instances drawn from a random ensemble defined by the linear combination. If the coefficients $\\eta_i$ form a probability distribution, they can be used directly as the probabilities of the ensemble. In practice, some of the coefficients are negative, so they form a quasi-probability distribution instead. They can still be used to define a random ensemble, but there is a sampling overhead related to the negativity of the quasi-probability distribution, which is characterized by the quantity\n",
"\n",
"$$\n",
"\\gamma = \\sum_{i} \\lvert \\eta_i \\rvert \\geq 1.\n",
"$$\n",
"\n",
"The sampling overhead is a multiplicative factor on the number of shots required to estimate an expectation value to a given precision, compared to the number of shots that would be needed from the ideal circuit. It scales quadratically with $\\gamma$, which in turn scales exponentially with the depth of the circuit.\n",
"\n",
"PEC can be enabled by setting `pec_mitigation` to `True` in the [Qiskit Runtime resilience options](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.ResilienceOptionsV2) for Estimator.\n",
"The Qiskit Runtime options for PEC are described [here](/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.PecOptions). A limit on the sampling overhead can be set using the `max_overhead` option. Note that limiting the sampling overhead can cause the precision of the result to exceed the requested precision. The default value of `max_overhead` is 100.\n",
"\n",
"The following code cell shows how to enable PEC and set the `max_overhead` option for the estimator.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f4ae33f2-3a4d-4869-952b-e5ebd9e69efc",
"metadata": {},
"outputs": [],
"source": [
"estimator = Estimator(mode=backend)\n",
"estimator.options.resilience.pec_mitigation = True\n",
"estimator.options.resilience.pec.max_overhead = 100"
]
},
{
"cell_type": "markdown",
"id": "b9b598a2-03c0-4ff9-ac47-d187693ac6e2",
"metadata": {},
"source": [
"## Next steps\n",
"\n",
"* Check out the [tutorial](https://learning.quantum.ibm.com/tutorial/combine-error-mitigation-options-with-the-estimator-primitive) on combining error mitigation options with the Estimator primitive.\n",
"* [Configure error mitigation.](configure-error-mitigation)\n",
"* [Configure error suppression.](configure-error-suppression)\n",
"* Explore other [options](runtime-options-overview) for the Qiskit Runtime primitives.\n",
"* Decide what [execution mode](execution-modes) to run your job in.\n",
"\n"
]
}
],
"metadata": {
"description": "Explanation of error mitigation and suppression techniques available through Qiskit Runtime",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3"
},
"title": "Error mitigation and suppression techniques"
},
"nbformat": 4,
"nbformat_minor": 5
}