Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Google Cirq: a Python Open Source Library for Quantum Computing

Google Cirq: a Python Open Source Library for Quantum Computing

This item in japanese

Cirq aims to make it easier to write, manipulate, and optimize quantum algorithms for noisy intermediate scale quantum (NISQ) computers. Cirq also enables the execution of those programs on a local simulator and is designed to support future quantum hardware and quantum cloud processors.

Noisy intermediate scale quantum computers will be the first quantum computers that will become available in the near future and that have been announced by several companies, including Microsoft, Google, IBM, Intel, and others. Comprised of 50–100 qubits, NISQ computers aim to allow researchers to demonstrate quantum supremacy, although their usefulness will be limited by quantum gates noise and thus by the efficiency of error correction algorithms that will be designed.

According to Google AI Quantum team engineers Alan Ho and Dave Bacon, one of the major hurdles when trying to program NISQ computers, beyond their intrinsic limitations, is getting the mapping between the algorithm and the hardware right, so qubits can be fully spent to solve the hardest part of the problem, as well as dealing with specific processor constraints, which could result in faulty computations when not addressed correctly. This is exactly where Cirq comes into play.

Cirq gives users fine tuned control over quantum circuits, specifying gate behavior using native gates, placing these gates appropriately on the device, and scheduling the timing of these gates within the constraints of the quantum hardware. Data structures are optimized for writing and compiling these quantum circuits to allow users to get the most out of NISQ architectures.

The following is minimalist "hello world" program for Cirq:

import cirq

# Pick a qubit.
qubit = cirq.GridQubit(0, 0)

# Create a circuit
circuit = cirq.Circuit.from_ops(
    cirq.X(qubit)**0.5,  # Square root of NOT.
    cirq.measure(qubit, key='m')  # Measurement.

# Simulate the circuit several times.
simulator =
result =, repetitions=20)

As you can see, Cirq provides higher-level syntax to manage typical quantum computing abstractions, such as a circuit, logical operations on qubits, or measurements. As the code snippet above shows, Cirq provides out-of-the-box support for local simulation, but according to Google Cirq higher-level instructions can also be translated into quantum circuits for Google’s Bristlecone processor, and will be used to access its Cloud version when it becomes available.

To learn how to use Circ, Google is providing a more complete tutorial which guides you through the process of creating a quantum variational algorithm, along with Cirq’s official documentation. Additionally, Google is releasing OpenFermion-Cirq, a platform to build low-depth quantum algorithms for quantum chemistry problems by translating the details of a chemical problem, such as simulating properties of molecules and complex materials, to Cirq circuits.

Cirq is available on GitHub and can be installed on Linux, Mac OS X, and Windows using pip:

python -m pip install --upgrade pip
python -m pip install cirq

A number of early adopters of Cirq, which is still in beta, have been announced, including Zapata Computing, QC Ware, Quantum Benchmark, and others.

For readers keen to learn more about quantum computing, Holly Cummins recently published a three-part introductory series on InfoQ; "Cats, Qubits, and Teleportation: The Spooky World of Quantum Computation".

Rate this Article