Skip to content

Commit 0762333

Browse files
sesmartnatestemen
andcommitted
feature: updates to error mitigation examples (#814)
Co-authored-by: nate stemen <nate@stemen.email>
1 parent 1b1ce74 commit 0762333

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed

examples/error_mitigation/on_mitiq/0_Getting_started_with_mitiq_on_Braket.ipynb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
"id": "4af17ce3",
66
"metadata": {},
77
"source": [
8+
<<<<<<< HEAD
89
"# Getting Started with Error Mitigation with Mitiq on Braket \n",
910
"\n",
1011
"In this notebook we will look at [Mitiq](https://mitiq.readthedocs.io/en/stable/), a python library for performing quantum error mitigation, in tandem with performance features from Amazon Braket for quantum computational applications. In subsequent notebooks, we show how to utilize mitiq with Amazon Braket, specifically focusing on utilizing Program Sets to orchestrate job submissions, reducing costs and improving accuracies for quantum jobs.\n",
12+
=======
13+
"# Getting Started with Error Mitigation with mitiq on Braket \n",
14+
"\n",
15+
"In this notebook we will look at [`mitiq`](https://mitiq.readthedocs.io/en/stable/), a python library for performing quantum error mitigation, in tandem with performance features from Amazon Braket for quantum computational applications. In subsequent notebooks, we show how to utilize mitiq with Amazon Braket, specifically focusing on utilizing Program Sets to orchestrate job submissions, reducing costs and improving accuracies for quantum jobs.\n",
16+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
1117
"\n",
1218
"### Why do we need error mitigation?\n",
1319
"\n",
@@ -31,11 +37,19 @@
3137
"metadata": {},
3238
"source": [
3339
"\n",
40+
<<<<<<< HEAD
3441
"### Using Mitiq and Braket\n",
3542
"\n",
3643
"Mitiq is an open source Python toolkit for implementing error mitigation techniques, which covers a breadth of different methodoloies and tools. \n",
3744
"\n",
3845
"The Mitiq library provides numerous error mitigation approaches as pre-implemented strategies. These include (but are not limited to):\n",
46+
=======
47+
"### Using mitiq and Braket\n",
48+
"\n",
49+
"mitiq is an open source Python toolkit for implementing error mitigation techniques, which covers a breadth of different methodoloies and tools. \n",
50+
"\n",
51+
"The mitiq library provides numerous error mitigation approaches as pre-implemented strategies. These include (but are not limited to):\n",
52+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
3953
"\n",
4054
"- Readout error mitigation (`mitiq.rem`)\n",
4155
"- Zero noise extrapolation (`mitiq.zne`)\n",
@@ -50,11 +64,19 @@
5064
"\n",
5165
"and more. See the [documentation](https://mitiq.readthedocs.io/en/stable/guide/guide.html) for a full list of supported methods. \n",
5266
"\n",
67+
<<<<<<< HEAD
5368
"#### Patterns in Mitiq\n",
5469
"\n",
5570
"\n",
5671
"\n",
5772
"Mitiq contains two methods for applying error mitigation generally. The first can be thought of as a simple function call in which one passes a Circuit and the QEM technique parameters into a function `mitiq.xyz.execute_with_xyz`. This uses an [`executor`](https://mitiq.readthedocs.io/en/stable/guide/executors.html) object, which is detailed below. \n",
73+
=======
74+
"#### Patterns in mitiq\n",
75+
"\n",
76+
"\n",
77+
"\n",
78+
"mitiq contains two methods for applying error mitigation generally. The first can be thought of as a simple function call in which one passes a Circuit and the QEM technique parameters into a function `mitiq.xyz.execute_with_xyz`. This uses an [`executor`](https://mitiq.readthedocs.io/en/stable/guide/executors.html) object, which is detailed below. \n",
79+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
5880
"\n",
5981
"```\n",
6082
"from mitiq.zne import execute_with_zne\n",
@@ -71,7 +93,11 @@
7193
"\n",
7294
"in the `mitiq_braket_tools.py` file, we develop a `braket_mitiq_executor` function which can easily be used with the first pattern, and meets the requirements of a `mitiq.executor.Executor` object. The second we will explore more in a future notebook, and is develop in the parent `tools` folder, i.e. in the `tools/program_set_tools.py` file. \n",
7395
"\n",
96+
<<<<<<< HEAD
7497
"Further details can be found in the [Mitiq guide](https://mitiq.readthedocs.io/en/stable/guide/guide.html). \n",
98+
=======
99+
"Further details can be found in the [mitiq guide](https://mitiq.readthedocs.io/en/stable/guide/guide.html). \n",
100+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
75101
"\n",
76102
"#### Using Verbatim circuits\n",
77103
"\n",
@@ -91,9 +117,16 @@
91117
"id": "02bfa0b1",
92118
"metadata": {},
93119
"source": [
120+
<<<<<<< HEAD
94121
"### Installing Mitiq\n",
95122
"\n",
96123
"> Mitiq is not included by default with the amazon-braket-examples or in the Amazon Braket notebook instances. To install, uncomment the first line in the next code block, and if necessary, restart the notebook. Mitiq utilizes [Cirq](https://quantumai.google/cirq) as the backend, and often times will represent circuits using their representation. "
124+
=======
125+
"### Installing mitiq\n",
126+
"\n",
127+
"> [!WARNING]\n",
128+
"> mitiq is not included by default with the amazon-braket-examples or in the Amazon Braket notebook instances. To install, uncomment the first line in the next code block, and if necessary, restart the notebook. Mitiq utilizes [Cirq](https://quantumai.google/cirq) as the backend, and often times will represent circuits using their representation. "
129+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
97130
]
98131
},
99132
{
@@ -148,7 +181,11 @@
148181
"\n",
149182
"## UNCOMMENT_TO_RUN\n",
150183
"# from braket.devices import LocalSimulator\n",
184+
<<<<<<< HEAD
151185
"# qd_depol = LocalSimulator()"
186+
=======
187+
"# qd_depol = LocalSimulator()\n"
188+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
152189
]
153190
},
154191
{
@@ -168,6 +205,10 @@
168205
"\n",
169206
"Generally these can be user-defined functions which input Circuits and output either floats or Measurement-type results. The `braket_expectation_executor` and `braket_measurement_executor` are Executors for Braket [Observables](https://amazon-braket-sdk-python.readthedocs.io/en/latest/_apidoc/braket.circuits.observables.html) or mitiq [Observables](https://mitiq.readthedocs.io/en/stable/guide/observables.html), respectively. \n",
170207
"\n",
208+
<<<<<<< HEAD
209+
=======
210+
">[!NOTE]\n",
211+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
171212
"> The Executors are essentially wrappers around the ProgramSet object, and will fail it you try to submit more executables than the ProgramSet limit given for a given device. "
172213
]
173214
},

