Cirq is an open-source Python framework for writing, optimizing and simulating quantum circuits, developed by Google Quantum AI and released in 2018 under the Apache 2.0 license. In quantum software it belongs to the family of quantum SDKs alongside Qiskit and PennyLane, and it is designed with a specific focus on noisy intermediate-scale quantum (NISQ) devices, where hardware details such as qubit layout and native gates matter for every experiment.
Within quantum computing, Cirq is best known for exposing hardware constraints directly to the programmer rather than hiding them behind heavy abstraction. It also serves as the foundation for libraries such as OpenFermion for quantum chemistry, TensorFlow Quantum for hybrid machine learning, and the high-performance simulator qsim.
How Cirq represents a quantum circuit
Cirq represents a circuit as an ordered list of moments, where each moment is a set of operations that act on disjoint qubits during the same time slice. This moment-based structure makes timing explicit: the programmer can see exactly which gates run in parallel and how deep the circuit is, which is essential on hardware where idle qubits decohere.
The core vocabulary is small and precise. The table below summarizes the main objects and what each one is responsible for.
| Object | Role | Typical example |
|---|---|---|
| Qubit | Identifies a physical or logical qubit | cirq.GridQubit(0, 1), cirq.LineQubit(3) |
| Gate | Abstract unitary or channel | cirq.H, cirq.CZ, cirq.rx(theta) |
| Operation | A gate applied to specific qubits | cirq.CNOT(q0, q1) |
| Moment | Operations in one time slice | Parallel single-qubit rotations |
| Circuit | Ordered sequence of moments | A full variational ansatz |
| Device | Validates hardware constraints | Allowed qubits and gate set |
When operations are appended, Cirq uses an insertion strategy to decide which moment receives them. The default strategy places each operation in the earliest moment where its qubits are free, which produces compact circuits without manual scheduling.
Simulation, parameters and noise
Cirq includes built-in simulators for both pure and mixed states. The default cirq.Simulator performs statevector simulation, whose memory grows as 2 to the power of n, so ordinary workstations handle roughly 25 to 32 qubits. The cirq.DensityMatrixSimulator tracks mixed states and supports noise channels, but its memory cost grows as 4 to the power of n, which limits it to about half as many qubits.
Variational algorithms rely on symbolic parameters. Gates can take SymPy symbols as angles, and a parameter sweep such as cirq.Linspace resolves them into concrete values at run time. This separation lets the same circuit be executed across hundreds of settings in one call, which is the pattern behind hybrid quantum-classical computing workflows such as VQE and QAOA.
| Method or tool | What it returns | Best used for |
|---|---|---|
| `simulate()` | Final state vector or density matrix | Debugging and amplitude analysis |
| `run()` | Sampled measurement results per shot | Hardware-like statistics |
| `run_sweep()` | Results for each parameter setting | Variational optimization loops |
| Noise models | Circuits with inserted error channels | Estimating realistic performance |
| qsim | Fast optimized simulation in C++ | Larger circuits, about 30 to 40 qubits |
The run() method returns sampled bitstrings, one per shot, keyed by measurement names. This mirrors real hardware, where only measurement outcomes are available, and it encourages writing analysis code that works unchanged on simulators and devices.
Compilation with transformers and target gate sets
Cirq compiles circuits through transformers, functions that take a circuit and return an equivalent rewritten circuit. Transformers merge adjacent single-qubit gates, drop negligible operations, eject Z rotations through other gates and convert operations into a target gate set such as the √iSWAP or Sycamore gates used by Google hardware or the CZ family used by many other platforms.
The function cirq.optimize_for_target_gateset chains these steps, and qubit routing utilities insert SWAP operations when the logical circuit requires interactions between physically distant qubits. Compared with the more automated pipelines in other toolkits, Cirq gives the user fine-grained control over each compilation pass, which suits research where the exact gate sequence is part of the experiment.
How Cirq compares with other quantum SDKs
Cirq differs from other quantum SDKs mainly in its emphasis on low-level hardware realism and in the ecosystem it serves. The comparison below covers the toolkits most often evaluated together with it.
| Framework | Main sponsor | Distinctive focus |
|---|---|---|
| Cirq | Google Quantum AI | Moments, device constraints, NISQ research |
| Qiskit | IBM | Full stack, extensive transpiler, IBM hardware |
| PennyLane | Xanadu | Differentiable programming and machine learning |
| TKET | Quantinuum | Hardware-agnostic compiler optimization |
| CUDA-Q | NVIDIA | GPU-accelerated hybrid kernels in C++ and Python |
Interoperability is good in practice. Cirq can export and import OpenQASM, PennyLane offers a Cirq plugin, and the stimcirq package connects Cirq circuits with the Stim stabilizer simulator for quantum error correction studies.
Hardware access and practical limitations
Cirq reaches physical hardware through vendor-specific modules. The cirq_google module targets Google processors, but access to that hardware is restricted to approved research partners. Separate packages such as cirq-ionq, cirq-aqt and cirq-pasqal provide access to trapped-ion and neutral-atom systems, and some cloud platforms accept circuits converted from Cirq.
- Limited public hardware: unlike IBM Quantum Platform, there is no broad open access to Google processors.
- Lower-level API: beginners often find Qiskit tutorials and higher-level abstractions easier to start with.
- Fewer built-in algorithms: application libraries live in separate projects such as OpenFermion and ReCirq.
- API evolution: older code written before version 1.0 may need updates after deprecations.
For teams that need precise control over gate timing and layout, these limitations are often acceptable, because Cirq makes the hardware model explicit and reproducible.
In simple terms
A quantum computer needs instructions, just like a regular computer, but those instructions are sequences of operations on qubits called circuits. Cirq is a toolkit for writing those circuits in Python, the popular programming language.
Think of it as sheet music for a quantum orchestra. Each column of notes shows which instruments play at the same moment, and Cirq checks that the music fits the actual instruments available. You can practice on a simulator on your laptop and then, if you have access, send the same score to real quantum hardware.
A practical example
A university chemistry group wants to estimate the ground-state energy of a small molecule such as lithium hydride. The researchers use OpenFermion to translate the molecular Hamiltonian into qubit operators and then build a variational ansatz in Cirq on 8 qubits, with 24 symbolic rotation angles.
They first run the circuit through the density matrix simulator with a depolarizing noise model of 0.5 percent per two-qubit gate to see how errors shift the energy estimate. A classical optimizer calls run_sweep() with 10,000 shots per evaluation, adjusting angles over about 200 iterations. The compiled circuit, converted to a CZ-based gate set with Cirq transformers, is then submitted to a trapped-ion device through a vendor module. The noisy hardware result lands within a few percent of the exact energy, and the simulation results help the group explain the remaining gap.