Skip to content

Document CircuitOp optimizer best practices #5221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions docs/google/best_practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ sent to Quantum Engine due to an upper limit on request size. If the circuits
in question have a repetitive structure, `cirq.CircuitOperation`s can be used
to reduce the request size and avoid this limit.

`optimized_for_sycamore` will preserve `CircuitOperation`s while optimizing
their contents.

```python
import cirq
import cirq_google as cg
Expand All @@ -81,6 +78,20 @@ circuit_op = circuit_op.repeat(100)
short_circuit = cirq.Circuit(circuit_op for q in qubits)
```

When compiling circuits with `CircuitOperation`s, providing a context
with `deep=True` will preserve the `CircuitOperation`s while
optimizing their contents. This is useful for producing a concise,
device-compatible circuit.

```python
ctx = cirq.TransformerContext(deep=True)
cz_circuit = cirq.optimized_for_target_gateset(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@95-martin-orion This should be cirq.optimize_for_target_gateset(short_circuit, gateset = cirq.CZTargetGateset(), context=ctx).
Differences from the current statement:

  • optimize instead of optimized
  • gateset should be a keyword argument.
  • cirq.CZTargetGateset is a class so we need to instantiate an instance of it.

I also think that the code snippet above demonstrating use of circuit operations for reducing serialization size is wrong. I've sent another PR doing these changes, can you please take a look? #5236

short_circuit,
cirq.CZTargetGateset,
context=ctx
)
```


## Running circuits faster

Expand Down