Cirq

An open source framework for programming quantum computers

Cirq is a Python software library for writing, manipulating, and optimizing quantum circuits, and then running them on quantum computers and quantum simulators. Cirq provides useful abstractions for dealing with today’s noisy intermediate-scale quantum computers, where details of the hardware are vital to achieving state-of-the-art results.

import cirq

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

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

# Simulate the circuit several times.
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=20)
print("Results:")
print(result)

Introduction to Cirq

Learn the basics of Cirq, from gates to operations to circuits to simulation. This is the best starting point for those who know the basics of quantum computing.

Circuits

Learn how to build quantum circuits from gates acting on qubits. Understand what a Moment is and how different insertion strategies can help you build your desired circuit. Learn about how to slice and dice circuits and transform them into new and better circuits.

Devices

Hardware constraints have a large impact on whether a circuit is practical or not on modern hardware. Learn how devices can be defined to handle these constraints.

Simulation

Cirq comes with built-in simulators, both for wave functions and for density matrices. These can handle noisy quantum channels using Monte Carlo or full density matrix simulations. In addition, Cirq works with qsim, a state-of-the-art wave function simulator. These simulators can be used to mock quantum hardware with the Quantum Virtual Machine.

End-2-end experiments

Cirq is used to run experiments on Google's quantum processors. Learn more about the latest experiments and access the code to see how to run them yourself.

Textbook Algorithms

Cirq users have coded up a zoo of textbook quantum algorithms. These give you an idea of good patterns to follow in your own code and are useful when you are learning these algorithms.

Quantum approximate optimization algorithm

Learn how to write a quantum approximate optimization algorithm for NISQ hardware by writing a variational algorithm to optimize a solution to max-cut, which is a hard problem for classical computing.

Quantum Virtual Machine

The Quantum Virtual Machine gives you the opportunity to run circuits on simulated hardware, which mocks the circuit constraints and noise behavior present in existing quantum hardware devices.