Skip to content

Commit 3969c2d

Browse files
Remove use of deprecated device behavior from quantum_volume_errors. (#5198)
Title
1 parent 0e6659f commit 3969c2d

File tree

1 file changed

+140
-131
lines changed

1 file changed

+140
-131
lines changed
+140-131
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,143 @@
11
{
2-
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"metadata": {},
6-
"source": [
7-
"# Analyzing Quantum Volume Errors\n",
8-
"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."
9-
]
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "8e3qhaan0Vwx"
7+
},
8+
"source": [
9+
"# Analyzing Quantum Volume Errors\n",
10+
"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."
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"metadata": {
17+
"id": "bd9529db1c0b"
18+
},
19+
"outputs": [],
20+
"source": [
21+
"try:\n",
22+
" import cirq\n",
23+
"except ImportError:\n",
24+
" print(\"installing cirq...\")\n",
25+
" !pip install --quiet cirq\n",
26+
" print(\"installed cirq.\")"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": null,
32+
"metadata": {
33+
"id": "1QezTbjO0Vw4"
34+
},
35+
"outputs": [],
36+
"source": [
37+
"import cirq\n",
38+
"import cirq_google\n",
39+
"\n",
40+
"# Configuration parameters. Feel free to mess with these!\n",
41+
"num_circuits = 10\n",
42+
"depth = 4\n",
43+
"num_samplers = 50\n",
44+
"repetitions = 10_000\n",
45+
"device=cirq_google.Sycamore\n",
46+
"\n",
47+
"print(f\"Configuration: depth {depth} with \"\n",
48+
" f\"{num_circuits} circuits of {num_samplers} samplers\")"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": null,
54+
"metadata": {
55+
"id": "rZ_7U7n90Vw5"
56+
},
57+
"outputs": [],
58+
"source": [
59+
"# Run the Quantum Volume algorithm over the above parameters.\n",
60+
"\n",
61+
"import numpy as np\n",
62+
"from cirq.contrib import quantum_volume, routing\n",
63+
"\n",
64+
"errors = np.logspace(-1, -4, num=num_samplers)\n",
65+
"samplers = [\n",
66+
" cirq.DensityMatrixSimulator(noise=cirq.ConstantQubitNoiseModel(\n",
67+
" qubit_noise_gate=cirq.DepolarizingChannel(p=error)))\n",
68+
" for error in errors]\n",
69+
"\n",
70+
"result = quantum_volume.calculate_quantum_volume(\n",
71+
" num_circuits=num_circuits,\n",
72+
" depth=depth,\n",
73+
" num_qubits=depth,\n",
74+
" device_graph=routing.gridqubits_to_graph_device(device.qubits),\n",
75+
" samplers=samplers,\n",
76+
" compiler=cirq_google.optimized_for_sycamore,\n",
77+
" repetitions=repetitions)"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"metadata": {
84+
"id": "CvJvkMLx0Vw6"
85+
},
86+
"outputs": [],
87+
"source": [
88+
"# Create a chart that plots the HOG rate relative to the simulated error ratio.\n",
89+
"\n",
90+
"from matplotlib import pyplot as plt\n",
91+
"import statistics\n",
92+
"\n",
93+
"def chunks(l, n):\n",
94+
" \"\"\"Yield successive n-sized chunks from l.\"\"\"\n",
95+
" for i in range(0, len(l), n):\n",
96+
" yield l[i:i + n]\n",
97+
" \n",
98+
"split = chunks([res.sampler_result for res in result], num_circuits)\n",
99+
"fig, axs = plt.subplots()\n",
100+
"axs.plot(errors,\n",
101+
" [statistics.mean(chunk) for chunk in split])\n",
102+
"\n",
103+
"# Line markers for asymptotic ideal heavy output probability and the ideal Heavy\n",
104+
"# Output Generation threshold.\n",
105+
"axs.axhline((1 + np.log(2)) / 2,\n",
106+
" color='tab:green',\n",
107+
" label='Asymptotic ideal',\n",
108+
" linestyle='dashed')\n",
109+
"axs.axhline(2 / 3, label='HOG threshold', color='k', linestyle='dotted')\n",
110+
"plt.xscale('log')\n",
111+
"axs.set_ybound(0.4, 1)\n",
112+
"axs.set_xlabel(\"error rate\")\n",
113+
"axs.set_ylabel(\"est. heavy output probability\")\n",
114+
"fig.suptitle(f'HOG probability by simulated error rate for d={depth}')"
115+
]
116+
}
117+
],
118+
"metadata": {
119+
"kernelspec": {
120+
"display_name": "Python 3",
121+
"language": "python",
122+
"name": "python3"
123+
},
124+
"language_info": {
125+
"codemirror_mode": {
126+
"name": "ipython",
127+
"version": 3
128+
},
129+
"file_extension": ".py",
130+
"mimetype": "text/x-python",
131+
"name": "python",
132+
"nbconvert_exporter": "python",
133+
"pygments_lexer": "ipython3",
134+
"version": "3.8.9"
135+
},
136+
"colab": {
137+
"name": "quantum_volume_errors.ipynb",
138+
"provenance": []
139+
}
10140
},
11-
{
12-
"cell_type": "code",
13-
"execution_count": null,
14-
"metadata": {
15-
"id": "bd9529db1c0b"
16-
},
17-
"outputs": [],
18-
"source": [
19-
"try:\n",
20-
" import cirq\n",
21-
"except ImportError:\n",
22-
" print(\"installing cirq...\")\n",
23-
" !pip install --quiet cirq\n",
24-
" print(\"installed cirq.\")"
25-
]
26-
},
27-
{
28-
"cell_type": "code",
29-
"execution_count": null,
30-
"metadata": {},
31-
"outputs": [],
32-
"source": [
33-
"import cirq\n",
34-
"import cirq_google\n",
35-
"\n",
36-
"# Configuration parameters. Feel free to mess with these!\n",
37-
"num_circuits = 10\n",
38-
"depth = 4\n",
39-
"num_samplers = 50\n",
40-
"device = cirq_google.Bristlecone\n",
41-
"repetitions = 10_000\n",
42-
"compiler = lambda circuit: cirq_google.optimized_for_xmon(\n",
43-
" circuit=circuit,\n",
44-
" new_device=device)\n",
45-
"\n",
46-
"print(f\"Configuration: depth {depth} with \"\n",
47-
" f\"{num_circuits} circuits of {num_samplers} samplers\")"
48-
]
49-
},
50-
{
51-
"cell_type": "code",
52-
"execution_count": null,
53-
"metadata": {},
54-
"outputs": [],
55-
"source": [
56-
"# Run the Quantum Volume algorithm over the above parameters.\n",
57-
"\n",
58-
"import numpy as np\n",
59-
"from cirq.contrib import quantum_volume, routing\n",
60-
"\n",
61-
"errors = np.logspace(-1, -4, num=num_samplers)\n",
62-
"samplers = [\n",
63-
" cirq.DensityMatrixSimulator(noise=cirq.ConstantQubitNoiseModel(\n",
64-
" qubit_noise_gate=cirq.DepolarizingChannel(p=error)))\n",
65-
" for error in errors]\n",
66-
"\n",
67-
"result = quantum_volume.calculate_quantum_volume(\n",
68-
" num_circuits=num_circuits,\n",
69-
" depth=depth,\n",
70-
" num_qubits=depth,\n",
71-
" device_graph=routing.gridqubits_to_graph_device(device.qubits),\n",
72-
" samplers=samplers,\n",
73-
" compiler=compiler,\n",
74-
" repetitions=repetitions)"
75-
]
76-
},
77-
{
78-
"cell_type": "code",
79-
"execution_count": null,
80-
"metadata": {},
81-
"outputs": [],
82-
"source": [
83-
"# Create a chart that plots the HOG rate relative to the simulated error ratio.\n",
84-
"\n",
85-
"from matplotlib import pyplot as plt\n",
86-
"import statistics\n",
87-
"\n",
88-
"def chunks(l, n):\n",
89-
" \"\"\"Yield successive n-sized chunks from l.\"\"\"\n",
90-
" for i in range(0, len(l), n):\n",
91-
" yield l[i:i + n]\n",
92-
" \n",
93-
"split = chunks([res.sampler_result for res in result], num_circuits)\n",
94-
"fig, axs = plt.subplots()\n",
95-
"axs.plot(errors,\n",
96-
" [statistics.mean(chunk) for chunk in split])\n",
97-
"\n",
98-
"# Line markers for asymptotic ideal heavy output probability and the ideal Heavy\n",
99-
"# Output Generation threshold.\n",
100-
"axs.axhline((1 + np.log(2)) / 2,\n",
101-
" color='tab:green',\n",
102-
" label='Asymptotic ideal',\n",
103-
" linestyle='dashed')\n",
104-
"axs.axhline(2 / 3, label='HOG threshold', color='k', linestyle='dotted')\n",
105-
"plt.xscale('log')\n",
106-
"axs.set_ybound(0.4, 1)\n",
107-
"axs.set_xlabel(\"error rate\")\n",
108-
"axs.set_ylabel(\"est. heavy output probability\")\n",
109-
"fig.suptitle(f'HOG probability by simulated error rate for d={depth}')"
110-
]
111-
}
112-
],
113-
"metadata": {
114-
"kernelspec": {
115-
"display_name": "Python 3",
116-
"language": "python",
117-
"name": "python3"
118-
},
119-
"language_info": {
120-
"codemirror_mode": {
121-
"name": "ipython",
122-
"version": 3
123-
},
124-
"file_extension": ".py",
125-
"mimetype": "text/x-python",
126-
"name": "python",
127-
"nbconvert_exporter": "python",
128-
"pygments_lexer": "ipython3",
129-
"version": "3.8.9"
130-
}
131-
},
132-
"nbformat": 4,
133-
"nbformat_minor": 4
141+
"nbformat": 4,
142+
"nbformat_minor": 0
134143
}

0 commit comments

Comments
 (0)