Skip to content

Commit 90bdf5e

Browse files
miamicoabbycross
andauthored
Update tutorial on combining error mitigation features (#3821)
Update text and re-run tutorial to catch any outdated statement in the text. Also bumped up requirements --------- Co-authored-by: abbycross <across@us.ibm.com>
1 parent 0fb366d commit 90bdf5e

9 files changed

+54
-39
lines changed

docs/tutorials/combine-error-mitigation-techniques.ipynb

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"metadata": {},
77
"source": [
88
"# Combine error mitigation options with the Estimator primitive\n",
9-
"*Usage estimate: Eight minutes on ibm_fez (NOTE: This is an estimate only. Your runtime might vary.)*"
9+
"*Usage estimate: Seven minutes on a Heron r2 processor (NOTE: This is an estimate only. Your runtime might vary.)*"
1010
]
1111
},
1212
{
@@ -35,8 +35,8 @@
3535
"\n",
3636
"Before starting this tutorial, ensure that you have the following installed:\n",
3737
"\n",
38-
"- Qiskit SDK 1.0 or later with visualization support (`pip install 'qiskit[visualization]'`)\n",
39-
"- Qiskit Runtime 0.22 or later (`pip install qiskit-ibm-runtime`)"
38+
"- Qiskit SDK v2.1 or later with visualization support (`pip install 'qiskit[visualization]'`)\n",
39+
"- Qiskit Runtime v0.40 or later (`pip install qiskit-ibm-runtime`)"
4040
]
4141
},
4242
{
@@ -49,15 +49,15 @@
4949
},
5050
{
5151
"cell_type": "code",
52-
"execution_count": 1,
52+
"execution_count": 7,
5353
"id": "95a72452-e067-4ee5-bcd9-e3bfcf0de208",
5454
"metadata": {},
5555
"outputs": [],
5656
"source": [
5757
"import matplotlib.pyplot as plt\n",
5858
"import numpy as np\n",
5959
"\n",
60-
"from qiskit.circuit.library import EfficientSU2, UnitaryOverlap\n",
60+
"from qiskit.circuit.library import efficient_su2, unitary_overlap\n",
6161
"from qiskit.quantum_info import SparsePauliOp\n",
6262
"from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\n",
6363
"\n",
@@ -72,14 +72,14 @@
7272
"source": [
7373
"## Step 1: Map classical inputs to a quantum problem\n",
7474
"\n",
75-
"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`](/docs/api/qiskit/qiskit.circuit.library.EfficientSU2#efficientsu2) circuit included in Qiskit's circuit library.\n",
75+
"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 [`efficient_su2`](/docs/api/qiskit/qiskit.circuit.library.efficient_su2) circuit included in Qiskit's circuit library.\n",
7676
"\n",
77-
"`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."
77+
"`efficient_su2` 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."
7878
]
7979
},
8080
{
8181
"cell_type": "code",
82-
"execution_count": 2,
82+
"execution_count": 4,
8383
"id": "24abd7ba-bbb8-443b-9e81-866795d39a6c",
8484
"metadata": {},
8585
"outputs": [
@@ -89,16 +89,25 @@
8989
"<Image src=\"/docs/images/tutorials/combine-error-mitigation-techniques/extracted-outputs/24abd7ba-bbb8-443b-9e81-866795d39a6c-0.avif\" alt=\"Output of the previous code cell\" />"
9090
]
9191
},
92-
"execution_count": 2,
92+
"execution_count": 4,
9393
"metadata": {},
9494
"output_type": "execute_result"
95+
},
96+
{
97+
"data": {
98+
"text/plain": [
99+
"<Image src=\"/docs/images/tutorials/combine-error-mitigation-techniques/extracted-outputs/24abd7ba-bbb8-443b-9e81-866795d39a6c-1.avif\" alt=\"Output of the previous code cell\" />"
100+
]
101+
},
102+
"metadata": {},
103+
"output_type": "display_data"
95104
}
96105
],
97106
"source": [
98107
"n_qubits = 10\n",
99108
"reps = 1\n",
100109
"\n",
101-
"circuit = EfficientSU2(n_qubits, entanglement=\"pairwise\", reps=reps)\n",
110+
"circuit = efficient_su2(n_qubits, entanglement=\"pairwise\", reps=reps)\n",
102111
"\n",
103112
"circuit.decompose().draw(\"mpl\", scale=0.7)"
104113
]
@@ -113,7 +122,7 @@
113122
},
114123
{
115124
"cell_type": "code",
116-
"execution_count": 3,
125+
"execution_count": 5,
117126
"id": "9500ba7b-4542-465f-a4e1-60165d6b6d1e",
118127
"metadata": {},
119128
"outputs": [],
@@ -135,12 +144,12 @@
135144
"\n",
136145
"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",
137146
"\n",
138-
"The following code cell assigns random parameters to your circuit, and then constructs the mirror circuit using the [`UnitaryOverlap`](/docs/api/qiskit/qiskit.circuit.library.UnitaryOverlap#unitaryoverlap) class. Before mirroring the circuit, append a [barrier](/docs/api/qiskit/circuit#qiskit.circuit.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."
147+
"The following code cell assigns random parameters to your circuit, and then constructs the mirror circuit using the [`unitary_overlap`](/docs/api/qiskit/qiskit.circuit.library.unitary_overlap) class. Before mirroring the circuit, append a [barrier](/docs/api/qiskit/circuit#qiskit.circuit.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."
139148
]
140149
},
141150
{
142151
"cell_type": "code",
143-
"execution_count": 4,
152+
"execution_count": 8,
144153
"id": "4dbde811-1ba9-47a8-85a0-dcaff054ed60",
145154
"metadata": {},
146155
"outputs": [
@@ -150,9 +159,18 @@
150159
"<Image src=\"/docs/images/tutorials/combine-error-mitigation-techniques/extracted-outputs/4dbde811-1ba9-47a8-85a0-dcaff054ed60-0.avif\" alt=\"Output of the previous code cell\" />"
151160
]
152161
},
153-
"execution_count": 4,
162+
"execution_count": 8,
154163
"metadata": {},
155164
"output_type": "execute_result"
165+
},
166+
{
167+
"data": {
168+
"text/plain": [
169+
"<Image src=\"/docs/images/tutorials/combine-error-mitigation-techniques/extracted-outputs/4dbde811-1ba9-47a8-85a0-dcaff054ed60-1.avif\" alt=\"Output of the previous code cell\" />"
170+
]
171+
},
172+
"metadata": {},
173+
"output_type": "display_data"
156174
}
157175
],
158176
"source": [
@@ -167,7 +185,7 @@
167185
"assigned_circuit.barrier()\n",
168186
"\n",
169187
"# Construct mirror circuit\n",
170-
"mirror_circuit = UnitaryOverlap(assigned_circuit, assigned_circuit)\n",
188+
"mirror_circuit = unitary_overlap(assigned_circuit, assigned_circuit)\n",
171189
"\n",
172190
"mirror_circuit.decompose().draw(\"mpl\", scale=0.7)"
173191
]
@@ -193,27 +211,15 @@
193211
},
194212
{
195213
"cell_type": "code",
196-
"execution_count": 6,
214+
"execution_count": 9,
197215
"id": "2c3ea768-0596-4db1-9b51-3ff78ec65818",
198216
"metadata": {},
199-
"outputs": [
200-
{
201-
"data": {
202-
"text/plain": [
203-
"<IBMBackend('ibm_fez')>"
204-
]
205-
},
206-
"execution_count": 6,
207-
"metadata": {},
208-
"output_type": "execute_result"
209-
}
210-
],
217+
"outputs": [],
211218
"source": [
212219
"service = QiskitRuntimeService()\n",
213220
"backend = service.least_busy(\n",
214221
" operational=True, simulator=False, min_num_qubits=127\n",
215-
")\n",
216-
"backend"
222+
")"
217223
]
218224
},
219225
{
@@ -226,7 +232,7 @@
226232
},
227233
{
228234
"cell_type": "code",
229-
"execution_count": 7,
235+
"execution_count": 10,
230236
"id": "027e829a-44d3-455e-b2bf-8ce0d7e26b9b",
231237
"metadata": {},
232238
"outputs": [
@@ -236,9 +242,18 @@
236242
"<Image src=\"/docs/images/tutorials/combine-error-mitigation-techniques/extracted-outputs/027e829a-44d3-455e-b2bf-8ce0d7e26b9b-0.avif\" alt=\"Output of the previous code cell\" />"
237243
]
238244
},
239-
"execution_count": 7,
245+
"execution_count": 10,
240246
"metadata": {},
241247
"output_type": "execute_result"
248+
},
249+
{
250+
"data": {
251+
"text/plain": [
252+
"<Image src=\"/docs/images/tutorials/combine-error-mitigation-techniques/extracted-outputs/027e829a-44d3-455e-b2bf-8ce0d7e26b9b-1.avif\" alt=\"Output of the previous code cell\" />"
253+
]
254+
},
255+
"metadata": {},
256+
"output_type": "display_data"
242257
}
243258
],
244259
"source": [
@@ -262,7 +277,7 @@
262277
},
263278
{
264279
"cell_type": "code",
265-
"execution_count": 8,
280+
"execution_count": 12,
266281
"id": "12338588-a2d0-4b9c-9e49-e25ec8617b93",
267282
"metadata": {},
268283
"outputs": [
@@ -275,7 +290,7 @@
275290
" coeffs=[1.+0.j])\n",
276291
"\n",
277292
"Observable with layout applied:\n",
278-
"SparsePauliOp(['IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIZIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII'],\n",
293+
"SparsePauliOp(['IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIZIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII'],\n",
279294
" coeffs=[1.+0.j])\n"
280295
]
281296
}
@@ -311,7 +326,7 @@
311326
},
312327
{
313328
"cell_type": "code",
314-
"execution_count": 9,
329+
"execution_count": 13,
315330
"id": "1114d15b-1408-4f4c-a20f-60f0da722325",
316331
"metadata": {},
317332
"outputs": [],
@@ -368,7 +383,7 @@
368383
},
369384
{
370385
"cell_type": "code",
371-
"execution_count": 10,
386+
"execution_count": 14,
372387
"id": "eef38976-0ca2-429a-b2dc-41aac69605f7",
373388
"metadata": {},
374389
"outputs": [
@@ -435,7 +450,7 @@
435450
},
436451
{
437452
"cell_type": "code",
438-
"execution_count": 11,
453+
"execution_count": 15,
439454
"id": "d7d8408b-faf1-4eda-ab9c-bdeaab01ff53",
440455
"metadata": {},
441456
"outputs": [
@@ -454,7 +469,7 @@
454469
"reps = 1\n",
455470
"\n",
456471
"# Construct circuit and observable\n",
457-
"circuit = EfficientSU2(n_qubits, entanglement=\"pairwise\", reps=reps)\n",
472+
"circuit = efficient_su2(n_qubits, entanglement=\"pairwise\", reps=reps)\n",
458473
"observable = SparsePauliOp.from_sparse_list(\n",
459474
" [(\"Z\", [-1], 1.0)], num_qubits=n_qubits\n",
460475
")\n",
@@ -465,7 +480,7 @@
465480
"assigned_circuit.barrier()\n",
466481
"\n",
467482
"# Construct mirror circuit\n",
468-
"mirror_circuit = UnitaryOverlap(assigned_circuit, assigned_circuit)\n",
483+
"mirror_circuit = unitary_overlap(assigned_circuit, assigned_circuit)\n",
469484
"\n",
470485
"# Transpile circuit and observable\n",
471486
"isa_circuit = pass_manager.run(mirror_circuit)\n",

0 commit comments

Comments
 (0)