A Brief Introduction of Quantum Computing with Qiskit (Part 1)

Kaushal Gagan
13 min readDec 6, 2021

--

The story of Quantum Computing starts with a young man looking for answers to a puzzle. This puzzle is alive and elegant. It travels across space, and time often meets those who can not ignore its existence.

The Puzzle: “ How Everything Works?

weeklystandard.com

Richard Phillips Feynman was trying to find the answer to a variant of the puzzle.

Variant: “How subatomic world works, or can we create one inside the world we have created(i.e., inside a computer)?

More precisely, variant asked him- “can you simulate a Quantum System into your computer?”

Quantum system: A system of fundamental/subatomic particles is known as a Quantum System.

Feynman found that this problem can not be solved with classical computers to solve this problem. He published a paper in 1982 titled “simulating physics with computers.” He pointed out that if we want to solve the problem of nature, we will need a computer that operates on the laws of quantum mechanics.

...nature isn’t classical, dammit, and if you want to make a simulation of nature, you’d better make it quantum mechanical, and by golly it’s a wonderful problem, because it doesn’t look so easy...

Same time, Benioff and Menin were working on the same ideas. All these efforts lead to the current state of Quantum Computing.
As we go ahead in this series, we will see many great works of this field that will help us better understand this universe.
Now let us start the journey to the Quantum Realm.

Table of Content:

Part - 1
0. A brief Introduction to the Postulates of Quantum Mechanics(QM)
1. Bits and Qubits
2. Properties of Qubit
a. Quantum Superposition
b. Quantum Entanglement
3. Operations on bits
4. Operations on Qubits
a. Single Qubit Gates
b. Multiple Qubit Gates
5. Bloch Sphere and Oracle
Part - 2
6. Maths for QC people
a. Tensors
b. Operations on Matrix(norms to tensor product)
c. Matrix as Operators
d. Hilbert space
Part - 3(Releasing on 15 Jan 2022)
7. Algorithms
a. Groover's Search
b. Deutsch-Jozsa Algorithm
c. Shor's Algorithm
d. The Bernstein-Vazirani Algorithm
Part - 4(Releasing on 25 Jan 2022)
8. Feel good topics
a. Superdense Coding
b. Quantum Cryptography
c. many more

0. A brief Introduction to the Postulates of QM

Postulate 1: you exist in Hilbert Space.

More precisely Postulate 1 says:

Any Isolated Physical System is a complex vector space with inner product(i.e., Hilbert Space) known as state space of the system. 
A unit vector completely describes the system into the state space known as state vector( denoted by ψ).
Suggestion: Please revisit section 0 after section 7.

Postulate 2: Evolution of you will be described by U(unitary operator)

More precisely Postulate 2 says:

A unitary transformation(U) describes the evolution of a closed system.
Let at time t1 state of the system is represented by ψ1 later system becomes ψ2 at time t2 then ψ1 and ψ2 are related by a Unitary operator U given by the expression 1(exp1),
(1)

Schrodinger's equation is an example of postulate 2,

(2)

Postulate 3:

A collection of measurement operators describes quantum measurements. For each possible outcome m there will be a measurement operator Mm.

probability of measuring a possible outcome m will be p(m),

(3)

Postulate 4:

The state-space of a composite physical system is the tensor product of the state space of the component physical system.

Note:

1. Bits and Qubits

Bits are the smallest unit of information that we all use in our classical computers. One bit stores either 0 or 1.

Matrix Representation for Bits:

Similarly, Qubits are the smallest unit of Quantum Information. One qubit can store 0 and 1 at the same time.

Note: Bloch Spare is used to visualize a Qubit. (sec -5)
https://thumbs.gfycat.com/BrokenSizzlingGuppy-size_restricted.gif

Now the question is, what happens when we observe the qubit? Will we be able to see both 0 and 1 simultaneously?
The answer is NO. We will get either 0 or 1 at the end of the observation.
Then what does it mean to have 0 and 1 simultaneously in qubit?
To answer this question, we will do a simple thought experiment.
Imagine we have 100 identical black boxes. Each box contains a mysterious coin that spins at the bottom of the box, and once we open the box, it stops spinning.
Suppose we have opened the first box, the coin falls. The result was that the head similarly observed all 100 boxes and noted the observation. As we know, the probability of getting a head or tail for an unbiased coin is 0.5.
So, we will observe that almost 50 times we get Heads and 50 (almost 50 times) Tails. Now, if I ask you what was inside every box? Head or Tail?
This question does not make any sense. We can say it contains both Heads and tails with a probability of 0.5.

