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

Stylistic updates to the Error mitigation w/ Estimator tutorial #1378

Merged
merged 19 commits into from
May 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"\n",
"*Estimated QPU usage: 8 minutes (tested on IBM Sherbrooke)*\n",
"\n",
"In this tutorial, we'll explore the error suppression and error mitigation options available with the Estimator primitive from Qiskit Runtime. We'll construct a circuit and observable and submit jobs using the Estimator primitive using different combinations of error mitigation settings. Then, we'll plot the results to observe the effects of the various settings. We'll go through most of the tutorial using a 10-qubit circuit to make visualizations easier, and at the end, we'll scale up the workflow to 50 qubits.\n",
"In this tutorial, you'll explore the error suppression and error mitigation options available with the Estimator primitive from Qiskit Runtime. You will construct a circuit and observable and submit jobs using the Estimator primitive using different combinations of error mitigation settings. Then, you will plot the results to observe the effects of the various settings. Most of the tutorial uses a 10-qubit circuit to make visualizations easier, and at the end, you can scale up the workflow to 50 qubits.\n",
"\n",
"The error suppression and mitigation options we'll explore are:\n",
"These are the error suppression and mitigation options you will use:\n",
"\n",
"- Dynamical decoupling\n",
"- Measurement error mitigation\n",
Expand All @@ -33,13 +33,13 @@
"source": [
"## Qiskit Pattern workflow\n",
"\n",
"We'll develop our workflow using the four steps of a Qiskit Pattern.\n",
"The four steps of a Qiskit Pattern provide a framework for the workflow in this tutorial.\n",
"\n",
"### Step 1: Map classical inputs to a quantum problem\n",
"\n",
"For the purposes of this tutorial, we'll assume that our classical problem has already been mapped to quantum, and we'll begin by constructing a circuit and observable to measure. While the techniques used in this tutorial apply to many different kinds of circuits, for simplicity we'll use the [`EfficientSU2`](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.EfficientSU2#efficientsu2) circuit included in Qiskit's circuit library.\n",
"This tutorial assumes that the classical problem has already been mapped to quantum. Begin by constructing a circuit and observable to measure. While the techniques used in this tutorial apply to many different kinds of circuits, for simplicity this tutorial uses the [`EfficientSU2`](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.EfficientSU2#efficientsu2) circuit included in Qiskit's circuit library.\n",
"\n",
"`EfficientSU2` is a parameterized quantum circuit designed to be efficiently executable on quantum hardware with limited qubit connectivity, while still being expressive enough to solve problems in application domains like optimization and chemistry. It's built by alternating layers of parameterized single-qubit gates with a layer containing a fixed pattern of two-qubit gates, for a chosen number of repetitions. The pattern of two-qubit gates can be specified by the user. We'll use the built-in `pairwise` pattern because it minimizes the circuit depth by packing the two qubit gates as densely as possible. This pattern can be executed using only linear qubit connectivity."
"`EfficientSU2` is a parameterized quantum circuit designed to be efficiently executable on quantum hardware with limited qubit connectivity, while still being expressive enough to solve problems in application domains like optimization and chemistry. It's built by alternating layers of parameterized single-qubit gates with a layer containing a fixed pattern of two-qubit gates, for a chosen number of repetitions. The pattern of two-qubit gates can be specified by the user. Here you can use the built-in `pairwise` pattern because it minimizes the circuit depth by packing the two-qubit gates as densely as possible. This pattern can be executed using only linear qubit connectivity."
]
},
{
Expand Down Expand Up @@ -97,13 +97,13 @@
"id": "52e59040-7023-4af3-8d18-468c4d244ea9",
"metadata": {},
"source": [
"At this point, we could proceed to run our circuit and measure the observable. However, we'd like to compare the output of the quantum device with the correct answer, i.e., the theoretical value of the observable if the circuit were executed without error. For small quantum circuits we can calculate this value by simulating the circuit on a classical computer, but we can't do this for larger, utility-scale circuits. Here, we'll work around this issue with the \"mirror circuit\" technique (also known as \"compute-uncompute\"), which is useful for benchmarking the performance of quantum devices.\n",
"At this point, you could proceed to run your circuit and measure the observable. However, you also want to compare the output of the quantum device with the correct answer - that is, the theoretical value of the observable, if the circuit had been executed without error. For small quantum circuits you can calculate this value by simulating the circuit on a classical computer, but this is not possible for larger, utility-scale circuits. You can work around this issue with the \"mirror circuit\" technique (also known as \"compute-uncompute\"), which is useful for benchmarking the performance of quantum devices.\n",
"\n",
"#### Mirror circuit\n",
"\n",
"In the mirror circuit technique, we concatenate the circuit with its inverse circuit, which is formed by inverting each gate of the circuit in reverse order. The resulting circuit implements the identity operator, which can trivially be simulated. Because the structure of the original circuit is preserved in the mirror circuit, executing the mirror circuit still gives us an idea of how the quantum device would perform on the original circuit.\n",
"In the mirror circuit technique, you concatenate the circuit with its inverse circuit, which is formed by inverting each gate of the circuit in reverse order. The resulting circuit implements the identity operator, which can trivially be simulated. Because the structure of the original circuit is preserved in the mirror circuit, executing the mirror circuit still gives an idea of how the quantum device would perform on the original circuit.\n",
"\n",
"In the following code cell, we assign random parameters to our circuit, and then construct the mirror circuit using the [`UnitaryOverlap`](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.UnitaryOverlap#unitaryoverlap) class. Before mirroring the circuit, we append a [barrier](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.Barrier#barrier) instruction to it to prevent the transpiler from merging the two parts of the circuit on either side of the barrier. Without the barrier, the transpiler would merge the original circuit with its inverse, resulting in a transpiled circuit without any gates."
"The following code cell assigns random parameters to your circuit, and then constructs the mirror circuit using the [`UnitaryOverlap`](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.UnitaryOverlap#unitaryoverlap) class. Before mirroring the circuit, append a [barrier](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.Barrier#barrier) instruction to it to prevent the transpiler from merging the two parts of the circuit on either side of the barrier. Without the barrier, the transpiler would merge the original circuit with its inverse, resulting in a transpiled circuit without any gates."
]
},
{
Expand Down Expand Up @@ -151,16 +151,16 @@
"source": [
"### Step 2: Optimize circuits for quantum hardware execution\n",
"\n",
"Before we can run our circuit on the hardware, we need to optimize it for hardware execution. This process involves a few steps:\n",
"You must optimize your circuit before running it on hardware. This process involves a few steps:\n",
"\n",
"- Pick a qubit layout that maps the virtual qubits of our circuit to physical qubits on the hardware.\n",
"- Pick a qubit layout that maps the virtual qubits of your circuit to physical qubits on the hardware.\n",
"- Insert swap gates as needed to route interactions between qubits that are not connected.\n",
"- Translate the gates in our circuit to [Instruction Set Architecture (ISA)](https://docs.quantum.ibm.com/transpile#instruction-set-architecture) instructions that can directly be executed on the hardware.\n",
"- Translate the gates in your circuit to [Instruction Set Architecture (ISA)](https://docs.quantum.ibm.com/transpile#instruction-set-architecture) instructions that can directly be executed on the hardware.\n",
"- Perform circuit optimizations to minimize the circuit depth and gate count.\n",
"\n",
"The transpiler built into Qiskit can perform all of these steps for us. Because we've chosen a hardware-efficient circuit, the transpiler should be able to pick a qubit layout that does not require any swap gates to be inserted for routing interactions.\n",
"The transpiler built into Qiskit can perform all of these steps for you. Because this tutorial uses a hardware-efficient circuit, the transpiler should be able to pick a qubit layout that does not require any swap gates to be inserted for routing interactions.\n",
"\n",
"Before we can optimize our circuit for hardware, we need to choose the hardware device we want to use. Let's request the least busy device with at least 127 qubits."
"You need to choose the hardware device to use before you optimize your circuit. The following code cell requests the least busy device with at least 127 qubits."
]
},
{
Expand All @@ -182,7 +182,7 @@
"id": "0b607d83-e7a2-4c03-83c9-3b52d23f8772",
"metadata": {},
"source": [
"We can transpile our circuit for our chosen backend by creating a pass manager and then running the pass manager on the circuit. An easy way to create a pass manager is to use the [`generate_preset_pass_manager`](https://docs.quantum.ibm.com/api/qiskit/transpiler_preset#qiskit.transpiler.preset_passmanagers.generate_preset_pass_manager) function. See [Transpile with pass managers](https://docs.quantum.ibm.com/transpile/transpile-with-pass-managers) for a more detailed explanation of transpiling with pass managers."
"You can transpile our circuit for your chosen backend by creating a pass manager and then running the pass manager on the circuit. An easy way to create a pass manager is to use the [`generate_preset_pass_manager`](https://docs.quantum.ibm.com/api/qiskit/transpiler_preset#qiskit.transpiler.preset_passmanagers.generate_preset_pass_manager) function. See [Transpile with pass managers](https://docs.quantum.ibm.com/transpile/transpile-with-pass-managers) for a more detailed explanation of transpiling with pass managers."
abbycross marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
Expand Down Expand Up @@ -219,9 +219,9 @@
"id": "761595f3-99bd-4a75-b493-e1a89afce6f6",
"metadata": {},
"source": [
"Now, our transpiled circuit contains only ISA instructions. The single-qubit gates have been decomposed in terms of $\\sqrt{X}$ gates and $R_z$ rotations, and the CX gates have been decomposed into [ECR gates](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.ECRGate#ecrgate) and single-qubit rotations.\n",
"The transpiled circuit now contains only ISA instructions. The single-qubit gates have been decomposed in terms of $\\sqrt{X}$ gates and $R_z$ rotations, and the CX gates have been decomposed into [ECR gates](https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.ECRGate#ecrgate) and single-qubit rotations.\n",
"\n",
"The transpilation process has mapped the virtual qubits of our circuit to physical qubits on the hardware. The information about the qubit layout is stored in the `layout` attribute of the transpiled circuit. Our observable was also defined in terms of the virtual qubits, so we need to apply this layout to the observable. This is done using the [`apply_layout`](https://docs.quantum.ibm.com/api/qiskit/qiskit.quantum_info.SparsePauliOp#apply_layout) method of `SparsePauliOp`."
"The transpilation process has mapped the virtual qubits of the circuit to physical qubits on the hardware. The information about the qubit layout is stored in the `layout` attribute of the transpiled circuit. The observable was also defined in terms of the virtual qubits, so you need to apply this layout to the observable, which you can do with the [`apply_layout`](https://docs.quantum.ibm.com/api/qiskit/qiskit.quantum_info.SparsePauliOp#apply_layout) method of `SparsePauliOp`."
]
},
{
Expand Down Expand Up @@ -261,16 +261,16 @@
"source": [
"### Step 3: Execute circuits using the Estimator primitive\n",
"\n",
"Now, we're ready to run our circuit using the Estimator primitive.\n",
"You are now ready to run your circuit using the Estimator primitive.\n",
"\n",
"We'll submit 5 separate jobs, starting with no error suppression or mitigation, and successively enabling various error suppression and mitigation options available in Qiskit Runtime. For information about the options, you can refer to the following pages:\n",
"Here you will submit five separate jobs, starting with no error suppression or mitigation, and successively enabling various error suppression and mitigation options available in Qiskit Runtime. For information about the options, refer to the following pages:\n",
"\n",
"- [Overview of all options](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/options)\n",
"- [Dynamical decoupling](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.DynamicalDecouplingOptions)\n",
"- [Resilience, including measurement error mitigation and zero-noise extrapolation (ZNE)](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.ResilienceOptionsV2)\n",
"- [Twirling](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.options.TwirlingOptions)\n",
"\n",
"Because our jobs can run independently of each other, we'll use [batch mode](https://docs.quantum.ibm.com/run/run-jobs-batch) to allow Qiskit Runtime to optimize the timing of their execution."
"Because these jobs can run independently of each other, you can use [batch mode](https://docs.quantum.ibm.com/run/run-jobs-batch) to allow Qiskit Runtime to optimize the timing of their execution."
]
},
{
Expand Down Expand Up @@ -330,7 +330,7 @@
"source": [
"### Step 4: Post-process and return results in classical format\n",
"\n",
"Finally, let's analyze the data. We'll retrieve the job results, extract the measured expectation values from them, and plot the values, including error bars of one standard deviation."
"Finally, you can analyze the data. Here you will retrieve the job results, extract the measured expectation values from them, and plot the values, including error bars of one standard deviation."
]
},
{
Expand Down Expand Up @@ -391,7 +391,7 @@
"source": [
"## Scale the experiment up\n",
"\n",
"When developing an experiment, it's useful to start with a small circuit to make visualizations and simulations easier. Now that we've developed and tested our workflow on a 10-qubit circuit, let's scale it up to 50 qubits. In the following code cell, we repeat all of the steps we developed in this tutorial, but now applying them to a 50 qubit circuit."
"When developing an experiment, it's useful to start with a small circuit to make visualizations and simulations easier. Now that you've developed and tested our workflow on a 10-qubit circuit, you can scale it up to 50 qubits. The following code cell repeats all of the steps in this tutorial, but now applies them to a 50-qubit circuit."
]
},
{
Expand Down Expand Up @@ -500,15 +500,15 @@
"id": "9bf5cb8a-0cb4-4b35-86ec-551d8db85155",
"metadata": {},
"source": [
"Let's compare the 50-qubit results with the 10-qubit results we obtained earlier:\n",
"When you compare the 50-qubit results with the 10-qubit results from earlier, note the following:\n",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"- The results without error mitigation are worse. Running the larger circuit involves executing more gates, so there are more opportunities for errors to accumulate.\n",
"- The addition of dynamical decoupling seems to have worsened performance. This is not surprising, because our circuit is very dense. Dynamical decoupling is primarily useful when there are large gaps in the circuit during which qubits sit idle without gates being applied to them. When these gaps are not present, dynamical decoupling is not effective, and can actually worsen performance due to errors in the dynamical decoupling pulses themselves. The 10-qubit circuit may have been too small for us to observe this effect.\n",
"- With zero-noise extrapolation, the result is as good, or nearly as good, as the 10-qubit result, though the error bar is much larger. ZNE is quite a powerful technique!\n",
"- The addition of dynamical decoupling seems to have worsened performance. This is not surprising, because the circuit is very dense. Dynamical decoupling is primarily useful when there are large gaps in the circuit during which qubits sit idle without gates being applied to them. When these gaps are not present, dynamical decoupling is not effective, and can actually worsen performance due to errors in the dynamical decoupling pulses themselves. The 10-qubit circuit may have been too small for us to observe this effect.\n",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
"- With zero-noise extrapolation, the result is as good, or nearly as good, as the 10-qubit result, though the error bar is much larger. This demonstrates the power of the ZNE technique!\n",
"\n",
"## Conclusion\n",
"\n",
"In this tutorial, we explored the different error mitigation available for the Qiskit Runtime Estimator primitive. We developed our workflow using a 10-qubit circuit, and then scaled it up to 50 qubits. We found that enabling more error suppression and mitigation options doesn't always improve performance (specifically, enabling dynamical decoupling in this case). Most of the options accept additional configuration, and here we only tested one configuration for each. There are a lot more things you can try when applying these techniques in your own work!"
"This tutorial walked through the different error mitigation options available for the Qiskit Runtime Estimator primitive. You developed a workflow using a 10-qubit circuit, and then scaled it up to 50 qubits. You found that enabling more error suppression and mitigation options doesn't always improve performance (specifically, enabling dynamical decoupling in this case). Most of the options accept additional configuration, and here you only tested one configuration for each. Try out the many more configurations when you apply these techniques in your own work!"
abbycross marked this conversation as resolved.
Show resolved Hide resolved
]
}
],
Expand Down
Loading