Skip to content

Commit db78359

Browse files
Document CircuitOp optimizer best practices (#5221)
Final item for #3634. With the new transformers, there is a clean pipeline for optimizing nested circuits and sending the (concise!) result to hardware for execution.
1 parent 12c6cc8 commit db78359

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

docs/google/best_practices.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ sent to Quantum Engine due to an upper limit on request size. If the circuits
5656
in question have a repetitive structure, `cirq.CircuitOperation`s can be used
5757
to reduce the request size and avoid this limit.
5858

59-
`optimized_for_sycamore` will preserve `CircuitOperation`s while optimizing
60-
their contents.
61-
6259
```python
6360
import cirq
6461
import cirq_google as cg
@@ -81,6 +78,20 @@ circuit_op = circuit_op.repeat(100)
8178
short_circuit = cirq.Circuit(circuit_op for q in qubits)
8279
```
8380

81+
When compiling circuits with `CircuitOperation`s, providing a context
82+
with `deep=True` will preserve the `CircuitOperation`s while
83+
optimizing their contents. This is useful for producing a concise,
84+
device-compatible circuit.
85+
86+
```python
87+
ctx = cirq.TransformerContext(deep=True)
88+
cz_circuit = cirq.optimized_for_target_gateset(
89+
short_circuit,
90+
cirq.CZTargetGateset,
91+
context=ctx
92+
)
93+
```
94+
8495

8596
## Running circuits faster
8697

0 commit comments

Comments
 (0)