Matrix Representation for Qubit:

Here α and β are directly related to the probability of getting 0 and 1 respectively after observation.

Extra Point:(OPTIONAL for now)

Probability that after measuring ψ can be found in state |x> is,

for example let’s calculate the probability of getting state |0>,

1. Properties of Qubit

A. Quantum superposition

Quantum systems can live in more than one state simultaneously.
This property is known as quantum superposition.
https://thumbs.gfycat.com/

This property explains:

  1. How qubits can have both {0,1} values at the same time.
  2. How Quantum Computers can take advantage of quantum parallelism.
Quantum parallelism lets Quantum computers evaluate multiple function values at once.
Note: In part-2, we will discuss this topic in more detail in Deutsch-Jozsa Algorithm.

3. How 300 qubits can represent states more than the number of particles in our universe.

The diagram below explains the exponential relation between the number of qubits states.

serokell.io

B. Quantum Entanglement

Quantum entanglement is a physical phenomenon that occurs when a group of particles are generated, interact, or share spatial proximity in a way such that the quantum state of each particle of the group cannot be described independently of the state of the others, including when a large distance separates the particles.
https://thumbs.gfycat.com/

Responsible for:

  1. Superdense coding
  2. Information transfers faster than light.
  3. The problem of non-locality.

Extra point: Let’s see how to create two entangled qubits,

here two qubits q0 and q1 are in state |0>, so the composite state for input will be |0>⊗|0> =|00>. After measuring the result of the circuit 1000 times output histogram will look like this diagram given below.

The diagram tells us that half of the time, we are getting the output in |00>, and half of the time, it shows |11>.
It means that if we measure output for q0, it will be sufficient information about the measurement result for qubit q1.
In the upcoming part of this series we will have a detailed discussion on bell states and superdense coding to understand this topic and its applications.
Here is code for this extra point,

3. Operations on Bits

Operation is nothing but transforming the state of bits to perform computation on your device.
There are 4 Logical operations on Bits.
Gates are used to performing those logical operations. We have four basic gates and one Universal gate, known as the NAND gate for a classical bit.

Note: Bits and operations can be represented by matrices.(Part 2)

The convention left side is the input side where the target bit enters a gate. The gate manipulates/performs logical operations, and the modified bit exits from the right side as output.

NOT GATE:

http://clarvis.co.uk/

OR GATE:

http://clarvis.co.uk/

AND GATE:

XOR GATE:

http://clarvis.co.uk/
http://clarvis.co.uk/

NAND GATE:

NAND Gate is a universal gate. Any other logical operation on bits can be performed with a collection of NAND Gate.

http://hyperphysics.phy-astr.gsu.edu/

Without these gates, we can not create classical computation devices similarly. There exist quantum gates to perform quantum computations.

4. Operations on Qubit/Quantum Gates

As we have seen bit manipulation with the help of Logical operation to perform classical computation.

Note: Qubits and operations can be represented by matrices.(Part 2)
https://thumbs.gfycat.com/

To represent a Gate we use a square box with input, output wires and name of the gate on square.

Single Qubit Gates

Gate which takes one qubit as input.

Note: All single qubit gates are part of more general gate known as general rotation gate (U-gate).

Hadamard Gate:

Hadamard gate is takes a Qubit and returns superposition state as output.

Matrix Representation:

Qiskit Implementation:

Visualization will look like:

to plot histogram for Hadamard gate,

Results:

Pauli Matrices: X, Y and ,Z

Pauli-X Gate : It is similar to NOT Gate, Which rotates state vector about x-axis by π.

Table of Contents (gatech.edu)

Matrix Representation for Pauli X:

Qiskit Implementation:

Visualization Result:

Pauli-Y Gate: It Rotates State vector about Y-axis by π.

Table of Contents (gatech.edu)

Matrix Representation for Pauli Y:

Qiskit Implementation:

Visualization Result:

Pauli-Z Gate: It Rotates State vector about Z-axis by π.

Table of Contents (gatech.edu)

Matrix Representation for Pauli Z:

Qiskit Implementation:

Visualization Result:

State vector is along Z-axis, Colour is associated with phase and in this case only phase of the qubit |0> changes which you can notice that colour changes from red to blue.

