Programming a quantum computer with Cirq (QuantumCasts)

Programming a quantum computer with Cirq (QuantumCasts)

DAVE BACON: A quantum computer
is a new type of computer that stores and acts on
information in its quantum form. Today, we are entering
into an exciting era where quantum
computers are beginning to be large enough
and performant enough to execute tasks in
less than a second that would take years to execute
on a normal computer. Here is Google’s own
Bristlecone chip. This is a quantum computer made
of superconducting circuits with 72 quantum bits. Google’s researchers are using
this chip to attempt to achieve a task that cannot be solved
in years on a supercomputer. Hi. I’m Dave Bacon from Google. I run the team that builds
software for Google’s quantum computers. And today, I’d like to tell
you a little bit about how we program Google’s
quantum computers. We do this using an open
source framework called Cirq. A quantum computer stores its
information using quantum bits, or qubits. The information in
these qubits is then maneuvered around using the
laws of quantum physics. To describe an algorithm
on a quantum computer, you would use what is called
the quantum circuit model. The quantum circuit
model is essentially a diagram describing how to
perform a quantum computation. Here is an example
of a quantum circuit. You read this diagram
like a sheet of music from left to right. Each of the qubits
in a quantum computer corresponds to a
single horizontal wire in the quantum circuit. Here we see that
this quantum circuit operates on four qubits. The boxes in the
diagram correspond to quantum gates that are
applied to one or more qubits, depending on how many wires
the box is connected to. Here’s a single qubit gate. And here is a two qubit gate. Quantum gates are instructions
to send control signals to the quantum computer to
perform a certain quantum action on the qubits. Finally, one has
instructions for reading out the quantum information. This corresponds to quantum
gates that perform measurements and turn quantum bits
into classical bits. If we have a quantum
circuit diagram, we can use this diagram
to send microwave pulses and instructions to our
quantum computing hardware to execute the quantum
gates, and then read out the result
of the circuit, like reading a sheet of music. As we sweep from left to
right, we play the given gates as they appear. The quantum circuit
diagram is cool looking. But of course, if we had to
draw a diagram to do this, and we are writing really
long quantum programs, this would quickly become
very challenging to do. To solve this
problem, researchers have developed frameworks,
or programming languages, to write more traditional
looking programs that represent the quantum circuit. An open source framework that
we use at Google for this effort is called Cirq. Welcome to the [? Cirqus. ?]
Let’s write a simple circuit. Cirq is a Python framework. This means you can use
all the goodness of Python in helping to write
your quantum program. The central object in
Cirq is a circuit object. Here we show creating
a circuit object. Another key set of
objects are qubits. Let’s define two qubits
with simple names. Now we can perform some
quantum gates on these qubits. Let’s apply a single qubit
Hadamard gate denoted by H to one of the qubits, followed
by a two qubit controlled NOT, or CNOT gate,
between the qubits. Finally, let’s measure
the quantum bits. What circuit have we produced? Simply use Print
to see the circuit. No, it’s not 1993. But ASCII diagrams are useful
for seeing the quantum circuit that you’ve built. Here we
see the H gate for a Hadamard, followed by the controlled NOT
gate with the ampersand symbol and the x symbol. And finally, the measurements
represented by M. Once we’ve constructed a quantum
circuit, what do we do with it? In Cirq right now,
you can perform a simulation of the circuit. Here we run the circuit 10
times and see the measurement results. Measurement results
in quantum computers don’t always give the
same values of bits. One run of the circuit may
result in the output being 0, and another in it being 1. Here we see that the
measurement results differ for each run of the simulation. Cirq also contains an interface
for running the quantum circuit against actual quantum hardware. Now that you’ve seen a simple
quantum circuit in Cirq, you might think, great. Now I can write really
large quantum programs. For example, it is known
that quantum computers can efficiently factor numbers,
something that breaks modern public key cryptography. That’s pretty scary. Today’s quantum
computers, however, are very far from being
able to perform this task. This is because essentially,
quantum computers can only perform so much quantum
computation before the quantum computation falls apart. Consider again a
quantum circuit. Every gate that you
apply in this circuit corresponds to some pretty
complicated electronics, shaping and setting of
electromagnetic fields to the quantum computer. These pulses are
not always perfect, and so every single one
of the gates you perform has some effective
chance of failing. Boom! One of our single
qubit gates has failed. In addition to not being able
to execute gates exactly, quantum computers also have
a problem just doing nothing. That is, if you leave quantum
bits around, over time, the quantum information stored
in them will decay away. We call this
process decoherence. Boom! While waiting to execute the
next gate, one of our qubits has failed due to decoherence. Today’s quantum computers
don’t perform exactly as we specify them in the
quantum circuit model. We call this the problem of
noise in quantum computers. Because of noise, the size
of our quantum computation is limited for today’s
quantum computers. It is limited both in
the number of qubits and the number of operations
we can perform on these qubits. If quantum computers
are noisy, can we ever build a really large
quantum computer? The answer to this is yes. Using a magic protocol called
quantum error correction. We won’t focus on
error correction here, but it is a procedure for
turning a bunch of noisy qubits into a fewer number of
much less noisy qubits. Since today’s quantum computers
cannot perform arbitrary large or long quantum computation,
an important question is, what can they do? This is the main question of
what people call the NISQ era. NISQ stands for Noisy
Intermediate-Scale Quantum. And it is used to distinguish
today’s quantum computers from future error corrected
quantum computers. Are there algorithms
of practical value in the NISQ era? We do not know the
answer to this question. On the other hand,
we also know that we are starting to build
quantum computers which exceed the capabilities
of classical computers, the so-called
supremacy frontier. Because of this, there
is tremendous excitement in quantum computing. We are entering
into the unknown, an era where there is potential
for important discovery. We built Cirq for NISQ computers
and to aid in this discovery. Because Cirq is focused
on NISQ computers and not on quantum error
corrected computers, we made some choices
that we believe are important for these
near-term devices. As an example,
one choice we made is that we believe
that the programmer who is coding for NISQ
algorithms needs to be very aware of the
idiosyncrasies of the hardware upon which the quantum
computation is run. Hardware is not
abstracted away in Cirq. In Cirq, this is captured
by device objects. Here is the device object
for our Bristlecone device. Printed out, it gives
a representation of the layout of the
qubits on the device. We see that it is a
strange grid of qubits. The qubits are
represented by pluses. The lines between the
qubits represents the fact that only adjacent qubits can be
subjected to a two qubit gate. For example, we can
perform a two qubit gate between these
qubits, but not these, which are too far
apart to directly interact. Another subtlety of
the Bristlecone device is that there are
important constraints on when you can simultaneously
perform two qubit gates. If you apply a two qubit
gate to two adjacent qubits, then you cannot simultaneously
apply a two qubit gate to any of the adjacent qubits
of this two qubit gate. Because the hardware isn’t
abstracted away in Cirq, we can use the device
objects directly when building our
quantum program to enforce these constraints. For example, here we try to
perform two two-qubit z gates at the same time
on adjacent qubits. But because we had passed in the
device object to the circuit, it is aware of the
Bristlecone constraint. And when we print
out the circuit, we see that the circuit has
correctly moved one of the cz’s to a later time slice
in order to avoid violating the constraint. Cirq is an open
source project license under the Apache 2 license. If you want to install the
latest release of Cirq, you can simply run
“pip install cirq” in most properly
configured environments for running Python. Cirq is an alpha release. That is, it is under
constant and active change. We welcome contributions. To do this, you can go
to Cirq’s GitHub repo, and follow the instructions
for contributing. The GitHub repo
also contains links to further
documentation for Cirq. I’m excited by the next few
years of quantum computers. Are there NISQ algorithms
that can perform problems of practical importance? Cirq is a tool we
are using to help explore this exciting question. We hope that you’ve enjoyed
this brief introduction to programming a NISQ computer. For more information about
Google’s efforts in quantum computing, I encourage
you to check out Google’s Quantum page.

29 thoughts to “Programming a quantum computer with Cirq (QuantumCasts)”

  1. At 4:01 Dave states that the Controlled Not gate is shown as containing an "amersand symbol", when the diagram displayed contains an @ (at sign) not an ampersand (&).

  2. Ah, quantum computers; the pursuit of adding more hardware to correct the errors that are generated by the hardware before the hardware outputs random results depending on how the hardware feels at the moment, that then have to be quantified by the billions to see which of the possible results were created the most so that we may assume it is the most probable correct answer. I do not want to dismiss quantum computers altogether, but I have yet to see anyone show a single example of a problem that a quantum computer has solved that could easily be solve by a normal computer, let alone a problem that a normal computer could not possibly solve.

  3. After one or two years the youtube tutorials will be like : the final video in the course , how to print "Hello world" 😴

  4. Just saw the presentation by Mr. Bacon at TQC-NIST conference.
    Awesome talk. Very grounded on the near term outlook. But optimistic nonetheless. Congrats 👏👍

  5. Tensorflow for artificial intelligence using python…
    Now Google released cirq python framework for quantum computing…

Leave a Reply

Your email address will not be published. Required fields are marked *