Skip to content

Commit d97d1b1

Browse files
tanujkhattaraugustehirth
authored andcommitted
Fix typos and nits in docs/transform.ipynb (quantumlib#5398)
Part of docs cleanup for Cirq 1.0
1 parent 1f177d0 commit d97d1b1

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

docs/transformers.ipynb

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,16 @@
108108
"Transformers that come with cirq can be found in the `cirq.transformers` package.\n",
109109
"\n",
110110
"A few notable examples are:\n",
111-
"* **cirq.align_left / cirq.align_right**: Align gates to the left/right of the circuit.\n",
112-
"* **cirq.defer_measurements**: Moves all (non-terminal) measurements in a circuit to the end of circuit by implementing the deferred measurement principle.\n",
113-
"* **cirq.drop_empty_moments** / **cirq.drop_negligible_operations**: Removes moments that are empty or operations that have very small effects, respectively.\n",
114-
"* **cirq.eject_phased_paulis**: Pushes X, Y, and PhasedX gates towards the end of the circuit, potentially absorbing Z gates and modifying gates along the way.\n",
115-
"* **cirq.eject_z**: Pushes Z gates towards the end of the circuit, potentially adjusting phases of gates that they pass through.\n",
116-
"* **cirq.expand_composite**: Uses `cirq.decompose` to expand composite gates.\n",
117-
"* **cirq.merge_k_qubit_unitaries**: Replaces connected components of unitary operations, acting on <= k qubits, with op-tree given by `rewriter(circuit_op)`.\n",
118-
"* **cirq.optimize_for_target_gateset**: Attempts to convert a circuit into and equivalent circuit using only gates from a given target gateset.\n",
119-
"* **cirq.stratified_circuit**: Repacks the circuit to ensure that moments only contain operations from the same category.\n",
120-
"* **cirq.synchronize_terminal_measurements**: Moves all terminal measurements in a circuit to the final moment, if possible.\n",
111+
"* **`cirq.align_left` / `cirq.align_right`**: Align gates to the left/right of the circuit.\n",
112+
"* **`cirq.defer_measurements`**: Moves all (non-terminal) measurements in a circuit to the end of circuit by implementing the deferred measurement principle.\n",
113+
"* **`cirq.drop_empty_moments`** / **`cirq.drop_negligible_operations`**: Removes moments that are empty or operations that have very small effects, respectively.\n",
114+
"* **`cirq.eject_phased_paulis`**: Pushes X, Y, and PhasedX gates towards the end of the circuit, potentially absorbing Z gates and modifying gates along the way.\n",
115+
"* **`cirq.eject_z`**: Pushes Z gates towards the end of the circuit, potentially adjusting phases of gates that they pass through.\n",
116+
"* **`cirq.expand_composite`**: Uses `cirq.decompose` to expand composite gates.\n",
117+
"* **`cirq.merge_k_qubit_unitaries`**: Replaces connected components of unitary operations, acting on <= k qubits, with op-tree given by `rewriter(circuit_op)`.\n",
118+
"* **`cirq.optimize_for_target_gateset`**: Attempts to convert a circuit into an equivalent circuit using only gates from a given target gateset.\n",
119+
"* **`cirq.stratified_circuit`**: Repacks the circuit to ensure that moments only contain operations from the same category.\n",
120+
"* **`cirq.synchronize_terminal_measurements`**: Moves all terminal measurements in a circuit to the final moment, if possible.\n",
121121
"\n",
122122
"\n",
123123
"Below you can see how to implement a transformer pipeline called `optimize_circuit`."
@@ -171,7 +171,7 @@
171171
"\n",
172172
"Every transformer in Cirq accepts a `cirq.TransformerContext` instance, which stores common configurable options useful for all transformers. \n",
173173
"\n",
174-
"One of the members of transformer context dataclass is `cirq.TransformerLogger` instance. When a logger instance is specified, every cirq transformer logs it's action on the input circuit using the given logger instance. The logs can then be inspected to understand the action of each individual transformer on the circuit. \n",
174+
"One of the members of transformer context dataclass is `cirq.TransformerLogger` instance. When a logger instance is specified, every cirq transformer logs its action on the input circuit using the given logger instance. The logs can then be inspected to understand the action of each individual transformer on the circuit.\n",
175175
"\n",
176176
"Below, you can inspect the action of each transformer in the `optimize_circuit` method defined above. "
177177
]
@@ -195,7 +195,7 @@
195195
"id": "kLm-5LHr0YAd"
196196
},
197197
"source": [
198-
"## Support for no-compile tags. \n",
198+
"## Support for no-compile tags\n",
199199
"\n",
200200
"Cirq also supports tagging operations with no-compile tags such that these tagged operations are ignored when applying transformations on the circuit. This allows users to gain more fine-grained conrol over the compilation process. \n",
201201
"\n",
@@ -239,7 +239,7 @@
239239
"id": "3f3c7851a571"
240240
},
241241
"source": [
242-
"## Support for recursively transforming sub-circuits.\n",
242+
"## Support for recursively transforming sub-circuits\n",
243243
"\n",
244244
"By default, an operation `op` of type `cirq.CircuitOperation` is considered as a single top-level operation by cirq transformers. As a result, the sub-circuits wrapped inside circuit operations will often be left as it is and a transformer will only modify the top-level circuit. \n",
245245
"\n",
@@ -281,7 +281,7 @@
281281
},
282282
"source": [
283283
"## Compiling to NISQ targets: `cirq.CompilationTargetGateset`\n",
284-
"Cirq's philosophy on compiling circuits for execution on a NISQ target device or simulator is that it would often require running only a handful of individual compilation passes on the input circuit, one after the other. \n",
284+
"Cirq's philosophy on compiling circuits for execution on a NISQ target device or simulator is that it would often require running only a handful of individual compilation passes on the input circuit, one after the other.\n",
285285
"\n",
286286
"**`cirq.CompilationTargetGateset`** is an abstraction in Cirq to represent such compilation targets as well as the bundles of transformer passes which should be executed to compile a circuit to this target. Cirq has implementations for common target gatesets like `cirq.CZTargetGateset`, `cirq.SqrtIswapTargetGateset` etc.\n",
287287
"\n",
@@ -319,6 +319,15 @@
319319
"print(\"Circuit compiled for CZ Target Gateset:\", cz_circuit, \"\\n\", sep=\"\\n\")"
320320
]
321321
},
322+
{
323+
"cell_type": "markdown",
324+
"metadata": {
325+
"id": "b963809fa20b"
326+
},
327+
"source": [
328+
"`cirq.optimize_for_target_gateset` also supports all the features discussed above, using `cirq.TransformerContext`. For example, you can compile the circuit for sqrt-iswap target gateset and inspect action of individual transformers using `cirq.TransformerLogger`, as shown below."
329+
]
330+
},
322331
{
323332
"cell_type": "code",
324333
"execution_count": null,
@@ -327,8 +336,6 @@
327336
},
328337
"outputs": [],
329338
"source": [
330-
"# `cirq.optimize_for_target_gateset` also supports all the features discussed above, using `cirq.TransformerContext`.\n",
331-
"# For example, you can compile the circuit for Sqrt-Iswap Target Gateset and inspect action of individual transformers.\n",
332339
"context = cirq.TransformerContext(logger=cirq.TransformerLogger())\n",
333340
"gateset = cirq.SqrtIswapTargetGateset()\n",
334341
"sqrt_iswap_circuit = cirq.optimize_for_target_gateset(circuit, gateset = gateset, context=context)\n",
@@ -342,7 +349,7 @@
342349
"id": "jyNdxrkI4CYX"
343350
},
344351
"source": [
345-
"# Building custom Transformers"
352+
"# Building custom transformers"
346353
]
347354
},
348355
{
@@ -351,7 +358,7 @@
351358
"id": "6da0Ra7bz2St"
352359
},
353360
"source": [
354-
"## `cirq.TRANSFORMER` API and `@cirq.transformer` decorator.\n",
361+
"## `cirq.TRANSFORMER` API and `@cirq.transformer` decorator\n",
355362
"\n",
356363
"Any callable that satisfies the `cirq.TRANSFORMER` contract, i.e. takes a `cirq.AbstractCircuit` and `cirq.TransformerContext` and returns a transformed `cirq.AbstractCircuit`, is a valid transformer in Cirq. \n",
357364
"\n",
@@ -401,10 +408,10 @@
401408
"id": "OLJrXdyTCGev"
402409
},
403410
"source": [
404-
"## `cirq.TransformerContext` to store common configurable options. \n",
411+
"## `cirq.TransformerContext` to store common configurable options\n",
405412
"`cirq.TransformerContext` is a dataclass that stores common configurable options for all transformers. All cirq transformers should accept the transformer context as an optional keyword argument. \n",
406413
"\n",
407-
"The `@cirq.transformer` decorator inspects the `cirq.TransformerContext` argument and automatically appends useful functionality like support for automated logging and recursively running the transformer on nested sub-circuits. \n"
414+
"The `@cirq.transformer` decorator can inspect the `cirq.TransformerContext` argument and automatically append useful functionality, like support for automated logging and recursively running the transformer on nested sub-circuits.\n"
408415
]
409416
},
410417
{
@@ -413,7 +420,7 @@
413420
"id": "5OuMLlNAFPcW"
414421
},
415422
"source": [
416-
"### `cirq.TransformerLogger` and support for automated logging.\n",
423+
"### `cirq.TransformerLogger` and support for automated logging\n",
417424
"The `cirq.TransformerLogger` class is used to log the actions of a transformer on an input circuit. `@cirq.transformer` decorator automatically adds support for logging the initial and final circuits for each transfomer step. "
418425
]
419426
},
@@ -437,7 +444,7 @@
437444
"id": "UvFdvxQ6MZD9"
438445
},
439446
"source": [
440-
"### Support for `deep=True`.\n",
447+
"### Support for `deep=True`\n",
441448
"You can call `@cirq.transformer(add_deep_support=True)` to automatically add the functionality of recursively running the custom transformer on circuits wrapped inside `cirq.CircuitOperation`. The recursive execution behavior of the transformer can then be controlled by setting `deep=True` in the transformer context. "
442449
]
443450
},
@@ -488,8 +495,8 @@
488495
"\n",
489496
"- **`cirq.map_operations`**: Applies local transformations on operations, by calling `map_func(op)` for each `op`.\n",
490497
"- **`cirq.map_moments`**: Applies local transformation on moments, by calling `map_func(m)` for each moment `m`.\n",
491-
"- **`cirq.merge_operations`**: Merges connected component of operations by calling `merge_func(op1, op2)` on iteratively for every mergeable operation `op1` and `op2`.\n",
492-
"- **`cirq.merge_moments`**: Merges adjacent moments, from left to right, by calling `merge_func(m1, m2)`.\n",
498+
"- **`cirq.merge_operations`**: Merges connected component of operations by iteratively calling `merge_func(op1, op2)` for every pair of mergeable operations `op1` and `op2`.\n",
499+
"- **`cirq.merge_moments`**: Merges adjacent moments, from left to right, by iteratively calling `merge_func(m1, m2)` for adjacent moments `m1` and `m2`.\n",
493500
"\n",
494501
"\n",
495502
"An important property of these primitives is that they have support for common configurable options present in `cirq.TransformerContext`, such as `tags_to_ignore` and `deep`. See the example below for a better understanding."

0 commit comments

Comments
 (0)