Multiple Qubit Gates

CNOT: Takes two qubits as input, Also Known as Controlled NOT gate where one qubit acts as a control, and other is target qubit.

Table of Contents (gatech.edu)

Here black dot wire is control wire currently (in above diagram) control qubit is in superposition which means when it passes through black dot it will collapse in either |0> or |1> state.
Wire with this ⊕ symbol contains target qubit, will act as not gate on the target (i.e., |0>) whenever control qubit is in state |1> otherwise no change will be observed on target qubit if control qubit turns out to be in |0> state.

Matrix Representation for CNOT:

Extra Point(Optional):

Suggestion: Do not worry if things written here are not making sense for now. after reading part-2(sec-6). It will make perfect sense.

Let’s take an example of how it works. In the diagram shown above, we have a target qubit in state |0>, now suppose control qubit turns out to be in state |1>.
So in the input state, we have |1>(control) and |0>(target), then
the composite input state will be the tensor product of |1> and |0>. (postulate 4)

now let’s apply CNOT matrix to|10> input state,

here we get the result as |11> = |1> ⊗ |1> = (control ) ⊗ (target qubit) which means our target qubit is now in state |1>.

Qiskit Implementation:

Result:

SWAP:

The swap gate has two input and two output wires. As its name suggests, it swaps the qubit state of the input wire.

Qiskit Implementation:

Code result:

CCNOT/Toffoli gate:

CCNOT is similar to CNOT gate. It has two control wires and one target wire. This means the target qubit state will flip only if the control qubits are in|1> state.

Note: Toffoli gate is one of the two universal gates in QC. Another universal gate is the Fredkin gate.

Qiskit Implementation:

Code Result:

Other gates

Phase Gate:

Pauli Z gate is a special case of Phase gate(at ϕ = π). Rotation about Z-axis results in a change in phase of the qubit’s state.

Also, I(Identity), S(Z^(1/2) gate), and T(Z^(1/4) gate) gates are special cases of phase gate at ϕ =0, π/2, and π/4 respectively.

Matrix Representation for U gate:

Qiskit Implementation:

General Rotation gate/U-gate:

Every single qubit gates are special cases of U gate.

Matrix Representation for U gate:

e.g. Let’s see how we can derive Hadamard gate from U gate.

Qiskit Implementation: This implementation shows how you can derive Hadamard gate from U gate.

Code Result:

Task: Compare this result with Hadamard gate result.

5. Bloch sphere

The state of a single Qubit can be visualized with the help of a unit vector in 3D space. Any qubit state starts at the origin and ends at the surface of a unit sphere.

The Sphere is known as Bloch Sphere.

Bloch Sphere

θ is the angle between state vector |ψ> and Z-axis where ϕ is the angle between a projection of |ψ> and X-axis. ϕ is important while creating a quantum algorithm even we can not measure it directly.

e^iγ is a global phase and has no observable effect, so we ignore this term from the above equation. Why?

To understand why we ignore the global phase, let’s understand what happens to a vector when we apply multiplication with e^iγ in complex (suggestion: 2:00)

Grant Sanderson(3Blue1brown)

This means multiplication of the global phase is related to the rotation of the Bloch sphere itself in some frame of reference, which we assume as global.
In the end, the probability of getting state |0> or |1> remains unaffected by the change in the global phase, so we can ignore e^iγ from the above equation.

now,

Note: Bloch sphere visualization is limited to a visualize only single-qubit state. There is no simple generalization to visualize multiple qubits system.

Here is a simple console to visualize the effects of simple gates on a qubit,

Vis — Replit

If you are reading this line, I wanted to say you are fantastic! Thanks for your time. stay curious and stay tuned for upcoming parts of this series(here is part2)

References:

  1. Quantum Computation and Quantum Information —Nielsen,Chuang
  2. Quantum Computing for Computer Scientists — Noson, Mirco
  3. Quantum Computing an applied approach — Jack D. Hidary
  4. Quantum Katas #1: Basic Quantum Gates :: Gideon Wolfe
  5. https://qiskit.org/textbook/ch-states/single-qubit-gates.html
  6. https://www.youtube.com/watch?v=nejFfcXumjM
  7. https://www.youtube.com/watch?v=O85OWBJ2ayo

--

--

Kaushal Gagan

Qiskit Advocate | IIT Goa | Writes about Quantum * , Computer Science, Philosophy, Cryptography ,and More.