The Bits and Atoms of Quantum Computing

Arunesh Sarker
9 min readAug 17, 2020

--

This is how a quantum computer looks like

With the advent of Star Wars movie series, we all have started believing that someday, concepts like teleportation, intergalactic travel, etc. will exist. Thinking of teleportation, we remember that during 1980s, a term coined as Quantum Teleportation became very popular, and people started believing that communication can be made possible faster than speed of light someday. So today, let’s discuss the bits and atoms of one of the most fancy technologies of the 21st century “Quantum Computing” and see how much truth is hidden in such science fiction. If this already sounds interesting, then I bet that by the end of this article, you will become familiar with some of the basic terminologies and concepts of Quantum Computing.

There are a million billion questions in people’s mind, how quantum computing will be beneficial to the world, what shall we get with such a huge investment (yeah building quantum computers are real pain), will it replace classical computers, etc. Google AI Quantum has recently announced that they have demonstrated Quantum Supremacy by completing a task in 200 seconds, which would have taken thousands of years on the most powerful supercomputers in the world today. This was achieved with their most powerful quantum processor, also known as the Sycamore processor, which is comprised of a whooping 54 qubits (“Quantum” bits). So let’s see what quantum computing is, and how do they work.

Silicon chips in a smartphone

The key fundamental difference that separates a quantum computer from a classical computer is the way in which information is stored and processed. A classical computer stores information in the form of bits, which can either be 0 or 1. A quantum computer stores information in the form of a qubit. We won’t discuss how physical qubit systems are made in this article, that is beyond our scope right now. But before telling more about qubits, let’s introduce a bit of mathematics.

Paul Dirac introduced us the bra-ket notation, which is an easy way of writing vectors. There are two primary states in quantum mechanics, which are called the state |0> and the state |1>. If you don’t get what this weird “|>” thing is, it is just a way of writing column vectors like this

Qubit states 0 and 1
Qubit states 0 and 1

These vectors are also called orthonormal basis, which means that the magnitude of the vectors is equal to 1, and the dot-product of the two vectors is 0.

A set of orthonormal basis vectors describe a new dimension. If there are two orthonormal basis vectors, they describe two dimensions. This means that any two-dimensional vector can be written as a linear combination of the orthonormal basis. As a quick exercise, take any two dimensional vector, like [2 1] (sorry I cannot write it vertically on Medium, but you get that the vector will be vertical ;), and write it as a combination of |0> and |1>. It will look something like a|0> + b|1>, where a and b are two constants. Try to find out the constants. What this means is that, you cannot write one orthonormal basis vector in terms of the other. Then these vectors are called linearly independent. These are also called computational basis states.

A qubit can be represented in the form

Representation of a qubit in the basis states
Representation of a qubit in the basis states

One thing to notice here is that the constants a and b we are talking about can be real, imaginary or both. (If you are new to imaginary numbers, read here). These are also called complex numbers, numbers which can be imaginary, real or both.

This vector, |q0> is called the qubit’s statevector, it tells us everything we could possibly know about this qubit. For now, we just need to understand that this qubit is neither completely in state |0> nor in state |1>, but a linear combination of both. Such linear combination of orthonormal basis vectors is termed as “superposition”.

Let’s introduce one more term, “amplitude”. Amplitude denotes the coefficient before the orthonormal basis vectors that we use to write our statevector. So, for the general case a|0> + b|1>, a is the amplitude of |0> state, whereas b is the amplitude of |1> state.

There is also a constraint associated with the amplitudes of the statevector. The “sum of square of modulus of amplitudes of a statevector should be equal to 1”. I know there’s a lot to unpack in this statement, but what it basically means is that

|a|²+|b|²=1, as simple as it can get.

This is called “normalzation”, and it basically means that the “every vector must have unit length”.

So a brief summary till now. We have introduced “kets” as a new notation to represent vectors. We have seen how any vector can be represented as a linear combination of orthonormal basis vector states, the representation being called a “statevector”, and the term used to describe this phenomenon is called “superposition”. We have also seen the “normalization” constraint, which limits the length of every vector defined to unity.

Phew!!! That was a lot of maths. So let’s do some hands-on coding with IBM Qiskit. Qiskit is IBM’s open source SDK for working with quantum computers at the level of pulses, circuits and algorithms. Qiskit accelerates the development of quantum applications by providing the complete set of tools needed for interacting with quantum systems and simulators. If you want to install Qiskit, check all the various options for installing and running Qiskit here.

Picture of a laptop
Open up Qiskit on your PC

Open up Jupyter notebook on your PC. To run a cell, press Shift+Enter. In the first cell, type the following. These will import all the necessary tools required for this lab exercise.

from qiskit import QuantumCircuit, execute, Aer
from qiskit.visualization import plot_histogram, plot_bloch_vector
from math import sqrt, pi

We will use QuantumCircuit to create a new circuit. We generally pass two numbers to it, first one represents the number of qubits we need in our circuit, and second one is the number of “classical” bits to take measurement (we will come to what is measurement later). For now, we will just initialise our circuit with just one qubit as follows

qc = QuantumCircuit(1) # Create a quantum circuit with one qubit

Remember that just as we initialise our Quantum Circuit, the qubits start in the state |0>. This is just a default to make further calculations easier. But Qiskit provides us the flexibility to initialise our qubits with any numbers we want. This can be done using the initialize() method. We pass a list of numbers and tell which qubit we want to initialise. List is a python data structure.

Important: The list of numbers you pass as an argument to initialize() method should follow the “Normalization” rule.

Okay, in the next cell, we initialize our qubit to the |1> state in the following way