examples/error_mitigation/on_mitiq/1_Readout_mitigation_with_mitiq.ipynb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
"In this notebook, you will learn how to perform readout-error mitigation using [mitiq](https://mitiq.readthedocs.io/en/stable/) with Amazon Braket ProgramSets. This is particularly helpful for superconducting devices (IQM and Rigetti devices), which may contain larger measurement errors. \n",
1111
"\n",
1212
"### Installing mitiq\n",
13+
<<<<<<< HEAD
1314
"\n",
15+
=======
16+
">[!WARNING]\n",
17+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
1418
">mitiq is not included by default with `amazon-braket-examples` requirements or in the Amazon Braket Notebook Instances. To install, uncomment the first line in the next code block, and restart the notebook. Or run install from `extra/requirement-mitiq.txt`. \n",
1519
"\n",
1620
"Mitiq utilizes Cirq as the backend, and may represent circuits using their representation. "

examples/error_mitigation/on_mitiq/2_Zero_noise_extrapolation_with_mitiq.ipynb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
"metadata": {},
1919
"source": [
2020
"### Installing mitiq\n",
21+
<<<<<<< HEAD
2122
"\n",
23+
=======
24+
">[!WARNING]\n",
25+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
2226
">mitiq is not included by default with `amazon-braket-examples` requirements or in the Amazon Braket Notebook Instances. To install, uncomment the first line in the next code block, and restart the notebook. Or run install from `extra/requirement-mitiq.txt`. \n",
2327
"\n",
2428
"Mitiq utilizes Cirq as the backend, and may represent circuits using their representation. "
@@ -888,7 +892,11 @@
888892
"source": [
889893
"### Conclusion\n",
890894
"\n",
895+
<<<<<<< HEAD
891896
"In this notebook we looked at extrapolation based approaches, including standard zero-noise extrapolation (ZNE) as well as layerwise Richardson extrapolation (LRE). mitiq has many other options for enhancing ZNE results, which we encourage the interested use to explore. We will explore larger scale applications in subsequent notebooks. \n",
897+
=======
898+
"In this notebook we looked at extrapolation based approaches, including standard zero-noise extrapolation (ZNE)as well as layerwise Richardson extrapolation (LRE). mitiq has many other options for enhancing ZNE results, which we encourage the interested use to explore. We will epxlore larger scale applications in subseqeuent notebooks. \n",
899+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
892900
"\n",
893901
"### References\n",
894902
"\n",

examples/error_mitigation/on_mitiq/3_Twirling_with_program_sets.ipynb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
"In this notebook, we look at Pauli twirling for normalizing noise on gates and measurement, and specifically how this can be realized using [mitiq](https://mitiq.readthedocs.io/en/stable/) on Amazon Braket. \n",
1111
"\n",
1212
"### Installing mitiq\n",
13+
<<<<<<< HEAD
1314
"\n",
15+
=======
16+
">[!WARNING]\n",
17+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
1418
">mitiq is not included by default with `amazon-braket-examples` requirements or in the Amazon Braket Notebook Instances. To install, uncomment the first line in the next code block, and restart the notebook. Or run install from `extra/requirement-mitiq.txt`. \n",
1519
"\n",
1620
"Mitiq utilizes Cirq as the backend, and may represent circuits using their representation. "
@@ -469,6 +473,10 @@
469473
"source": [
470474
"Thus we see that the effect of noise is largely normalized - each channel exhibits straightforward decay. To truly verify that we have elemintated coherent errors we can consider how the channel acts on different input states - effectively corresponding with quantum process tomography. \n",
471475
"\n",
476+
<<<<<<< HEAD
477+
=======
478+
">[!NOTE]\n",
479+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
472480
">Generally, the most performant way to twirling on Braket today is the above manner, with discrete circuits. "
473481
]
474482
},

examples/error_mitigation/on_mitiq/4_Error_mitigation_workflow_with_mitiq.ipynb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
"metadata": {},
1919
"source": [
2020
"### Installing mitiq\n",
21+
<<<<<<< HEAD
2122
"\n",
23+
=======
24+
">[!WARNING]\n",
25+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
2226
">mitiq is not included by default with `amazon-braket-examples` requirements or in the Amazon Braket Notebook Instances. To install, uncomment the first line in the next code block, and restart the notebook. Or run install from `extra/requirement-mitiq.txt`. \n",
2327
"\n",
2428
"Mitiq utilizes Cirq as the backend, and may represent circuits using their representation. "
@@ -272,6 +276,10 @@
272276
"id": "c315df44",
273277
"metadata": {},
274278
"source": [
279+
<<<<<<< HEAD
280+
=======
281+
"> [!IMPORTANT]\n",
282+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
275283
"> While ProgramSets greatly reduce the *task cost*, the *shot cost* can be further reduced in a number of ways. We have explored this in previous notebooks, but one should consider (1) setting precision correctly for a problem specification, (2) bounding mitigation costs, including REM and extrapolation based ones, (3) shot allocation and variance reduction strategies for observables, and (4) avoiding over calibration. While it is not harmful to measure additional calibration shots, at some point it can no lopnger improve the quality of your result."
276284
]
277285
},
@@ -861,6 +869,10 @@
861869
"source": [
862870
"Here we see in isolation, each method may slightly improve the answer, but combining methods requires conceptually understanding their differences and intended scope. For intance, we expect REM to naively improve any answer, which we do see. Twirling may or may not help a particular result but it should make it more consistent. ZNE likewise may not perform well in the case that measurement errors are not extrapolated as well - which they generally cannot be. ZNE + twirling does not help this; REM + twirling gives a more accurate readout error, but has not addressed the circuit noise source. ZNE + REM here struggles with the amplitude damping noise, and does not quite extrapolate back to the correct answer. \n",
863871
"\n",
872+
<<<<<<< HEAD
873+
=======
874+
">[!NOTE]\n",
875+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
864876
"> Using a depolarizing model will result in REM + ZNE yielding similar errors to REM + Twirl + ZNE. On today's devices we do not always expect for normalized noise models, and so the depolarizing model is not realistic. The current model, `qd_total`, has a small amplitude damping factor which affects these results and makes the noise channel non-unital."
865877
]
866878
},

