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

Remove use of deprecated device behavior from quantum_volume_errors. #5198

Merged
merged 3 commits into from
Apr 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 140 additions & 131 deletions examples/advanced/quantum_volume_errors.ipynb
Original file line number Diff line number Diff line change
@@ -1,134 +1,143 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line #18.        compiler=compiler,

Think you can just make this cirq_google.optimized_for_xmonnow andremove compiler lambda?


Reply via ReviewNB

"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Analyzing Quantum Volume Errors\n",
"This notebook analyzes the error rates required for achieving Quantum Volume at a particular depth. For a given m = depth = number of qubits, plot the HOG for np.logspace outputs to view when it crosses the 2/3rds probability threshold."
]
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "8e3qhaan0Vwx"
},
"source": [
"# Analyzing Quantum Volume Errors\n",
"This notebook analyzes the error rates required for achieving Quantum Volume at a particular depth. For a given m = depth = number of qubits, plot the HOG for np.logspace outputs to view when it crosses the 2/3rds probability threshold."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bd9529db1c0b"
},
"outputs": [],
"source": [
"try:\n",
" import cirq\n",
"except ImportError:\n",
" print(\"installing cirq...\")\n",
" !pip install --quiet cirq\n",
" print(\"installed cirq.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "1QezTbjO0Vw4"
},
"outputs": [],
"source": [
"import cirq\n",
"import cirq_google\n",
"\n",
"# Configuration parameters. Feel free to mess with these!\n",
"num_circuits = 10\n",
"depth = 4\n",
"num_samplers = 50\n",
"repetitions = 10_000\n",
"device=cirq_google.Sycamore\n",
"\n",
"print(f\"Configuration: depth {depth} with \"\n",
" f\"{num_circuits} circuits of {num_samplers} samplers\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "rZ_7U7n90Vw5"
},
"outputs": [],
"source": [
"# Run the Quantum Volume algorithm over the above parameters.\n",
"\n",
"import numpy as np\n",
"from cirq.contrib import quantum_volume, routing\n",
"\n",
"errors = np.logspace(-1, -4, num=num_samplers)\n",
"samplers = [\n",
" cirq.DensityMatrixSimulator(noise=cirq.ConstantQubitNoiseModel(\n",
" qubit_noise_gate=cirq.DepolarizingChannel(p=error)))\n",
" for error in errors]\n",
"\n",
"result = quantum_volume.calculate_quantum_volume(\n",
" num_circuits=num_circuits,\n",
" depth=depth,\n",
" num_qubits=depth,\n",
" device_graph=routing.gridqubits_to_graph_device(device.qubits),\n",
" samplers=samplers,\n",
" compiler=cirq_google.optimized_for_sycamore,\n",
" repetitions=repetitions)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "CvJvkMLx0Vw6"
},
"outputs": [],
"source": [
"# Create a chart that plots the HOG rate relative to the simulated error ratio.\n",
"\n",
"from matplotlib import pyplot as plt\n",
"import statistics\n",
"\n",
"def chunks(l, n):\n",
" \"\"\"Yield successive n-sized chunks from l.\"\"\"\n",
" for i in range(0, len(l), n):\n",
" yield l[i:i + n]\n",
" \n",
"split = chunks([res.sampler_result for res in result], num_circuits)\n",
"fig, axs = plt.subplots()\n",
"axs.plot(errors,\n",
" [statistics.mean(chunk) for chunk in split])\n",
"\n",
"# Line markers for asymptotic ideal heavy output probability and the ideal Heavy\n",
"# Output Generation threshold.\n",
"axs.axhline((1 + np.log(2)) / 2,\n",
" color='tab:green',\n",
" label='Asymptotic ideal',\n",
" linestyle='dashed')\n",
"axs.axhline(2 / 3, label='HOG threshold', color='k', linestyle='dotted')\n",
"plt.xscale('log')\n",
"axs.set_ybound(0.4, 1)\n",
"axs.set_xlabel(\"error rate\")\n",
"axs.set_ylabel(\"est. heavy output probability\")\n",
"fig.suptitle(f'HOG probability by simulated error rate for d={depth}')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"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.8.9"
},
"colab": {
"name": "quantum_volume_errors.ipynb",
"provenance": []
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bd9529db1c0b"
},
"outputs": [],
"source": [
"try:\n",
" import cirq\n",
"except ImportError:\n",
" print(\"installing cirq...\")\n",
" !pip install --quiet cirq\n",
" print(\"installed cirq.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import cirq\n",
"import cirq_google\n",
"\n",
"# Configuration parameters. Feel free to mess with these!\n",
"num_circuits = 10\n",
"depth = 4\n",
"num_samplers = 50\n",
"device = cirq_google.Bristlecone\n",
"repetitions = 10_000\n",
"compiler = lambda circuit: cirq_google.optimized_for_xmon(\n",
" circuit=circuit,\n",
" new_device=device)\n",
"\n",
"print(f\"Configuration: depth {depth} with \"\n",
" f\"{num_circuits} circuits of {num_samplers} samplers\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Run the Quantum Volume algorithm over the above parameters.\n",
"\n",
"import numpy as np\n",
"from cirq.contrib import quantum_volume, routing\n",
"\n",
"errors = np.logspace(-1, -4, num=num_samplers)\n",
"samplers = [\n",
" cirq.DensityMatrixSimulator(noise=cirq.ConstantQubitNoiseModel(\n",
" qubit_noise_gate=cirq.DepolarizingChannel(p=error)))\n",
" for error in errors]\n",
"\n",
"result = quantum_volume.calculate_quantum_volume(\n",
" num_circuits=num_circuits,\n",
" depth=depth,\n",
" num_qubits=depth,\n",
" device_graph=routing.gridqubits_to_graph_device(device.qubits),\n",
" samplers=samplers,\n",
" compiler=compiler,\n",
" repetitions=repetitions)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create a chart that plots the HOG rate relative to the simulated error ratio.\n",
"\n",
"from matplotlib import pyplot as plt\n",
"import statistics\n",
"\n",
"def chunks(l, n):\n",
" \"\"\"Yield successive n-sized chunks from l.\"\"\"\n",
" for i in range(0, len(l), n):\n",
" yield l[i:i + n]\n",
" \n",
"split = chunks([res.sampler_result for res in result], num_circuits)\n",
"fig, axs = plt.subplots()\n",
"axs.plot(errors,\n",
" [statistics.mean(chunk) for chunk in split])\n",
"\n",
"# Line markers for asymptotic ideal heavy output probability and the ideal Heavy\n",
"# Output Generation threshold.\n",
"axs.axhline((1 + np.log(2)) / 2,\n",
" color='tab:green',\n",
" label='Asymptotic ideal',\n",
" linestyle='dashed')\n",
"axs.axhline(2 / 3, label='HOG threshold', color='k', linestyle='dotted')\n",
"plt.xscale('log')\n",
"axs.set_ybound(0.4, 1)\n",
"axs.set_xlabel(\"error rate\")\n",
"axs.set_ylabel(\"est. heavy output probability\")\n",
"fig.suptitle(f'HOG probability by simulated error rate for d={depth}')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"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.8.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
"nbformat": 4,
"nbformat_minor": 0
}