qc = QuantumCircuit(1)  # Create a quantum circuit with one qubit
initial_state = [0,1] # Define initial_state as |1>
qc.initialize(initial_state, 0) # Apply initialisation operation to the 0th qubit
qc.draw('text') # Let's view our circuit (text drawing is required for the 'Initialize' gate due to a known bug in qiskit)

If you initialize your qubit that does not follow the normalization rule, something like this

vector = [1,1]
qc.initialize(vector, 0)

You will get an error on running this cell as

QiskitError                               Traceback (most recent call last)
<ipython-input-12-ddc73828b990> in <module>
1 vector = [1,1]
----> 2 qc.initialize(vector, 0)

/usr/local/anaconda3/lib/python3.7/site-packages/qiskit/extensions/quantum_initializer/initializer.py in initialize(self, params, qubits)
252 if not isinstance(qubits, list):
253 qubits = [qubits]
--> 254 return self.append(Initialize(params), qubits)
255
256

/usr/local/anaconda3/lib/python3.7/site-packages/qiskit/extensions/quantum_initializer/initializer.py in __init__(self, params)
56 if not math.isclose(sum(np.absolute(params) ** 2), 1.0,
57 abs_tol=_EPS):
---> 58 raise QiskitError("Sum of amplitudes-squared does not equal one.")
59
60 num_qubits = int(num_qubits)

QiskitError: 'Sum of amplitudes-squared does not equal one.

To get the resulting statevector after performing such an operation of a qubit, we will use Qiskit’s “statevector_simulator”. There are other simulators as well, but more on that later.

backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit

Then we will use execute to run our circuit, and the .result() to get our required statevector.

qc = QuantumCircuit(1) # Create a quantum circuit with one qubit
initial_state = [0,1] # Define initial_state as |1>
qc.initialize(initial_state, 0) # Apply initialisation operation to the 0th qubit
result = execute(qc,backend).result() # Do the simulation, returning the result

from result, we can then get the final statevector using .get_statevector()

qc = QuantumCircuit(1) # Create a quantum circuit with one qubit
initial_state = [0,1] # Define initial_state as |1>
qc.initialize(initial_state, 0) # Apply initialisation operation to the 0th qubit
result = execute(qc,backend).result() # Do the simulation, returning the result
out_state = result.get_statevector()
print(out_state) # Display the output state vector
[0.+0.j 1.+0.j]

Note that j here is used to represent imaginary numbers.

Congratulations on implementing your first quantum circuit. Although it is of not much importance, but we have built our fundamental quantum circuit. We will build upon this as the blog series will continue.

We are left with one last concept in this article, which is “measurement”.

Picture of cathode ray oscilloscope
Let’s take some measurement

Before speaking anything about measurement, let me introduce you a small topic, called the “inner product”. This is a generalisation of the vector dot product. We use the inner product between a bra-(row-vector) and a ket-(column vector) like this

Inner product (bra-ket)
Inner product (bra-ket)

The asterisk(*) above a number denotes “complex conjugate” of that number. If a complex number is written as a+jb, its complex conjugate will be a-jb.

A very important rule for measurement

Rule of measurement
Rule of measurement

If you brush up a little maths of linear algebra, then you will realise that if we write any quantum state as |x> = a|0> + b|1>, then the probability of measuring state |x> as |0> is |a|², and that of |1> is |b|². Try to do this by taking |x> as |0> and |1>, and ⍦ as some “a|0> + b|1>”.

Wait, we just found out the famous Born rule. It says that the probability of finding a quantum state in another given quantum state is just the square of modulus of inner product of the two states.

Let’s check this using Qiskit’s statevector_simulator. First we will initialise our qubit like this

qc = QuantumCircuit(1) # Redefine qc
initial_state = [0.+1.j/sqrt(2),1/sqrt(2)+0.j]
qc.initialize(initial_state, 0)
qc.draw('mpl')

This should initialize our qubit as

Initialize qubit state

To verify this, let’s use our statevector_simulator.

state = execute(qc, backend).result().get_statevector()
print("Qubit State = " + str(state))

Finally, let’s measure this qubit

qc.measure_all()
qc.draw('mpl')

Now, let’s simulate the circuit and get our measured state

state = execute(qc, backend).result().get_statevector()
print("State of Measured Qubit = " + str(state))

You will always get result as

State of Measured Qubit = [0.+0.j 1.+0.j]#ORState of Measured Qubit = [1.+0.j 0.+0.j]

Phew!!!!! That was a lot to take in one article. Today we have seen terms like “qubit”, “state-vectors”, “superposition”, “normalisation”, “Born Rule” and many more. These are all just the fundamentals of quantum computing. There are many more fundamentals, but we shall cover them in the next article. I’ve tried to simplify concepts as much as possible. Also, check out the links that I’ve attached with this article, they are super useful and will give you a complete picture about what I’m referring to.

PSST: Most of my work here is inspired from Qiskit’s community textbook, which is an awesome resource to learn from. If you want to check that out, it is linked here. You can give it a read, or maybe download the Jupyter notebook and run on your local machine. Both works fine. One additional thing that’s mentioned there is about the Bloch Sphere, and I could have mentioned that here also. But it would be a lot to take in this article. I will do it in the next article, along with some cool stuff like Quantum Teleportation.

So it is still not clear to us whether communication can be done faster than speed of light. Just to break the ice, I will say the answer here. But that shouldn’t stop you guys from reading the next article on Quantum Teleportation, as it will discuss the process in details.

Till then, happy Quantum Computing.

Oh yeah, I forgot!!! We cannot communicate faster than speed of light. The Theory of Relativity formulated by Einstein is still very true even in the 21st century.

--

--