-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,143 @@ | ||
{ | ||
"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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think you can just make this
cirq_google.optimized_for_xmon
now andremove compiler lambda?Reply via ReviewNB