A quantum superposition of a tiger and a bear

Dr James Wootton
Qiskit
Published in
5 min readMay 3, 2018

--

Here is a picture of a tiger and a bear overlaid on to one another. Though there are many ways one might try to achieve this effect, I used a rather exotic one: I created a quantum superposition of them on a quantum computer.

Before we get onto what quantum computers are, let’s have a quick primer on the more familiar ones. Normal computers are built of bits: tiny chunks of information that can take the value 0or 1.

Bits can also be combined to make bit strings, like 0001 or 0010. These are a powerful way to encode pretty much any information. The simplest example is using them for numbers: 1 is 1, 10 is 2, 100 is 4 and so on for all the powers of 2 and everything in between.

Quantum computers are instead made of qubits. Like bits, these can take the values 0and 1, and we can combine them to make strings too. If we wanted, we could just use qubits as an alternative type of bit.

This would be a pretty expensive thing to do, as qubits need a lot more care and attention than bits. But since IBM offers prototype quantum processors for free on the cloud, it is not us that will have to pay the expense.

So let’s write some things with qubits!

The easiest thing to write are numbers, but they are a bit boring. So let’s go for text instead. The ASCII standard provides a way of assigning strings of letters, numbers and punctuation into strings of bits. This means we can use IBM’s 16 qubit cloud device to encode some emoticons.

Here’s a couple of emoticon bit strings we could use.

;) = 00111011 00101001
8) = 00111000 00101001

We are obviously not getting the full advantages of qubits when we just use them for emoticons. This comes not from how we encode information, but how we manipulate it. Rather than being restricted to the standard logic gates at the heart of normal computers, we can do more intricate quantum operations as well.

In some sense, these operations can allow a qubit to be both 0 and 1 at once: a quantum superposition. Quantum computers can then use these superpositions to create interference effects, just as we see when waves superpose. These effects can then be harnessed in our quantum programs, allowing us to find shorter routes between input and output.

But if we go back to just messing around with emoticons, we can use this functionality to create a superposition of ;) and 8).

When we do this, we extract the output directly from the superposition. Because of this, we don’t see any of the subtlety of the interference. Instead, it just serves as a generator of random bit strings for ;) and 8). These random outputs, combined with Matplotlib, can then be used to construct an image to represent the superposition.

Now let’s use the same principle, but do something more complex than just emoticons. Let’s superpose photos!

To do this, we need to give the photos a binary encoding. For a given set of binary strings, we assign each a certain image. This basically just means that we’ll take a bunch of image files, and give them binary strings as file names.

I chose to use a bunch of pictures of animals from Wikimedia Commons. With simple (but not too simple) strings of four bits, we can have 16 different images.

Now all we need to do is choose two images to superpose. For example, I went for 0010 (the bear) and 0001 (the tiger). Once this choice is made, we know which bit strings we need to create a quantum superposition of.

Creating the superposition requires us to tell some qubits what to do. For that we need a quantum program. We’ll also need to send it to a quantum processor, because that’s where qubits live. Fortunately, neither of these things are as scary as they sound!

Most of the programming is already set up for you in a Jupyter notebook. This sets up the job and sends it to one of IBM’s quantum devices, using the QISKit quantum SDK.

The result should, ideally, spit the two chosen results out with 50/50 probability. But rather than just rely on the maths to predict what the quantum computer will do, let’s actually make one do it. We’ll run the program many times and use the results to estimate the probabilities. These will then be used to mix the images together in a weighted average, with the strength of each image given by the probability of its filename.

The only part missing from the notebook is the most important part: setting up the superposition. This is the quantum heart of the program, and it is the part that you’ll need to change if you want to superpose a different pair of images. But don’t worry, I made a game help you through it.

The image superposer mode of this game will let you choose the file names, and lead you though the process of superposing them.

With this, I wrote the code snippet needed to create my tiger and bear superposition. Then I used the Jupyter notebook to send the job to a real quantum device. And in the end, I got an image.

Half tiger and half bear, or thereabouts. Due to noise in current quantum devices, there are also slight traces of other animals. These arise because the quantum computer occasionally spits out their file names in error. Most prominent is a rhino, whose horn can be seen just above the bear’s right paw.

Now you have all you need to create your own quantum art. If you don’t like the images I chose, just find 16 of your own and give them the binary filenames instead. But if you send your sweetheart a quantum superposition of you together, beware of the photobombs caused by quantum noise!

--

--

Dr James Wootton
Qiskit

Helping to make quantum computers IBM Research . Occasionally misusing them for fun and/or science. Two Ts and no Es. All nonsense here is my own doing