Skip to content

Cirq

The in-app starter (Bell state — runnable as-is):

import cirq
# Create a Bell State
q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit([
cirq.H(q0),
cirq.CNOT(q0, q1),
cirq.measure(q0, q1, key='result'),
])
StageBehavior
Availabilityimport cirq happens at adapter-module import; if it fails, every call raises ImportError("cirq")missing_dependency.
DiscoveryAfter exec(), the last cirq.Circuit in the namespace wins.
Qubit indicessorted(circuit.all_qubits()) defines snapshot indices 0..n-1.
LayeringNative 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_countThe number of MeasurementGate operations.

Cirq gates are recognized by isinstance checks on PowGate classes with exponent == 1 (exact equality):

CirqCanonical
HPowGate/XPowGate/YPowGate/ZPowGate, exponent 1H / X / Y / Z
ZPowGate, exponent 0.5 / 0.25S / T
XPowGate/YPowGate/ZPowGate, any other exponent tRX/RY/RZ with params = [t·π]
CNotPowGate / CZPowGate / SwapPowGate / CCXPowGate, exponent 1CNOT / CZ / SWAP / Toffoli
MeasurementGateMeasure
anything elsestr(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.

One cirq.Simulator, two passes:

  1. Exact statevector — a rebuilt circuit with every MeasurementGate stripped, simulated with qubit_order=sorted(all_qubits). Produces state_vector, exact probabilities, and partial-trace Bloch coordinates.
  2. 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.

  • Qubit order is sorted order, not declaration order. A circuit on LineQubit(5) and LineQubit(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 before measure(q0, key='b'), so the measurements keys put q1’s bit first. One multi-qubit measure(..., key='result') avoids the surprise.
  • Partial exponents become rotations with angle t·π — equal to RZ(t·π) only up to global phase (a ZPowGate carries an extra phase factor relative to the canonical RZ matrix). The Bloch sphere is unaffected; amplitude phases in state_vector reflect the true ZPowGate, not the relabeled RZ.
  • Exact-equality exponent checks. cirq.X**1.0 is X, but a float artifact like cirq.X**0.9999999 silently becomes RX with a near-π angle.