Skip to content

Commit 53ed3f2

Browse files
Update best practices page (quantumlib#8243)
Updates the best practices doc to reflect some changes since the document was written.
1 parent 5539290 commit 53ed3f2

1 file changed

Lines changed: 57 additions & 18 deletions

File tree

docs/google/best_practices.ipynb

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"This guide is split into three parts:\n",
9797
"* Getting your circuit to run\n",
9898
"* Making it run faster\n",
99+
"* Running it without keeping your laptop online\n",
99100
"* Lowering error"
100101
]
101102
},
@@ -112,12 +113,24 @@
112113
"gates will immediately cause a circuit to fail.\n",
113114
"\n",
114115
"Validating a circuit with a device, such as\n",
115-
"`cg.Sycamore.validate_circuit(circuit)` will test a lot of these\n",
116+
"`cg.Willow105.validate_circuit(circuit)` will test a lot of these\n",
116117
"conditions. Calling the `validate_circuit` function will work with any\n",
117118
"device, including those retrieved directly from the API using the\n",
118119
"[engine object](./specification.md#conversion-to-cirq.device), which can help\n",
119120
"identify any qubits used in the circuit that have been disabled on the actual\n",
120-
"device."
121+
"device. Sometimes, a pair of qubits may not have a gate calibrated between them\n",
122+
"even though the device object shows them as coupled. One way to see which pairs\n",
123+
"of adjacent qubits do not support gates between them is by checking the two-qubit\n",
124+
"XEB metrics, which can be found in the web UI\n",
125+
"([engine.quantumai.google](https://quantumai.engine.google)), where unsupported\n",
126+
"pairs of qubits will show as grey and be missing two-qubit metrics. These pairs of\n",
127+
"qubits will also be missing metrics in `engine.get_config(...).calibration`.\n",
128+
"\n",
129+
"Circuits containing gates other than CZ and single-qubit microwave gates may require\n",
130+
"special internal calibration. For example, if you intend to use cphase gates, physical\n",
131+
"Z gates, analog circuits, etc., you should discuss this with the Google support team\n",
132+
"to make sure the necessary calibrations and benchmarks are performed. Circuits containing\n",
133+
"classically-conditioned operations are not currently supported."
121134
]
122135
},
123136
{
@@ -250,7 +263,9 @@
250263
"id": "0e58b5ded5cb"
251264
},
252265
"source": [
253-
"### Use sweeps when possible\n",
266+
"### Use sweeps or batches when possible\n",
267+
"\n",
268+
"#### Sweeps:\n",
254269
"\n",
255270
"Round trip network time to and from the engine typically adds latency on the order of a second\n",
256271
"to the overall computation time. Reducing the number of trips and allowing the engine to\n",
@@ -315,16 +330,15 @@
315330
"id": "114fb6c6b766"
316331
},
317332
"source": [
318-
"### Use batches if sweeps are not possible\n",
333+
"#### Batches:\n",
319334
"\n",
320335
"The sampler has a method called `run_batch()` that can be used to send multiple\n",
321336
"circuits in a single request. This can be used to increase the efficiency\n",
322337
"of your program so that more repetitions are completed per second.\n",
323338
"\n",
324-
"The circuits that are grouped into the same batch must\n",
325-
"measure the same qubits and have the same number of repetitions for each\n",
326-
"circuit. Otherwise, the circuits will not be batched together\n",
327-
"on the device, and there will be no gain in efficiency."
339+
"By default, `run_batch` will create one job per circuit. It is also possible to\n",
340+
"pack multiple circuits into a job by specifying `jobs_per_batch` when loading the\n",
341+
"sampler using [`cirq_google.engine.ProcessorSampler(..., jobs_per_batch=...)`](https://quantumai.google/reference/python/cirq_google/engine/ProcessorSampler)."
328342
]
329343
},
330344
{
@@ -371,6 +385,37 @@
371385
"print(list(flat_sweep.param_tuples()))"
372386
]
373387
},
388+
{
389+
"cell_type": "markdown",
390+
"metadata": {
391+
"id": "3e442c11d381"
392+
},
393+
"source": [
394+
"## Running circuits without keeping your laptop online\n",
395+
"\n",
396+
"One can create an\n",
397+
"[`EngineProgram`](https://quantumai.google/reference/python/cirq_google/engine/EngineProgram)\n",
398+
"using\n",
399+
"[`engine.create_program`](https://quantumai.google/reference/python/cirq_google/engine/Engine#create_program).\n",
400+
"You can pass either a circuit or a list of circuits to this method, and you\n",
401+
"can optionally specify a program ID, description, and labels. After running\n",
402+
"this, the program should appear in the\n",
403+
"[\"Programs\" tab](https://console.cloud.google.com/quantum/programs) of the older web UI.\n",
404+
"\n",
405+
"You can then run a program using\n",
406+
"[`program.run()`](https://quantumai.google/reference/python/cirq_google/engine/EngineProgram#run)\n",
407+
"or\n",
408+
"[`program.run_sweep()`](https://quantumai.google/reference/python/cirq_google/engine/EngineProgram#run_sweep),\n",
409+
"which returns an [`EngineJob`](https://quantumai.google/reference/python/cirq_google/engine/EngineJob),\n",
410+
"which you can query for its status (`job.status()`) and its results (`job.results()`).\n",
411+
"Jobs can be named by specifying a `job_id` at the `program.run()` or `program.run_sweep()` step and can be retrived later\n",
412+
"using `job = engine.get_program(program_id).get_job(job_id)`. Jobs appear in the\n",
413+
"[jobs tab](https://console.cloud.google.com/quantum/jobs) of the older UI and the programs/jobs\n",
414+
"tab of the [new UI](https://engine.quantumai.google/program). Corresponding calibration metrics\n",
415+
"can be viewed using `job.get_config().calibration`. See the\n",
416+
"[calibration metrics tutorial](https://quantumai.google/cirq/google/calibration) for more details."
417+
]
418+
},
374419
{
375420
"cell_type": "markdown",
376421
"metadata": {
@@ -413,8 +458,7 @@
413458
"measuring all qubits with a single gate or by adding\n",
414459
"the measurement gate after all optimizers have run.\n",
415460
"\n",
416-
"Currently, only terminal measurements are supported by the hardware. If you\n",
417-
"absolutely need intermediate measurements for your application, reach out to\n",
461+
"If you need intermediate measurements for your application, reach out to\n",
418462
"your Google sponsor to see if they can help devise a proper circuit using\n",
419463
"intermediate measurements.\n",
420464
"\n",
@@ -425,7 +469,8 @@
425469
"[Spin Echo](https://en.wikipedia.org/wiki/Spin_echo) into your circuit onto\n",
426470
"qubits that have long idle periods, such as a pair\n",
427471
"of involutions, such as two successive Pauli Y gates, will generally increase\n",
428-
"performance of the circuit.\n",
472+
"performance of the circuit. This can be done using\n",
473+
"[`cirq.add_dynamical_decoupling`](https://quantumai.google/reference/python/cirq/add_dynamical_decoupling).\n",
429474
"\n",
430475
"Be aware that this should be done after calling\n",
431476
"`cirq.optimize_for_target_gateset`, since this function will 'optimize'\n",
@@ -470,13 +515,7 @@
470515
"calibration procedure. These metrics can be used as a baseline to evaluate\n",
471516
"circuit performance or identify outliers to avoid. This data can be inspected\n",
472517
"programmatically by retrieving metrics from the [API](calibration.md) or\n",
473-
"[visually by applying a cirq.Heatmap](../tutorials/google/visualizing_calibration_metrics.ipynb)\n",
474-
"to that data or by using the built-in\n",
475-
"heatmaps in the Cloud console page for the processor. Note that, since this\n",
476-
"data is only taken during calibration (e.g. at most daily), drifts and other\n",
477-
"concerns may affect the values significantly, so these metrics should only be\n",
478-
"used as a first approximation. There is no substitute for actually running characterizations\n",
479-
"on the device.\n",
518+
"using the [web UI](https://engine.quantumai.google).\n",
480519
"* Loschmidt echo: Running a small circuit on a string of qubits and then\n",
481520
"applying the circuit's inverse can be used as a quick but effective way to\n",
482521
"judge qubit quality. See\n",

0 commit comments

Comments
 (0)