examples/error_mitigation/supplemental/Advanced_QPU_workflow.ipynb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
"# Performing an error mitigation workflow with program sets on Amazon Braket\n",
99
"\n",
1010
"This notebook builds on topics present in the error mitigation workflow seen using mitiq, but instead focuses on a QHP-based (Rigetti) workflow. As such, it requires substantial customization beyond what is commonly available. \n",
11+
<<<<<<< HEAD
1112
"\n",
13+
=======
14+
">[!WARNING]\n",
15+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
1216
">Executing this notebook with devices will charge your AWS account! Please keep this in mind and verify with the previous notebook tracker. "
1317
]
1418
},
@@ -117,6 +121,10 @@
117121
"id": "15258900",
118122
"metadata": {},
119123
"source": [
124+
<<<<<<< HEAD
125+
=======
126+
">[!NOTE]\n",
127+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
120128
"> To use the emulator, you can simply specify a smaller number of qubits, and modify the device target \n",
121129
"\n",
122130
"Now we define our problem Hamiltonian, here a simple Ising Hamiltonian. For simplicity, we use a simple string representation of the Pauli operators, and a greedy color-based grouping scheme using networkx. \n",
@@ -928,6 +936,7 @@
928936
]
929937
},
930938
{
939+
<<<<<<< HEAD
931940
"cell_type": "code",
932941
"execution_count": null,
933942
"id": "3d22aa40",
@@ -936,20 +945,30 @@
936945
"source": []
937946
},
938947
{
948+
=======
949+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
939950
"cell_type": "markdown",
940951
"id": "2b4d5cca",
941952
"metadata": {},
942953
"source": [
954+
<<<<<<< HEAD
943955
"### Step 0.5 - Generating Circuits\n",
944956
"\n",
945957
"Here, we generate our circuits. We first expand the circuits into noise amplified virsions, and then we apply a twirling sequence for each circuit. For the device, we need to convert the Pauli operators to native Rigetti instructions, and then remove the verbatim flags from the circuits. We will add these back in later, once we have bound observables to our circuits. \n",
946958
"\n",
947959
"> You also could construct observables at this point, ideally before or after ZNE, and before twirling circuits. "
960+
=======
961+
"### Step 0.5 - Generating Circuits"
962+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
948963
]
949964
},
950965
{
951966
"cell_type": "code",
967+
<<<<<<< HEAD
952968
"execution_count": null,
969+
=======
970+
"execution_count": 18,
971+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
953972
"id": "91405d02",
954973
"metadata": {},
955974
"outputs": [
@@ -969,7 +988,15 @@
969988
],
970989
"source": [
971990
"folded_circuits = [multiply_gates(ansatz_v1, ['ISwap','Rz'],scale) for scale in scale_factors_expanded]\n",
991+
<<<<<<< HEAD
972992
"circuits_pre = np.array([twirl_iswap(c, num_twirls) for c in folded_circuits], dtype=object)\n",
993+
=======
994+
"\n",
995+
"\n",
996+
"circuits_pre = np.array([twirl_iswap(c, num_twirls) for c in folded_circuits], dtype=object)\n",
997+
"\n",
998+
"\n",
999+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
9731000
"circuits, twirls = apply_readout_twirl(circuits_pre)\n",
9741001
"\n",
9751002
"circuits = np.vectorize(convert_paulis)(circuits)\n",
@@ -993,6 +1020,25 @@
9931020
},
9941021
{
9951022
"cell_type": "markdown",
1023+
<<<<<<< HEAD
1024+
=======
1025+
"id": "0f63942a",
1026+
"metadata": {},
1027+
"source": [
1028+
"We can also just visually verify that our circuits look reasonable:"
1029+
]
1030+
},
1031+
{
1032+
"cell_type": "code",
1033+
"execution_count": null,
1034+
"id": "b8662489",
1035+
"metadata": {},
1036+
"outputs": [],
1037+
"source": []
1038+
},
1039+
{
1040+
"cell_type": "markdown",
1041+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
9961042
"id": "7533d1e8",
9971043
"metadata": {},
9981044
"source": [
@@ -1070,7 +1116,11 @@
10701116
"source": [
10711117
"#### Step 2.0 - Main Execution\n",
10721118
"\n",
1119+
<<<<<<< HEAD
10731120
"From our custom `run_with_program_sets` functions, using `None` for our set of observables in each basis indicates that we want to return the output distribution. "
1121+
=======
1122+
"Now, we begin our main execution. Supplying `None` as our set of observables indicates that we want to return the output distribution. "
1123+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
10741124
]
10751125
},
10761126
{
@@ -1113,7 +1163,11 @@
11131163
"source": [
11141164
"### Step 3.0 - processing our results\n",
11151165
"\n",
1166+
<<<<<<< HEAD
11161167
"Now, we need to carry out our processing. The main two ways are to either extrapolate a final summed expectation value, or to extrapolate each Pauli observable, and then sum. We find the latter method typically works slightly better, but that may not be true for all systems. \n",
1168+
=======
1169+
"Now, we need to carry out our processing. The main two ways are to extrapolate a final expectation value, or to extrapolate each Pauli observable, and then sum. We find the latter method typically works slightly better, but that may not be true for all systems. \n",
1170+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
11171171
"\n",
11181172
"Additionally, we have three relevant set of qubit labels to keep track of. First, our problem and associated Hamiltonian entries, which are indexed from 1 to `num_qubits`. These are associated with a physical set of qubits, and finally there is the register, which importantly, is taken to be ordered by design. "
11191173
]
@@ -1700,7 +1754,11 @@
17001754
"\n",
17011755
"For this precision, assuming that our method is more or less unbiased and that the true noisy mean is 0.52, we would expect to see improvements of between 14-16x improvement, maybe as low as 5-10x, solely based on precision, so our result is optimistically better. \n",
17021756
"\n",
1757+
<<<<<<< HEAD
17031758
"Regardless, with careful planning, these principles can be applied to other, more complex systems. For this workflow, we can see that individually, the different error mitigation methods do help, but not in as complete a manner as using them all together. "
1759+
=======
1760+
"Regardless, with careful planning, these principles can be applied to numerous systems. For this workflow, we can see that individually, the different error mitigation methods do help, but not in as complete a manner as using them all together. "
1761+
>>>>>>> 98f6da3 (feature: updates to error mitigation examples (#814))
17041762
]
17051763
},
17061764
{

0 commit comments

Comments
 (0)