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

update parallel XEB notebook #6494

Merged
merged 13 commits into from
Mar 15, 2024
78 changes: 73 additions & 5 deletions docs/noise/qcvv/parallel_xeb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
" import cirq\n",
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

@eliottrosenberg eliottrosenberg Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that it's worth commenting that the default entangling gate in parallel_two_qubit_xeb is CZ even though this example uses sqrt_iswap?


Reply via ReviewNB

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

"except ImportError:\n",
" print(\"installing cirq...\")\n",
" !pip install --quiet cirq\n",
" !pip install --quiet cirq --pre\n",
" print(\"installed cirq.\")"
]
},
Expand All @@ -88,7 +88,63 @@
"outputs": [],
"source": [
"import cirq\n",
"import numpy as np"
"import numpy as np\n",
"\n",
"%matplotlib inline\n",
"from matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Parallel XEB with library functions\n",
"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`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Simulation\n",
"qubits = cirq.GridQubit.rect(3, 2, 4, 3)\n",
"result = cirq.experiments.parallel_two_qubit_xeb(\n",
" sampler=cirq.DensityMatrixSimulator(noise=cirq.depolarize(5e-3)), # Any simulator or a ProcessorSampler.\n",
" qubits=qubits \n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The returned result is an instance of the `TwoQubitXEBResult` class which provides visualization methods like \n",
NoureldinYosri marked this conversation as resolved.
Show resolved Hide resolved
"result.plot_heatmap(); # plot the heatmap of XEB errors\n",
"result.plot_fitted_exponential(*qubits[:2]); # plot the fitted model of xeb error of a qubit pair.\n",
"result.plot_histogram(); # plot a histogram of all xeb errors."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# `TwoQubitXEBResult` also has methods to retrieve errors.\n",
"print('pauli errors:', result.pauli_error())\n",
"print('xeb errors:', result.xeb_error(*qubits[:2]))\n",
"print('xeb fidelity:', result.xeb_fidelity(*qubits[:2]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
]
},
{
Expand All @@ -97,6 +153,9 @@
"id": "ace31cc4d258"
},
"source": [
"# Step by step XEB\n",
"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",
"\n",
"## Set up Random Circuits\n",
"\n",
"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."
Expand Down Expand Up @@ -224,9 +283,6 @@
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"from matplotlib import pyplot as plt\n",
"\n",
"fig, axes = plt.subplots(2,2, figsize=(9,6))\n",
"for comb_layer, ax in zip(combs_by_layer, axes.reshape(-1)):\n",
" active_qubits = np.array(comb_layer.pairs).reshape(-1)\n",
Expand Down Expand Up @@ -500,6 +556,18 @@
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down