Cirq
The in-app starter (Bell state — runnable as-is):
import cirq
# Create a Bell Stateq0, q1 = cirq.LineQubit.range(2)circuit = cirq.Circuit([ cirq.H(q0), cirq.CNOT(q0, q1), cirq.measure(q0, q1, key='result'),])What the adapter does
Section titled “What the adapter does”| Stage | Behavior |
|---|---|
| Availability | import cirq happens at adapter-module import; if it fails, every call raises ImportError("cirq") → missing_dependency. |
| Discovery | After exec(), the last cirq.Circuit in the namespace wins. |
| Qubit indices | sorted(circuit.all_qubits()) defines snapshot indices 0..n-1. |
| Layering | Native moments are preserved: each operation’s layer is its moment index, and depth is the moment count — Cirq’s own layout is not re-packed by the greedy algorithm the other frameworks use. |
classical_bit_count | The number of MeasurementGate operations. |
Gate recognition
Section titled “Gate recognition”Cirq gates are recognized by isinstance checks on PowGate classes with
exponent == 1 (exact equality):
| Cirq | Canonical |
|---|---|
HPowGate/XPowGate/YPowGate/ZPowGate, exponent 1 | H / X / Y / Z |
ZPowGate, exponent 0.5 / 0.25 | S / T |
XPowGate/YPowGate/ZPowGate, any other exponent t | RX/RY/RZ with params = [t·π] |
CNotPowGate / CZPowGate / SwapPowGate / CCXPowGate, exponent 1 | CNOT / CZ / SWAP / Toffoli |
MeasurementGate | Measure |
| anything else | str(gate).upper() passthrough — rendered as a labeled box |
This means cirq.rz(θ) is recognized (it is a ZPowGate), but
cirq.CNOT**0.5 is not a CNOT — it falls to the passthrough rule.
Simulation
Section titled “Simulation”One cirq.Simulator, two passes:
- Exact statevector — a rebuilt circuit with every
MeasurementGatestripped, simulated withqubit_order=sorted(all_qubits). Producesstate_vector, exactprobabilities, and partial-trace Bloch coordinates. - Sampled run — the original circuit with
repetitions=shots. Per-measurement-key result arrays are concatenated in sorted key-name order into one bitstring per shot.
Probability keys are big-endian over the sorted qubit order — qubit 0 is the leftmost character. See bitstring-key conventions.
Gotchas
Section titled “Gotchas”- Qubit order is sorted order, not declaration order. A circuit on
LineQubit(5)andLineQubit(2)maps qubit 2 → index 0 and qubit 5 → index 1;GridQubits sort row-major. Sparse qubit ids are compacted. - Measurement-key names control bitstring layout. Keys are concatenated
alphabetically —
measure(q1, key='a')sorts beforemeasure(q0, key='b'), so themeasurementskeys put q1’s bit first. One multi-qubitmeasure(..., key='result')avoids the surprise. - Partial exponents become rotations with angle
t·π— equal toRZ(t·π)only up to global phase (aZPowGatecarries an extra phase factor relative to the canonicalRZmatrix). The Bloch sphere is unaffected; amplitude phases instate_vectorreflect the trueZPowGate, not the relabeledRZ. - Exact-equality exponent checks.
cirq.X**1.0isX, but a float artifact likecirq.X**0.9999999silently becomesRXwith a near-π angle.