|
65 | 65 | " import cirq\n",
|
66 | 66 | "except ImportError:\n",
|
67 | 67 | " print(\"installing cirq...\")\n",
|
68 |
| - " !pip install --quiet cirq\n", |
| 68 | + " !pip install --quiet cirq --pre\n", |
69 | 69 | " print(\"installed cirq.\")"
|
70 | 70 | ]
|
71 | 71 | },
|
|
88 | 88 | "outputs": [],
|
89 | 89 | "source": [
|
90 | 90 | "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." |
92 | 148 | ]
|
93 | 149 | },
|
94 | 150 | {
|
|
97 | 153 | "id": "ace31cc4d258"
|
98 | 154 | },
|
99 | 155 | "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", |
100 | 159 | "## Set up Random Circuits\n",
|
101 | 160 | "\n",
|
102 | 161 | "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 | 283 | },
|
225 | 284 | "outputs": [],
|
226 | 285 | "source": [
|
227 |
| - "%matplotlib inline\n", |
228 |
| - "from matplotlib import pyplot as plt\n", |
229 |
| - "\n", |
230 | 286 | "fig, axes = plt.subplots(2,2, figsize=(9,6))\n",
|
231 | 287 | "for comb_layer, ax in zip(combs_by_layer, axes.reshape(-1)):\n",
|
232 | 288 | " active_qubits = np.array(comb_layer.pairs).reshape(-1)\n",
|
|
500 | 556 | "kernelspec": {
|
501 | 557 | "display_name": "Python 3",
|
502 | 558 | "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" |
503 | 571 | }
|
504 | 572 | },
|
505 | 573 | "nbformat": 4,
|
|
0 commit comments