Making a quantum computer smile

A simple example of how to play with a quantum computer

Dr James Wootton
Published in
3 min readNov 2, 2017


We are going to make a simple quantum program. Let’s start with the classic example of a simple program on a normal computer: Hello, World!

print("Hello, World!")

The computer takes the input Hello, World! and makes it appear on screen. It does that like it does everything: by manipulating lots of 0s and 1s. So at some point in the program, Hello, World! will be turned into the following binary string.

01001000 01100101 01101100 01101100 01101111 0101100 0100000 01010111 01101111 01110010 01101100 01100100 0100001

This is the binary representation of the text using the ASCII encoding. It needs a lot of bits for a simple message. Over 100, in fact!

Now suppose we want to do Hello, World! on a quantum computer, and so using qubits. These can act just like bits, but also have extra quantum tricks.

Since a quantum computer can do everything a normal one can, we could just run the same program. The 104 required bits would be encoded using 104 qubits.

Unfortunately, quantum computers with that many qubits don’t currently exist. Running such a normal, boring program would also not use any of the quantum fanciness.

So what should we do? Well for one thing, we could shorten our message. Using just two characters would need only 16 bits. Since IBM have a device with 16 qubits, encoding this would not be a problem. Let’s go with 0011101100101001, which you probably know as ;)

Now let’s add some quantumness. Rather than just have a single emoticon, we could make a quantum superposition of two. This would be easiest if their binary strings don’t differ too much, and so we’ll go for an often overlooked smiley: 8)

;) = 00111011 00101001
8) = 00111000 00101001

These both agree that bits 1, 2, 6, 9, 10, 12, 14 and 15 should be 0, and also agree that bits 3, 4, 5, 11, 13 and 16 should be 1. This means that these qubits will just be set to these normal, boring values.

Its on qubits 7 and 8 where the magic happens. For a superposition of ;) and 8), these qubits must be made to be both 0 and both 1 at the same time. This is what we call an entangled state. In fact, it’s an entangled state that can be used to prove something that Einstein thought was impossible: the non-locality of quantum mechanics.

To program this, I used QISKit, an SDK for quantum computing. This let’s me interface through the cloud with IBM’s prototype 16 qubit quantum computer.

I encoded the superposition of ;) and 8) and then read it out. If you want the details, check out the source code here. Or you can also see the quantum circuit using IBM’s quantum experience here.

Each time the program is run, it’s like opening the box of Schrödinger’s cat.

Before readout, the device held both ;) and 8) at the same time. Once we look, it has to randomly choose one or the other. So we repeat many times, and look at how often each result occurs.

Current quantum devices are prototypes, and so are a bit noisy. This means there is a probability that errors messed with our qubits and we’ll read out something entirely different, like :(

To represent the result in a human readable way, I superimposed all the results on top of each other. The more a particular result occurred, the stronger they appeared. Here is the result.

I took one of the most advanced pieces of tech in the world. Which is also one of the coldest things in the whole universe. And I used it to superpose two smileys. That’s the fun of quantum programming.



Dr James Wootton
Writer for

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