257 lines
13 KiB
Plaintext
257 lines
13 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "d59934c8-76a1-4eda-97ba-4fcfb6f15776",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Configure error mitigation"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "8f3a25e1-b73d-48d1-8b82-9c57095c9108",
|
|
"metadata": {
|
|
"tags": [
|
|
"version-info"
|
|
]
|
|
},
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3f1ea669-4144-4071-a4e9-88e01056f465",
|
|
"metadata": {},
|
|
"source": [
|
|
"Error mitigation techniques allow users to mitigate circuit errors by\n",
|
|
"modeling the device noise at the time of execution. This typically\n",
|
|
"results in quantum pre-processing overhead related to model training and\n",
|
|
"classical post-processing overhead to mitigate errors in the raw results\n",
|
|
"by using the generated model.\n",
|
|
"\n",
|
|
"The Estimator primitive supports several error mitigation techniques, including [TREX](/docs/api/qiskit-ibm-runtime/options-resilience-options-v2#measure_mitigation), [ZNE](/docs/api/qiskit-ibm-runtime/options-resilience-options-v2#zne), [PEC](/docs/api/qiskit-ibm-runtime/options-resilience-options-v2#pec), and [PEA](/docs/api/qiskit-ibm-runtime/options-zne-options). See [Error mitigation and suppression techniques](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](#advanced-error) section for details.\n",
|
|
"\n",
|
|
"<Admonition type=\"note\">\n",
|
|
"\n",
|
|
"Sampler does not support error mitigation, but you can use the [mthree](https://qiskit.github.io/qiskit-addon-mthree/) (matrix-free measurement mitigation) package to perform error mitigation locally.\n",
|
|
"\n",
|
|
"</Admonition>\n",
|
|
"\n",
|
|
"Estimator also supports `resilience_level`. The resilience level specifies how much resilience to build against\n",
|
|
"errors. Higher levels generate more accurate results, at the expense of\n",
|
|
"longer processing times. Resilience levels can be used to configure the\n",
|
|
"cost/accuracy trade-off when applying error mitigation to your primitive\n",
|
|
"query. Error mitigation reduces errors (bias) in results by processing\n",
|
|
"the outputs from a collection, or ensemble, of related circuits. The\n",
|
|
"degree of error reduction depends on the method applied. The resilience\n",
|
|
"level abstracts the detailed choice of error mitigation method to allow\n",
|
|
"users to reason about the cost/accuracy trade that is appropriate to\n",
|
|
"their application.\n",
|
|
"\n",
|
|
"Given this, each level corresponds to a method or methods with\n",
|
|
"increasing level of quantum sampling overhead to enable you experiment\n",
|
|
"with different time-accuracy tradeoffs. The following table shows you\n",
|
|
"which levels and corresponding methods are available for each of the\n",
|
|
"primitives.\n",
|
|
"\n",
|
|
"<Admonition type=\"info\" title=\"Attention\">\n",
|
|
"Error mitigation is task-specific, so the techniques you can\n",
|
|
"apply vary based whether you are sampling a distribution or generating\n",
|
|
"expectation values.\n",
|
|
"</Admonition>\n",
|
|
"\n",
|
|
"<span id=\"resilience-table\"></span>\n",
|
|
"\n",
|
|
"Estimator supports the following resilience levels. Sampler does not support resilience levels.\n",
|
|
"\n",
|
|
"| Resilience Level | Definition | Technique |\n",
|
|
"|------------------|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------|\n",
|
|
"| 0 | No mitigation | None |\n",
|
|
"| 1 [Default] | Minimal mitigation costs: Mitigate error associated with readout errors | Twirled Readout Error eXtinction (TREX) measurement twirling |\n",
|
|
"| 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\n",
|
|
"\n",
|
|
"\n",
|
|
"<Admonition type=\"info\" title=\"Attention\">\n",
|
|
"\n",
|
|
"Resilience levels are currently in beta so sampling overhead and\n",
|
|
"solution quality will vary from circuit to circuit. New features,\n",
|
|
"advanced options, and management tools will be released on a rolling\n",
|
|
"basis. Specific error mitigation methods are not guaranteed to be\n",
|
|
"applied at each resilience level.\n",
|
|
"</Admonition>\n",
|
|
"\n",
|
|
"## Configure Estimator with resilience levels\n",
|
|
"\n",
|
|
"You can use resilience levels to specify error mitigation techniques, or you can set custom techniques individually as described in [Custom error settings.](#advanced-error)\n",
|
|
"\n",
|
|
"<details>\n",
|
|
"<summary>Resilience Level 0</summary>\n",
|
|
"\n",
|
|
"No error mitigation is applied to the user program.\n",
|
|
"\n",
|
|
"\n",
|
|
"</details>\n",
|
|
"\n",
|
|
"\n",
|
|
"<details>\n",
|
|
"<summary>Resilience Level 1</summary>\n",
|
|
"\n",
|
|
"Level 1 applies **readout error mitigation** and **measurement twirling** by applying a model-free technique known\n",
|
|
"as Twirled Readout Error eXtinction (TREX). It reduces measurement error\n",
|
|
"by diagonalizing the noise channel associated with measurement by\n",
|
|
"randomly flipping qubits through X gates immediately before measurement. A\n",
|
|
"rescaling term from the diagonal noise channel is learned by\n",
|
|
"benchmarking random circuits initialized in the zero state. This allows\n",
|
|
"the service to remove bias from expectation values that result from\n",
|
|
"readout noise. This approach is described further in [Model-free\n",
|
|
"readout-error mitigation for quantum expectation\n",
|
|
"values](https://arxiv.org/abs/2012.09738).\n",
|
|
"\n",
|
|
"</details>\n",
|
|
"\n",
|
|
"\n",
|
|
"<details>\n",
|
|
"<summary>Resilience Level 2</summary>\n",
|
|
"\n",
|
|
"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\n",
|
|
"expectation value of the observable for different noise factors\n",
|
|
"(amplification stage) and then uses the measured expectation values to\n",
|
|
"infer the ideal expectation value at the zero-noise limit (extrapolation\n",
|
|
"stage). This approach tends to reduce errors in expectation values, but\n",
|
|
"is not guaranteed to produce an unbiased result.\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"The overhead of this method scales with the number of noise factors. The\n",
|
|
"default settings sample the expectation value at three noise factors,\n",
|
|
"leading to a roughly 3x overhead when employing this resilience level.\n",
|
|
"\n",
|
|
"In Level 2, the TREX method randomly flips qubits through X gates immediately before measurement,\n",
|
|
"and flips the corresponding measured bit if an X gate was applied. This approach is described further in [Model-free\n",
|
|
"readout-error mitigation for quantum expectation\n",
|
|
"values](https://arxiv.org/abs/2012.09738).\n",
|
|
"\n",
|
|
"</details>\n",
|
|
"\n",
|
|
"### Example\n",
|
|
"\n",
|
|
"The `EstimatorV2` interface lets users seamlessly work with the variety of\n",
|
|
"error mitigation methods to reduce error in expectation values of\n",
|
|
"observables. The following code uses Zero Noise Extrapolation and readout error mitigation by simply\n",
|
|
"setting `resilience_level 2`."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "841b526d-55b8-4125-bd2c-758d9db8dbb3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
|
|
"from qiskit_ibm_runtime import EstimatorV2 as Estimator\n",
|
|
"\n",
|
|
"service = QiskitRuntimeService()\n",
|
|
"backend = service.least_busy(operational=True, simulator=False)\n",
|
|
"\n",
|
|
"# Setting options during primitive initialization\n",
|
|
"estimator = Estimator(backend, options={\"resilience_level\": 2})"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c497a0e5-bcb7-4954-8096-70b4514ea498",
|
|
"metadata": {},
|
|
"source": [
|
|
"<span id=\"advanced-error\"></span>\n",
|
|
"## Custom error settings\n",
|
|
"\n",
|
|
"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](error-mitigation-and-suppression-techniques) for an explanation of each.\n",
|
|
"\n",
|
|
"<Admonition type = \"note\" title = \"Notes\">\n",
|
|
"- Not all options are available for both primitives. See the [available options table](runtime-options-overview#options-table) for the list of available options.\n",
|
|
"- Not all methods work together on all types of circuits. See the [feature compatibility table](runtime-options-overview#options-compatibility-table) for details.\n",
|
|
"</Admonition>\n",
|
|
"\n",
|
|
"<Tabs>\n",
|
|
" <TabItem value=\"Estimator\" label=\"Estimator\">\n",
|
|
" ```python\n",
|
|
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
|
|
"from qiskit_ibm_runtime import EstimatorV2 as Estimator\n",
|
|
"\n",
|
|
"service = QiskitRuntimeService()\n",
|
|
"backend = service.least_busy(operational=True, simulator=False)\n",
|
|
"\n",
|
|
"estimator = Estimator(backend)\n",
|
|
"options = estimator.options\n",
|
|
"# Turn on gate twirling.\n",
|
|
"options.twirling.enable_gates = True\n",
|
|
"# Turn on measurement error mitigation.\n",
|
|
"options.resilience.measure_mitigation = True\n",
|
|
"\n",
|
|
"print(f\">>> gate twirling is turned on: {estimator.options.twirling.enable_gates}\")\n",
|
|
"print(f\">>> measurement error mitigation is turned on: {estimator.options.resilience.measure_mitigation}\")\n",
|
|
"```\n",
|
|
" </TabItem>\n",
|
|
"\n",
|
|
" <TabItem value=\"Sampler\" label=\"Sampler\">\n",
|
|
"```python\n",
|
|
"from qiskit_ibm_runtime import SamplerV2 as Sampler\n",
|
|
"\n",
|
|
"# Estimator and Sampler have different options\n",
|
|
"sampler = Sampler(backend)\n",
|
|
"options = sampler.options\n",
|
|
"\n",
|
|
"options.dynamical_decoupling.enable = True\n",
|
|
"# Turn on gate twirling. Requires qiskit_ibm_runtime 0.23.0 or later.\n",
|
|
"options.twirling.enable_gates = True\n",
|
|
"\n",
|
|
"print(f\">>> dynamical decoupling is turned on: {sampler.options.dynamical_decoupling.enable}\")\n",
|
|
"print(f\">>> gate twirling is turned on: {sampler.options.twirling.enable_gates}\")\n",
|
|
"\n",
|
|
"```\n",
|
|
" </TabItem>\n",
|
|
"</Tabs>\n",
|
|
"\n",
|
|
"## Turn off all error mitigation\n",
|
|
"\n",
|
|
"For instructions to turn off all error mitigation, see the [Turn off all error suppression and mitigation](specify-runtime-options#no-error-mitigation) section.\n",
|
|
"\n",
|
|
"## Next steps\n",
|
|
"\n",
|
|
"<Admonition type=\"tip\" title=\"Recommendations\">\n",
|
|
" - Walk through an example that uses error mitigation in the [Cost function lesson](https://learning.quantum.ibm.com/course/variational-algorithm-design/cost-functions#primitives) in IBM Quantum Learning.\n",
|
|
" - Learn more about [error mitigation and error suppression techniques.](error-mitigation-and-suppression-techniques)\n",
|
|
" - [Configure error suppression.](configure-error-suppression)\n",
|
|
" - Explore other [options.](runtime-options-overview)\n",
|
|
" - Decide what [execution mode](execution-modes) to run your job in.\n",
|
|
"</Admonition>"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"description": "How to configure error mitigation with 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": "Configure error mitigation"
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|