Skip to content
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
22 changes: 20 additions & 2 deletions cirq-core/cirq/contrib/paulistring/clifford_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,26 @@


def clifford_optimized_circuit(circuit: circuits.Circuit, atol: float = 1e-8) -> circuits.Circuit:
# Convert to a circuit with SingleQubitCliffordGates,
# CZs and other ignored gates
"""Optimizes a circuit composed of Clifford and CZ gates.

This function attempts to simplify a circuit by finding local optimizations.
It works in two stages:
1. It converts the circuit to a target gateset consisting of
`cirq.SingleQubitCliffordGate` and `cirq.CZPowGate` gates.
2. It then iterates through the circuit, applying the following rules:
- Merges adjacent single-qubit Clifford gates.
- Commutes single-qubit Clifford gates past CZ gates, attempting to
merge them with other single-qubit Clifford gates.
- Cancels pairs of identical CZ gates.

Args:
circuit: The circuit to optimize.
atol: A limit on the amount of absolute error introduced by the decomposition.

Returns:
The optimized circuit.
"""
# Convert to a circuit with SingleQubitCliffordGates, CZs and other ignored gates.
c_cliff = transformers.optimize_for_target_gateset(
circuit, gateset=CliffordTargetGateset(atol=atol)
)
Expand Down