Skip to content

Commit 0f4822b

Browse files
update parallel XEB notebook (#6494)
1 parent 2700f95 commit 0f4822b

File tree

1 file changed

+73
-5
lines changed

1 file changed

+73
-5
lines changed

docs/noise/qcvv/parallel_xeb.ipynb

+73-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
" import cirq\n",
6666
"except ImportError:\n",
6767
" print(\"installing cirq...\")\n",
68-
" !pip install --quiet cirq\n",
68+
" !pip install --quiet cirq --pre\n",
6969
" print(\"installed cirq.\")"
7070
]
7171
},
@@ -88,7 +88,63 @@
8888
"outputs": [],
8989
"source": [
9090
"import cirq\n",
91-
"import numpy as np"
91+
"import numpy as np\n",
92+
"\n",
93+
"%matplotlib inline\n",
94+
"from matplotlib import pyplot as plt"
95+
]
96+
},
97+
{
98+
"cell_type": "markdown",
99+
"metadata": {},
100+
"source": [
101+
"# Parallel XEB with library functions\n",
102+
"The entire XEB workflow can be run by calling `cirq.experiments.parallel_two_qubit_xeb` and the combined single-qubit randomized benchmarking (RB) and XEB workflows can be run by calling `cirq.experiments.run_rb_and_xeb`."
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"metadata": {},
109+
"outputs": [],
110+
"source": [
111+
"# Simulation\n",
112+
"qubits = cirq.GridQubit.rect(3, 2, 4, 3)\n",
113+
"result = cirq.experiments.parallel_two_qubit_xeb(\n",
114+
" sampler=cirq.DensityMatrixSimulator(noise=cirq.depolarize(5e-3)), # Any simulator or a ProcessorSampler.\n",
115+
" qubits=qubits \n",
116+
")"
117+
]
118+
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": null,
122+
"metadata": {},
123+
"outputs": [],
124+
"source": [
125+
"# The returned result is an instance of the `TwoQubitXEBResult` class which provides visualization methods like \n",
126+
"result.plot_heatmap(); # plot the heatmap of XEB errors\n",
127+
"result.plot_fitted_exponential(*qubits[:2]); # plot the fitted model of xeb error of a qubit pair.\n",
128+
"result.plot_histogram(); # plot a histogram of all xeb errors."
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": null,
134+
"metadata": {},
135+
"outputs": [],
136+
"source": [
137+
"# `TwoQubitXEBResult` also has methods to retrieve errors.\n",
138+
"print('pauli errors:', result.pauli_error())\n",
139+
"print('xeb errors:', result.xeb_error(*qubits[:2]))\n",
140+
"print('xeb fidelity:', result.xeb_fidelity(*qubits[:2]))"
141+
]
142+
},
143+
{
144+
"cell_type": "markdown",
145+
"metadata": {},
146+
"source": [
147+
"The `run_rb_and_xeb` method returns an object of type [InferredXEBResult](https://github.com/quantumlib/Cirq/blob/bc766606b94744f80da435c522d16a34529ae671/cirq-core/cirq/experiments/two_qubit_xeb.py#L188C7-L188C24) which is like [TwoQubitXEBResult](https://github.com/quantumlib/Cirq/blob/bc766606b94744f80da435c522d16a34529ae671/cirq-core/cirq/experiments/two_qubit_xeb.py#L56) except that it removes the single-qubit errors obtained from the single-qubit randomized benchmarking (RB) experiment to isolate the error from the two qubit gate."
92148
]
93149
},
94150
{
@@ -97,6 +153,9 @@
97153
"id": "ace31cc4d258"
98154
},
99155
"source": [
156+
"# Step by step XEB\n",
157+
"The rest of this notebook explains how the `parallel_two_qubit_xeb` works internally. Note that the notebook uses `SQRT_ISWAP` as the entangling gate while `parallel_two_qubit_xeb` and `run_rb_and_xeb` default to `CZ`.\n",
158+
"\n",
100159
"## Set up Random Circuits\n",
101160
"\n",
102161
"We create a library of 10 random, two-qubit `circuits` using the sqrt(ISWAP) gate. These library circuits will be mixed-and-matched among all the pairs on the device we aim to characterize."
@@ -224,9 +283,6 @@
224283
},
225284
"outputs": [],
226285
"source": [
227-
"%matplotlib inline\n",
228-
"from matplotlib import pyplot as plt\n",
229-
"\n",
230286
"fig, axes = plt.subplots(2,2, figsize=(9,6))\n",
231287
"for comb_layer, ax in zip(combs_by_layer, axes.reshape(-1)):\n",
232288
" active_qubits = np.array(comb_layer.pairs).reshape(-1)\n",
@@ -500,6 +556,18 @@
500556
"kernelspec": {
501557
"display_name": "Python 3",
502558
"name": "python3"
559+
},
560+
"language_info": {
561+
"codemirror_mode": {
562+
"name": "ipython",
563+
"version": 3
564+
},
565+
"file_extension": ".py",
566+
"mimetype": "text/x-python",
567+
"name": "python",
568+
"nbconvert_exporter": "python",
569+
"pygments_lexer": "ipython3",
570+
"version": "3.10.13"
503571
}
504572
},
505573
"nbformat": 4,

0 commit comments

Comments
 (0)