Cirq
Cirq is a Python framework developed by Google's Quantum AI team for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits. It focuses on providing fine-tuned control over quantum circuits and gate-level operations for current-generation quantum processors. The library is actively maintained, with frequent releases, and is currently at version 1.6.1.
Warnings
- breaking The minimum required Python version has been increased to 3.11.0. Older Python versions are no longer supported.
- breaking The `cirq-rigetti` subpackage has been completely removed from the main `cirq` distribution. It was previously deprecated in v1.5.0.
- breaking The `cirq-ft` package (for fault-tolerant resource estimation) was removed from Cirq. It was deprecated in v1.3.0.
- deprecated The `cirq-rigetti` subpackage was deprecated and became an opt-in component, requiring explicit installation.
- gotcha A bug in `cirq.kraus` could return erroneous near-zero matrices, potentially affecting simulations or analysis involving Kraus operators.
- gotcha While Cirq v1.0.0 brought a commitment to API stability following SemVer, earlier versions (pre-1.0) were in an 'alpha' state with frequent breaking changes between releases.
Install
-
pip install cirq -
pip install cirq-core
Imports
- cirq
import cirq
- LineQubit
import cirq # ... q0, q1 = cirq.LineQubit.range(2)
- Simulator
import cirq # ... simulator = cirq.Simulator()
Quickstart
import cirq
import numpy as np
# Create two qubits
q0, q1 = cirq.LineQubit.range(2)
# Build a simple Bell state circuit
circuit = cirq.Circuit(
cirq.H(q0),
cirq.CNOT(q0, q1),
cirq.measure(q0, q1, key='result')
)
print("Circuit:")
print(circuit)
# Simulate the circuit 1000 times
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=1000)
# Display the measurement results
print("\nMeasurement results (histogram):")
print(result.histogram(key='result'))