Skip to content

Commit 0df354c

Browse files
authored
Update QVM demo notebooks to use willow_pink (#7428)
The following quantum virtual machine notebooks were updated to use the new `willow_pink` processor by default: - quantum_virtual_machine.ipynb - qvm_basic_example.ipynb - qvm_builder_code.ipynb - qvm_stabilizer_example.ipynb Small fixups in other reviewed notebooks. Related to b/395705720
1 parent 66b582f commit 0df354c

File tree

9 files changed

+107
-87
lines changed

9 files changed

+107
-87
lines changed

docs/simulate/noisy_simulation.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@
10011001
"source": [
10021002
"import cirq_google\n",
10031003
"\n",
1004-
"processor_id = \"rainbow\" # or \"weber\"\n",
1004+
"# See cirq_google.engine.list_virtual_processors() for available processor names\n",
1005+
"processor_id = \"willow_pink\" # or \"rainbow\" or \"weber\"\n",
10051006
"# Load the noise properties for the processor\n",
10061007
"noise_props = cirq_google.engine.load_device_noise_properties(processor_id)\n",
10071008
"# Build a noise model from the noise properties\n",

docs/simulate/quantum_virtual_machine.ipynb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@
138138
},
139139
"outputs": [],
140140
"source": [
141-
"# Choose a processor (\"rainbow\" or \"weber\")\n",
142-
"processor_id = \"weber\""
141+
"# Choose a processor (\"willow_pink\" or \"rainbow\" or \"weber\")\n",
142+
"# (see cirq_google.engine.list_virtual_processors() for available names)\n",
143+
"\n",
144+
"processor_id = \"willow_pink\""
143145
]
144146
},
145147
{
@@ -164,8 +166,6 @@
164166
},
165167
"outputs": [],
166168
"source": [
167-
"# Load the median device noise calibration for your selected processor.\n",
168-
"cal = cirq_google.engine.load_median_device_calibration(processor_id)\n",
169169
"# Load the noise properties for the processor.\n",
170170
"noise_props = cirq_google.engine.load_device_noise_properties(processor_id)\n",
171171
"# Create a noise model from the noise properties.\n",
@@ -200,6 +200,8 @@
200200
"# Package the simulator and device in an Engine.\n",
201201
"# The device object\n",
202202
"device = cirq_google.engine.create_device_from_processor_id(processor_id)\n",
203+
"# Load the median device noise calibration for your processor.\n",
204+
"cal = cirq_google.engine.load_median_device_calibration(processor_id)\n",
203205
"# The simulated processor object\n",
204206
"sim_processor = cirq_google.engine.SimulatedLocalProcessor(\n",
205207
" processor_id=processor_id, sampler=sim, device=device, calibrations={cal.timestamp // 1000: cal}\n",
@@ -236,7 +238,13 @@
236238
"source": [
237239
"q0 = cirq.GridQubit(4, 4)\n",
238240
"q1 = cirq.GridQubit(4, 5)\n",
239-
"circuit = cirq.Circuit(cirq.X(q0), cirq.SQRT_ISWAP(q0, q1), cirq.measure([q0, q1], key=\"measure\"))\n",
241+
"circuit = cirq.Circuit(\n",
242+
" cirq.X(q0),\n",
243+
" cirq.X(q1) ** 0.5,\n",
244+
" cirq.CZ(q0, q1),\n",
245+
" cirq.X(q1) ** 0.5,\n",
246+
" cirq.measure([q0, q1], key=\"measure\"),\n",
247+
")\n",
240248
"\n",
241249
"results = sim_engine.get_sampler(processor_id).run(circuit, repetitions=3000)\n",
242250
"\n",

docs/simulate/qvm_basic_example.ipynb

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"source": [
137137
"## Create a **Quantum Virtual Machine**\n",
138138
"\n",
139-
"The following cell builds a Quantum Virtual Machine that mimics a particular Google quantum hardware device (currently Rainbow or Weber) using the following customizable steps: \n",
139+
"The following cell builds a Quantum Virtual Machine that mimics a particular Google quantum hardware device (currently Willow-pink, Rainbow or Weber) using the following customizable steps: \n",
140140
"- Constructing a `cirq.NoiseModel` object from device calibration data saved in Cirq. See [Representing Noise](../noise/representing_noise.ipynb) for more on noise models. \n",
141141
"- Building a `qsimcirq.QsimSimulator` that uses this noise model. See [Noisy Simulation](./noisy_simulation.ipynb) and [Noise simulation with qsim](/qsim/tutorials/noisy_qsimcirq) for more. \n",
142142
"- Creating a `cirq.Device` that imposes the same constraints on circuits that the original device would. See [Devices](../hardware/devices.ipynb) for more on these constraint objects. \n",
@@ -154,17 +154,18 @@
154154
},
155155
"outputs": [],
156156
"source": [
157-
"# @title Choose a processor (\"rainbow\" or \"weber\")\n",
158-
"processor_id = \"weber\" # @param {type:\"string\"}\n",
157+
"# @title Choose a processor (\"willow_pink\" or \"rainbow\" or \"weber\")\n",
158+
"# (see cirq_google.engine.list_virtual_processors() for available names)\n",
159+
"processor_id = \"willow_pink\" # @param {type:\"string\"}\n",
159160
"\n",
160161
"# Construct a simulator with a noise model based on the specified processor.\n",
161-
"cal = cirq_google.engine.load_median_device_calibration(processor_id)\n",
162162
"noise_props = cirq_google.engine.load_device_noise_properties(processor_id)\n",
163163
"noise_model = cirq_google.NoiseModelFromGoogleNoiseProperties(noise_props)\n",
164164
"sim = qsimcirq.QSimSimulator(noise=noise_model)\n",
165165
"\n",
166166
"# Create a device from the public device description\n",
167167
"device = cirq_google.engine.create_device_from_processor_id(processor_id)\n",
168+
"cal = cirq_google.engine.load_median_device_calibration(processor_id)\n",
168169
"# Build the simulated local processor from the simulator and device.\n",
169170
"sim_processor = cirq_google.engine.SimulatedLocalProcessor(\n",
170171
" processor_id=processor_id, sampler=sim, device=device, calibrations={cal.timestamp // 1000: cal}\n",
@@ -193,7 +194,7 @@
193194
"- Is applied to qubits that exist on the device. \n",
194195
"- Respects the connectivity of qubits on the device.\n",
195196
"\n",
196-
"Below is an example of a circuit that has the correct topology to be placed on the Weber device, and how it is prepared to be run on the QVM."
197+
"Below is an example of a circuit that has the correct topology to be placed on the Willow-pink device, and how it is prepared to be run on the QVM."
197198
]
198199
},
199200
{
@@ -245,7 +246,7 @@
245246
"source": [
246247
"### Transform the circuit \n",
247248
"\n",
248-
"Before executing a circuit on (virtual) quantum hardware, the operations in the circuit need to be translated to use the types of gates the device supports. The `cirq.optimize_for_target_gateset` function does this for you, transforming the operations to use the `cirq.SqrtIswapTargetGateset`, which is supported by the Weber processor that this QVM is based on. Learn more about the gate set constraints of Google hardware at the [Hardware](../hardware) page."
249+
"Before executing a circuit on (virtual) quantum hardware, the operations in the circuit need to be translated to use the types of gates the device supports. The `cirq.optimize_for_target_gateset` function does this for you, transforming the operations to use the `cirq.CZTargetGateset`, which is supported by the Willow-pink processor that this QVM is based on. Learn more about the gate set constraints of Google hardware at the [Hardware](../hardware) page."
249250
]
250251
},
251252
{
@@ -256,9 +257,9 @@
256257
},
257258
"outputs": [],
258259
"source": [
259-
"# Convert the gates in the GHZ circuit to the \"SqrtIswap\" gateset, which the device uses.\n",
260+
"# Convert the gates in the GHZ circuit to the \"CZ\" gateset, which the device uses.\n",
260261
"translated_ghz_circuit = cirq.optimize_for_target_gateset(\n",
261-
" ghz_circuit, context=cirq.TransformerContext(deep=True), gateset=cirq.SqrtIswapTargetGateset()\n",
262+
" ghz_circuit, context=cirq.TransformerContext(deep=True), gateset=cirq.CZTargetGateset()\n",
262263
")\n",
263264
"print(translated_ghz_circuit)"
264265
]
@@ -271,7 +272,7 @@
271272
"source": [
272273
"### Choose qubits on the virtual device\n",
273274
"\n",
274-
"Choose qubits on the device to execute your device ready circuit on. Look at the device map (as above) and choose a set of qubits that fit your circuit (eg a line or a block). The Rainbow and Weber devices have different topologies, some qubit maps may be possible on only one of these devices. As noted, the GHZ example circuit as constructed will fit on a 17 qubit chain of adjacent qubits on the device, so you only need to find this consecutive line of qubits. See [Qubit Picking](../hardware/qubit_picking.ipynb) for more advice and methods for selecting qubits. "
275+
"Choose qubits on the device to execute your device ready circuit on. Look at the device map (as above) and choose a set of qubits that fit your circuit (eg a line or a block). The Willow-pink, Rainbow and Weber devices have different topologies, some qubit maps may be possible on only one of these devices. As noted, the GHZ example circuit as constructed will fit on a 17 qubit chain of adjacent qubits on the device, so you only need to find this consecutive line of qubits. See [Qubit Picking](../hardware/qubit_picking.ipynb) for more advice and methods for selecting qubits. "
275276
]
276277
},
277278
{
@@ -284,39 +285,39 @@
284285
"source": [
285286
"# Choose qubits on the virtual device\n",
286287
"device_qubit_chain = [\n",
287-
" cirq.GridQubit(5, 2),\n",
288-
" cirq.GridQubit(5, 3),\n",
289-
" cirq.GridQubit(4, 3),\n",
290-
" cirq.GridQubit(4, 2),\n",
291-
" cirq.GridQubit(4, 1),\n",
292-
" cirq.GridQubit(5, 1),\n",
293-
" cirq.GridQubit(6, 1),\n",
294-
" cirq.GridQubit(6, 2),\n",
295-
" cirq.GridQubit(6, 3),\n",
296-
" cirq.GridQubit(6, 4),\n",
288+
" cirq.GridQubit(5, 6),\n",
289+
" cirq.GridQubit(5, 7),\n",
290+
" cirq.GridQubit(4, 7),\n",
291+
" cirq.GridQubit(4, 6),\n",
292+
" cirq.GridQubit(4, 5),\n",
293+
" cirq.GridQubit(5, 5),\n",
297294
" cirq.GridQubit(6, 5),\n",
298-
" cirq.GridQubit(7, 5),\n",
299-
" cirq.GridQubit(8, 5),\n",
300-
" cirq.GridQubit(8, 4),\n",
301-
" cirq.GridQubit(8, 3),\n",
302-
" cirq.GridQubit(7, 3),\n",
303-
" cirq.GridQubit(7, 4),\n",
295+
" cirq.GridQubit(6, 6),\n",
296+
" cirq.GridQubit(6, 7),\n",
297+
" cirq.GridQubit(6, 8),\n",
298+
" cirq.GridQubit(6, 9),\n",
299+
" cirq.GridQubit(7, 9),\n",
300+
" cirq.GridQubit(8, 9),\n",
301+
" cirq.GridQubit(8, 8),\n",
302+
" cirq.GridQubit(8, 7),\n",
303+
" cirq.GridQubit(7, 7),\n",
304+
" cirq.GridQubit(7, 8),\n",
304305
"]\n",
305306
"# Layout:\n",
306307
"#\n",
307-
"# q(4, 1)───q(4, 2)───q(4, 3)\n",
308+
"# q(4, 5)───q(4, 6)───q(4, 7)\n",
308309
"# │ │\n",
309310
"# │ │\n",
310-
"# q(5, 1) q(5, 2)───q(5, 3)\n",
311+
"# q(5, 5) q(5, 6)───q(5, 7)\n",
311312
"# │\n",
312313
"# │\n",
313-
"# q(6, 1)───q(6, 2)───q(6, 3)───q(6, 4)───q(6, 5)\n",
314+
"# q(6, 5)───q(6, 6)───q(6, 7)───q(6, 8)───q(6, 9)\n",
314315
"# │\n",
315316
"# │\n",
316-
"# q(7, 3)───q(7, 4) q(7, 5)\n",
317+
"# q(7, 7)───q(7, 8) q(7, 9)\n",
317318
"# │ │\n",
318319
"# │ │\n",
319-
"# q(8, 3)───q(8, 4)───q(8, 5)"
320+
"# q(8, 7)───q(8, 8)───q(8, 9)"
320321
]
321322
},
322323
{

docs/simulate/qvm_builder_code.ipynb

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@
8080
"## **Install** Cirq and qsim"
8181
]
8282
},
83+
{
84+
"cell_type": "markdown",
85+
"metadata": {
86+
"id": "3f2687e48726"
87+
},
88+
"source": [
89+
"## Setup\n",
90+
"\n",
91+
"Note: this notebook relies on unreleased Cirq features. If you want to try these features, make sure you install cirq via `pip install --upgrade cirq~=1.0.dev`."
92+
]
93+
},
8394
{
8495
"cell_type": "code",
8596
"execution_count": null,
@@ -96,7 +107,7 @@
96107
" import cirq_google\n",
97108
"except ImportError:\n",
98109
" print(\"installing cirq...\")\n",
99-
" !pip install --quiet cirq-google\n",
110+
" !pip install --upgrade --quiet cirq-google~=1.0.dev\n",
100111
" print(\"installed cirq.\")\n",
101112
" import cirq\n",
102113
" import cirq_google\n",
@@ -132,8 +143,9 @@
132143
},
133144
"outputs": [],
134145
"source": [
135-
"# @title Choose a processor (\"rainbow\" or \"weber\")\n",
136-
"processor_id = \"rainbow\" # @param {type:\"string\"}\n",
146+
"# @title Choose a processor (\"willow_pink\" or \"rainbow\" or \"weber\")\n",
147+
"# (see cirq_google.engine.list_virtual_processors() for available names)\n",
148+
"processor_id = \"willow_pink\" # @param {type:\"string\"}\n",
137149
"\n",
138150
"# Instantiate an engine.\n",
139151
"sim_engine = cirq_google.engine.create_default_noisy_quantum_virtual_machine(\n",
@@ -175,7 +187,7 @@
175187
"outputs": [],
176188
"source": [
177189
"# create your device ready circuit here!\n",
178-
"q0 = cirq.GridQubit(4, 1)\n",
190+
"q0 = cirq.GridQubit(6, 3)\n",
179191
"your_circuit = cirq.Circuit([(cirq.X**0.5)(q0), cirq.measure(q0)])\n",
180192
"print(your_circuit)"
181193
]
@@ -210,6 +222,17 @@
210222
"print(f'QVM runtime: {elapsed:.04g}s ({reps} reps)')\n",
211223
"print('You can now print or plot \"results\"')"
212224
]
225+
},
226+
{
227+
"cell_type": "code",
228+
"execution_count": null,
229+
"metadata": {
230+
"id": "98bf142f5be6"
231+
},
232+
"outputs": [],
233+
"source": [
234+
"print(f\"measurements: {results.histogram(key=q0)}\")"
235+
]
213236
}
214237
],
215238
"metadata": {

docs/simulate/qvm_stabilizer_example.ipynb

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@
8080
"## **Install** Cirq and qsim, Create **Quantum Virtual Machine**"
8181
]
8282
},
83+
{
84+
"cell_type": "markdown",
85+
"metadata": {
86+
"id": "3f2687e48726"
87+
},
88+
"source": [
89+
"## Setup\n",
90+
"\n",
91+
"Note: this notebook relies on unreleased Cirq features. If you want to try these features, make sure you install cirq via `pip install --upgrade cirq~=1.0.dev`."
92+
]
93+
},
8394
{
8495
"cell_type": "code",
8596
"execution_count": null,
@@ -96,7 +107,7 @@
96107
" import cirq_google\n",
97108
"except ImportError:\n",
98109
" print(\"installing cirq...\")\n",
99-
" !pip install --quiet cirq-google\n",
110+
" !pip install --upgrade --quiet cirq-google~=1.0.dev\n",
100111
" print(\"installed cirq.\")\n",
101112
" import cirq\n",
102113
" import cirq_google\n",
@@ -124,8 +135,9 @@
124135
},
125136
"outputs": [],
126137
"source": [
127-
"# @title Create Quantum Virtual Machine: Choose a processor (\"rainbow\" or \"weber\")\n",
128-
"processor_id = \"rainbow\" # @param {type:\"string\"}\n",
138+
"# @title Create Quantum Virtual Machine: Choose a processor (\"willow_pink\", \"rainbow\" or \"weber\")\n",
139+
"# (see cirq_google.engine.list_virtual_processors() for available names)\n",
140+
"processor_id = \"willow_pink\" # @param {type:\"string\"}\n",
129141
"\n",
130142
"# Instantiate the engine.\n",
131143
"sim_engine = cirq_google.engine.create_default_noisy_quantum_virtual_machine(\n",
@@ -214,8 +226,7 @@
214226
"source": [
215227
"simulator = cirq.Simulator()\n",
216228
"result = simulator.run(stabilizer_circuit, repetitions=100)\n",
217-
"ax = cirq.plot_state_histogram(result)\n",
218-
"plt.show(ax)"
229+
"cirq.plot_state_histogram(result)"
219230
]
220231
},
221232
{
@@ -254,8 +265,7 @@
254265
"outputs": [],
255266
"source": [
256267
"result = simulator.run(stabilizer_circuit_with_error, repetitions=100)\n",
257-
"ax = cirq.plot_state_histogram(result)\n",
258-
"plt.show(ax)"
268+
"cirq.plot_state_histogram(result)"
259269
]
260270
},
261271
{
@@ -313,11 +323,16 @@
313323
" cirq.GridQubit(6, 3),\n",
314324
"]\n",
315325
"\n",
326+
"if processor_id == \"willow_pink\":\n",
327+
" target_gateset = cirq.CZTargetGateset()\n",
328+
"else:\n",
329+
" target_gateset = cirq.SqrtIswapTargetGateset()\n",
330+
"\n",
316331
"# Translate the circuit to a suitable gate set.\n",
317332
"test_stabilizer_circuit = cirq.optimize_for_target_gateset(\n",
318333
" stabilizer_circuit_for_hardware,\n",
319334
" context=cirq.TransformerContext(deep=True),\n",
320-
" gateset=cirq.SqrtIswapTargetGateset(),\n",
335+
" gateset=target_gateset,\n",
321336
")\n",
322337
"# Map circuit qubits to hardware ones.\n",
323338
"qubit_map = dict(zip([measure_qubit] + data_qubits, device_stabilizer_plaquette))\n",
@@ -378,8 +393,7 @@
378393
"\n",
379394
"print(\"Results (<meas>_<data>)\")\n",
380395
"ax = cirq.plot_state_histogram(hist)\n",
381-
"plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right')\n",
382-
"plt.show(ax)"
396+
"plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right');"
383397
]
384398
},
385399
{
@@ -406,7 +420,7 @@
406420
"}\n",
407421
"\n",
408422
"heatmap = cirq.Heatmap({**meas_map, **data_map})\n",
409-
"heatmap.plot()"
423+
"heatmap.plot();"
410424
]
411425
},
412426
{
@@ -560,7 +574,7 @@
560574
"}\n",
561575
"\n",
562576
"heatmap = cirq.Heatmap({**meas_map, **data_map})\n",
563-
"heatmap.plot()"
577+
"heatmap.plot();"
564578
]
565579
},
566580
{
@@ -587,7 +601,7 @@
587601
"test_stabilizer_grid_circuit = cirq.optimize_for_target_gateset(\n",
588602
" cirq.Circuit(cirq.decompose(stabilizer_grid_circuit)),\n",
589603
" context=cirq.TransformerContext(deep=True),\n",
590-
" gateset=cirq.SqrtIswapTargetGateset(),\n",
604+
" gateset=target_gateset,\n",
591605
")\n",
592606
"print(test_stabilizer_grid_circuit)"
593607
]
@@ -628,7 +642,7 @@
628642
"}\n",
629643
"\n",
630644
"heatmap = cirq.Heatmap({**meas_map, **data_map})\n",
631-
"heatmap.plot()"
645+
"heatmap.plot();"
632646
]
633647
}
634648
],

0 commit comments

Comments
 (0)