Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error mitigation explanation notebook #1482

Merged
merged 22 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/run/_toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
{
"title": "Advanced runtime options",
"url": "/run/advanced-runtime-options"
},
{
"title": "Error mitigation technique explanations",
"url": "/run/error-mitigation-explanation"
}
]
},
Expand Down
274 changes: 274 additions & 0 deletions docs/run/error-mitigation-explanation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "b1267e87-e0b3-4934-b4b8-0265fe84adfd",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"source": [
"# Error mitigation technique explanations\n",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"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."
]
},
{
"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": {
"vscode": {
"languageId": "plaintext"
}
},
"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",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"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 cohoice 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",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"\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/run/error-mitigation-explanation/dd.jpg)\n",
"\n",
"The Qiskit Runtime options for dynamical decoupling are described [here](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.DynamicalDecouplingOptions). Notably, the `sequence_type` option can be used to pick from several different pulse sequences.\n",
"\n",
"The following code cell shows how to enable dynamical decoupling for the estimator and choose a dynamical decoupling sequence."
]
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
},
{
"cell_type": "code",
"execution_count": 2,
"id": "cc057e3f-f592-434e-8bb2-96f901564318",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"estimator = Estimator(backend=backend)\n",
"estimator.options.dynamical_decoupling.enable = True\n",
"estimator.options.dynamical_decoupling.sequence_type = \"XpXm\""
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"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/run/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/run/error-mitigation-explanation/gate_twirls.png)\n",
"\n",
"The Qiskit Runtime options for Pauli twirling are described [here](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.TwirlingOptions). The following options are notable:\n",
"\n",
"- `enable_gates`: Set this to `True` to enable Pauli twirling of two-qubit gates.\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."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c3e12d44",
"metadata": {},
"outputs": [],
"source": [
"estimator = Estimator(backend=backend)\n",
"estimator.options.twirling.enable_gates = True\n",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"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/run/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 version 2 of the [Qiskit Runtime resilience options](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.ResilienceOptionsV2). Options for measurement twirling are described [here](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.MeasureNoiseLearningOptions). As in gate twirling, you can set the number of circuit randomizations and the number of shots per randomization.\n",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"The following code cell shows how to enable TREX and set these options for the estimator."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "80c858e3",
"metadata": {},
"outputs": [],
"source": [
"estimator = Estimator(backend=backend)\n",
"estimator.options.resilience.measure_mitigation = True\n",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"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": [
"## 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/run/error-mitigation-explanation/zne.png)\n",
"\n",
"ZNE can be enabled by setting `zne_mitigation` to `True` in version 2 of the [Qiskit Runtime resilience options](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.ResilienceOptionsV2).\n",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"The Qiskit Runtime options for ZNE are described [here](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.ZneOptions). The following options are notable:\n",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"\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 enable ZNE and set these options for the estimator."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "06de4431",
"metadata": {},
"outputs": [],
"source": [
"estimator = Estimator(backend=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": "fcc40cb7-45b7-4248-84c4-aa7f26ba50ff",
"metadata": {},
"source": [
"## 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 quasiprobability distribution instead. They can still be used to define a random ensemble, but there is a sampling overhead related to the negativity of the quasiprobability distribution, which is characterized by the quantity\n",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"\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",
"ZNE can be enabled by setting `pec_mitigation` to `True` in version 2 of the [Qiskit Runtime resilience options](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.ResilienceOptionsV2).\n",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"The Qiskit Runtime options for PEC are described [here](https://docs.quantum.ibm.com/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",
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"The following code cell shows how to enable PEC and set the `max_overhead` option for the estimator."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "f4ae33f2-3a4d-4869-952b-e5ebd9e69efc",
"metadata": {},
"outputs": [],
"source": [
"estimator = Estimator(backend=backend)\n",
"estimator.options.resilience.pec_mitigation = True\n",
"estimator.options.resilience.pec.max_overhead = 100"
]
}
],
"metadata": {
"description": "Explanation of error mitigation 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 technique explanations"
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions qiskit_bot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ notifications:
- "@beckykd"
- "@abbycross"
- "`@blakejohnson`"
"docs/run/error-mitigation-explanation":
- "@kevinsung"
"docs/run/sessions":
- "@jyu00"
- "@beckykd"
Expand Down
1 change: 1 addition & 0 deletions scripts/nb-tester/notebooks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ notebooks_normal_test = [
"docs/build/pulse.ipynb",
"docs/build/save-circuits.ipynb",
"docs/run/dynamic-circuits-considerations.ipynb",
"docs/run/error-mitigation-explanation.ipynb",
"docs/run/get-backend-information.ipynb",
"docs/run/save-jobs.ipynb",
"docs/run/visualize-results.ipynb",
Expand Down
Loading