DEGREE PROJECT IN TECHNOLOGY,
FIRST CYCLE, 15 CREDITS
,
Simulating a Quantum
Computer
Grover's Search Algorithm with Error Correction
MARTIN SJÖBORG
HANNA LINN
KTH ROYAL INSTITUTE OF TECHNOLOGY
SCHOOL OF ENGINEERING SCIENCES
DEGREE PROJECT IN TEKNIK,
FIRST CYCLE, 15 CREDITS
,
Att simulera en kvantdator
Grovers sökalgoritm med felhantering
MARTIN SJÖBORG
HANNA LINN
KTH ROYAL INSTITUTE OF TECHNOLOGY
SKOLAN FÖR TEKNIKVETENSKAP
Abstract
Classical simulations of quantum computers give us an insight into various things such as what
quantum algorithms can achieve, whether it is possible to verify that they function as postulated,
the difficulties that have to be overcome before quantum computers can be realized, as well
as how we can handle these difficulties. We build a Python library to simulate a quantum
computer that can perform all quantum algorithms by defining an universal gate set, from
which all quantum gates – and thereby all circuits – can be constructed. We implement two
algorithms that both highlight two important aspects of quantum computing: Grover’s quantum
search algorithm, which demonstrates the efficiency of quantum algorithms and their superiority
over their classical counterparts by searching an unsorted list quadratically faster; and an error
correcting code, the Shor code, which highlights the cost of correcting the possible errors in a
quantum computer.
We test the rigidity of Grover’s algorithm by introducing errors without correction, and find
that the algorithm shows resilience to smaller 1-qubit Pauli errors, but looses its efficiency
under larger errors and thus the need for Pauli error correction arise.
Abstract
Klassiska simuleringar av kvantdatorer ger oss en inblick i vad kvantalgoritmer kan åstadkomma,
hur vi kan verifiera att algoritmerna fungerar, vilka problem vi måste lösa innan kvantdatorerna blir en verklighet, samt hur vi kanske kan hantera problemen. Vi bygger ett bibliotek i
Python för att simulera en kvantdator som kan utföra alla kvantalgoritmer genom att definiera en
grinduniversalmängd, ur vilken alla kvantgrindar – och därmed alla kretsar – kan konstrueras. Vi
implementar två algoritmer som båda belyser två viktiga aspekter hos kvantberäkning: Grover’s
kvantsökning, som demonstrerar effektiviteten hos kvantalgoritmer över deras klassiska analoger,
samt en felhanteringsalgoritm, Shorkoden, som kan jämka Paulifel och är betydelsefull för att
förstå vikten hos felkorrigering.
Vi prövar motståndskraften hos Grovers algoritm genom att utsätta den för slumpmässiga rotationer hos en qubit, och finner att algoritmen är resistent mot mindre Paulifel, men snabbt
slutar producera meningsfulla resultat vid större Paulifel.
Contents
1 Introduction
1.1 Qubits: Superposition & Entanglement . . . . . . . . . . . . . . . . . . . . . . .
1.2 Quantum Supremacy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Grover’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4 Error: Decoherence & Operational Inaccuracy . . . . . . . . . . . . . . . . . . .
1.5 Error Correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.6 Simulation of Quantum Computers . . . . . . . . . . . . . . . . . . . . . . . . .
2
3
4
4
5
5
5
2 Architecture of Our Quantum Computer
2.1 Quantum Gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Grover’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.1 The Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.2 Result Periodicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Error & Error Correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3.1 Defining the Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3.2 Error Correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
7
10
11
13
14
14
14
3 Simulation & Results
3.1 Simulation in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Grover’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Grover’s Algorithm with Error . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4 Error Correction Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5 Grover’s Algorithm with Error correction . . . . . . . . . . . . . . . . . . . . . .
18
18
19
20
20
21
4 Discussion
4.1 Simulation of a Quantum Computer . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Weakness in Grover’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3 Error & Correction Price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4 Coherence Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
23
23
24
24
5 Conclusion
26
1
Chapter 1
Introduction
In the early 1980’s, Yuri Manin and Richard
Feynman suggested that we might be able to
exploit the quantum effects in order to go beyond what the conventional computers can
do [Feynman, 1982]. Feynman mainly argued
that the complexity in the interaction between
particles could not be simulated without approximations and simplifications by a classical computer, and the computer that would be
able to do the information processing required
to make the simulation accurate would have
to operate in the world of quantum mechanics
itself. Manin broadened this statement by reversing Feynman’s argument, suggesting that
computers using quantum effects to do calculations would be considerably more powerful
than classical ones, surpassing todays computers and thereby achieving quantum supremacy,
explained in Sec. (1.2) [Manin, 1999]. The
quantum computers could be able to process
larger amounts of data with the use of quantum parallelism, and with a lower complexity due to quantum mechanical properties, explained in Sec. (1.1).
decoherence and error might be controlled.
One method being the use of error correction
codes, especially one developed by Peter Shor
[Mermin, 2016, Shor, 1995].
How the quantum computer is realized is
yet to be discovered, but we can anticipate
which elements that will be crucial by classically simulating the operations the quantum
computer would perform and even introduce
decoherence and errors. This can also foretell
what would be possible to do with a quantum
computer. More about this in Sec. (1.6).
Practical applications for quantum computing, if feasible, is a debated subject, but it is
clear that it will not be everyday tasks. The
two main applications are to:
1) simulate systems with complex
Schrödinger equations like chemical reactions or quantum interactions, and
2) speed up classical algorithms by inventing
a quantum analog.
The first topic is interesting because information processing of molecular systems with
modeling of chemical reactions and materials scales exponentially with the number of
atoms involved, rendering it impossible due
in part to multi-body couplings. The quantum simulation field promises a revolution in
areas such as drug design, material engineering, and elucidation of biochemical processes
[Wang et al., 2015].
The second topic concerns the quantum
applications of classical algorithms. Perhaps
the most interesting examples are Peter Shor’s
However, a bundle of technical hurdles
may be in the way of quantum computers as
we have yet not been able to construct the
hardware required for the quantum computers
to be practical. The quantum state is highly
sensitive to its surroundings, experiencing
decoherence, explained in Sec. (1.4). Furthermore, we have not yet found a way to control
and manipulate the quantum information efficiently without errors, outlined in Sec. (1.4).
There have been a number of theories and
published results on how the problem with
2
|0i
prime factorization algorithm [Shor, 1995],
Alexei Kitaev’s stabilizers of Abelian group
actions [Kitaev, 1997], and Lov Grover’s
search algorithm [Grover, 1996]. According to
Manin, these three algorithms demonstrated
a useful toolkit that has then been used
while searching for even greater algorithms.
These, at the time, new concepts have
boosted the field of quantum algorithms and
researchers have since then generalized them
[Manin, 1999].
0
1
(a) The
states.
|1i
two
bit
(b) A qubit superposition on the Bloch
sphere.
Figure 1.1: Bit representation in a) classical
systems, and b) quantum systems.
In this thesis, we focus on the implementation of Grover’s search algorithm, and the
benefits of the algorithm’s speedup in database
searching. This is outlined in Sec. (1.3). We
then discuss the problems with errors, decoherence and operation inaccuracy, and how
parts of the problems could be handled by
Shor’s error correcting code.
1.1
|0i+|1i
√
2
amplitude, |αi |2 , denotes the probability that
the system, when measured, is found in the
state with corresponding basis vector |ψi i. We
can in principle choose a non-binary quantum
system such as the energy levels of an atom
with n basis vectors and expand the theory beyond binary states, but this is unconventional
and complicated. Instead, consider the spin of
an electron with basis vectors |↑i and |↓i with
corresponding eigenvalues Sz = ±~/2 respectively. We can now translate the classical bit
state of 0 or 1 as the eigenvectors of Sz such
that
|↑i = |0i ,
|↓i = |1i .
(1.2)
Qubits: Superposition
& Entanglement
A classical computer works by manipulating
binary numbers composed of bits represented
by the charge stored in a capacitor, where the
state of the bit is either 0 or 1, whether charge
is stored or not. The quantum bit (qubit) can
be implemented as a two-state quantum system - e.g. the spin of an electron, polarization
of a photon or a trapped ion, or a nuclear magnetic moment [Mermin, 2016] - such that the
state of the system can be expressed as a superposition of each distinct state.
We get a state
|Ψi = α |0i + β |1i
if we have one qubit.
In a way, we have now replaced the classical
existence of capacitor charge with the quantum direction of electron spin along the z-axis.
We can picture this on the Bloch sphere, seen
in Fig. (1.1b). On the Bloch sphere, we can
represent the state as a two-component vector, with the complex coefficients αi from Eq.
(1.1).
Superposition
To express the superposition formally, we introduce the bra-ket notation, outlined below.
The quantum state of a system in superposition is defined as the normalized vector
X
|Ψi =
αi |ψi i
(1.1)
Register
i
Just as in a classical computer, we are interested in forming a register, which in our
case translates to collecting the state of each
such that |ψi i forms a complete orthogonal set
in Hilbert space, and the square of the complex
3
qubit into a quantum system with an associated wave function. This means that a register
with n qubits is described by a quantum state
in 2n Hilbert space. For simplicity, we define
the state of the system where all qubits are in
the state |0i as the n-fold Kronecker product
of the n states in Eq. (1.3). The superscripts
denote the qubit, but can be omitted if we keep
track of the order which the states appear in
the ket vector
A measurement of one of the particles would
lead to the other one choosing a state, and
thereby being measured too, causing the superposition to collapse. This holds even if the
particles are parted by a great distance, Albert Einstein called this "Spooky action at a
distance".
00 ⊗ 01 ⊗ . . . ⊗ 0n−1 = 00 01 . . . 0n−1
Not surprisingly, the goal of the field of quantum computing is to perform tasks quicker
than, or even tasks that are outright unfeasible
to simulate on, classical supercomputers. A
quantum search algorithm is a good and simple example of the former, whereas a factoring
algorithm is more complicated and an example of the latter. The set of all problems that
can be solved classically in polynomial time
N k for some k and where N is the size of the
problem, lies in the complexity class P, which
in turn is a subset of the class NP, in which a
solution can be readily verified in P. Searching an unordered list classically requires N/2
steps, and has a solution that is easily checked
(does the entry found match the search criterion?). The optimal quantum search algorithm
√ completes in a time that is polynomial
in N [Bennett et al., 1996], and one of possible applications of this is to offer enormous
aid in recognizing solutions to NP-complete
problems, due to the quadratic speed-up
from classical searching [Bennett et al., 1996,
Nielsen and Chuang, 2016].
= |0i⊗n .
1.2
(1.3)
For example: We describe the state of the
qubit register of qubits 0, in state |ψ 0 i =
α0 |0i + β0 |1i, and 1, in state |ψ 1 i = α1 |0i +
β1 |1i, with |Ψi to describe the whole register,
using bra-ket notation we get
|Ψi = ψ 0 ⊗ ψ 1
= (α0 |0i + β0 |1i) ⊗ (α1 |0i + β1 |1i)
= α0 β0 |00i + α0 β1 |01i
+ α1 β0 |10i + α1 β1 |11i .
(1.4)
Gates
Similar to classical computers we need operations, called gates, to alter the state of
the qubit, more about these and how they
have to differ from ordinary gate in Sec.
(2.1). We will use them to put the qubits in
superposition and entangling them.
Quantum Supremacy
Entanglement
1.3
Unlike classical bits the qubits will have the
property of entanglement. Quantum entanglement is a physical phenomenon that describes
when two or more particles interact with each
other leading to each of the particle’s state not
being possible to be described independently
of the other’s states. Thereby making it impossible to describe the single qubits in the
register with a single Kronecker product as depicted in Eq. (1.4), but a superposition of the
different product states: |00 01 . . . 0n−1 i.
Grover’s Algorithm
√
Requiring O( N ) steps, Grover’s search algorithm is the fastest possible quantum search
algorithm, and yet still relatively easy to implement. The ramifications of the quadratic
speed-up compared to classical search is not
only palpable in fields related to ordinary
database handling; the Grover algorithm has
also been modified neuronally to select optimal
responses in vital cell functions [Clark, 2014].
4
1.4
Error: Decoherence &
Operational Inaccuracy
the wave function from the superposition into
one certain state, rendering it to a Boolean
bit. We also have another kind of error that
the classic computer does not have: the phase
shift. In quantum systems we need to keep
the qubit in superposition and correcting for
the error without knowing the error. There
are many different ways to correct errors
in quantum memories, two common ones
are: back up reservoirs [Almlöf, 2016] and
correction algorithms [Mermin, 2016].
The quantum computers will be highly sensitive to small changes, caused either by disturbances from the outside or by defects in
the components of the hardware. More precisely the error could take place anywhere in
a quantum computer but especially in a vulnerable part, called a noisy part, which can be
in a long transportation channel, in a storage,
or in a certain gate. [Chiaverini et al., 2004,
Shor, 1995].
When performing the quantum algorithm in
real quantum computers we need the qubit
to be in a pure quantum state, thereby to
not be perturbed by the world around it, either by nearby qubits or by the outside of the
quantum computer. An interaction with its
surroundings, caused by thermal fluctuations,
quantum fluctuations, mechanical vibrations,
or other extraneous interactions, will entangle the qubit with some state in the environment. The entanglement will lead to an error by either just altering the superposition a
bit, changing the output of the quantum computer, or lead to a measurement of the qubit,
thereby destroying the superposition and reduce the qubit to a classical boolean bit making it impossible to perform operations on the
superposition. This change in the superposition is called decoherence. Decoherence may
be the one reason why quantum computers will
be difficult, if not impossible to build because
the totally isolated qubit may be unattainable. [Shor, 1995, Mermin, 2016] Another error could occur in the components: the qubits
or the gates, if they don’t do the desired operation exact.
1.5
We have chosen to focus on one algorithm
called the 9-qubit Error Correction Code, often referred to as the Shor Code (not to be confused with Shor’s Factorization Algorithm).
Shor suggested to make the system more robust by the use of ancillary qubits to "backup" the state of one qubit, called encoding,
before the possible error, so that the inverse
of the encoding, called decoding, could reconstruct the "no-error" state of the qubit by majority voting [Shor, 1995].
1.6
Simulation of Quantum
Computers
A large number of studies in simulating quantum computers has paved the way for more
accurate hardware research in the quantum
computer field. By determining what kind
of operations a quantum computer will have
to be able to perform and how many qubits
are required to achieve quantum supremacy,
together with anticipation of what obstacles
would be in the way, the simulations paint a
clearer picture of what the hardware will be.
Using a distributed high-performance simulator to model circuits with 42 qubits,
[Boixo et al., 2017] came to the conclusion
that quantum supremacy can be achieved
with only 50 super conducting qubits. Even
by their cutting edge technology, incorporating optimizations such as multi-threading,
they were still 8 qubits away to their proposed quantum supremacy of 50 qubits.
Error Correction
We will not be able to use classical error
correction codes, because if we did we would
have to measure the qubit to correct the right
error, and in doing so cause the collapse of
5
Using their in-house quantum computer,
[Bishop et al., 2017] at IBM have proposed a
formula showing the useful amount of work a
given quantum computer can perform. They
have quantified the implementation challenges
such as number of qubits and gate quality, and
their findings show that the hardware is bottlenecking performance.
The findings from both these research groups
indicates that, for the time being, quantum
simulations are heavily hampered by hardware. This shows that the simulations provide
useful direction to the field, even if the simulations per se can’t achieve a speed-up.
6
Chapter 2
Architecture of Our Quantum Computer
2.1
Quantum Gates
P h gates together with the controlled-U gate
cU , form a basis for
In order to manipulate the state of the qubit
and thereby to build algorithms, regular quantum operators are used in the form of gates.
Similar to the classical Boolean gates, the
quantum gates alters the state of the qubit,
but unlike classical Boolean logic, it is possible to rotate the state over three different spin
axes and change the phase. Another important distinction between Boolean and quantum gates is reversibility of the latter, which
only the NOT-gate possesses in the Boolean
set. The necessary condition of reversibility is
inherited from the time symmetry in quantum
mechanics. Thus, in order to represent a possible operation, all quantum gates need to be
unitary. As rotation and phase shift are transformations to other Hilbert spaces it is possible
to represent a quantum gate U as a matrix in
the basis corresponding to the Hilbert space.
The transformation have to be linear in order to take unit vectors into unit vectors and
also to ensure that the probability amplitude
is conserved,
U † U = I.
(2.1)
S = {Rx (α), Ry (β), Rz (γ), P h(δ), cU }. (2.2)
We can create any 1-bit unitary gate by combining the first four as
U = Rx (α) · Ry (β) · Rz (γ) · P h(δ),
(2.3)
and we can build any n-qubit circuit by including the cU -gate. The implementation of these
gates are discussed below. However, by adding
additional gates that can be built with the
gates in S, can we construct an over-complete
set S 0 , which is more common and simpler to
work with theoretically. In S 0 , we include the
Hadamard gate H, the Pauli gates X, Y, Z,
and the Toffoli gate.
We are now ready to visualize the qubit register, as shown in Fig. (2.1) This is read as the
|q 0 i
|q 1 i
U |q 0 i = |q̃ 0 i
|q 1 i
Figure 2.1
U
state of each qubit evolving from left to right.
In this case, we see qubits |q0 i and |q1 i starting
out in their own (independent) states |q0 i and
|q1 i respectively. An arbitrary gate U is then
applied to |q0 i, while |q1 i is left unaltered. The
resulting state of |q0 i is U |q0 i = |q˜0 i. U acting
in this way on the register can be expressed as
its action on the over the whole Hilbert space
with the Kronecker product from Eq. (1.3) as
We want to find a set of operators so that we
can preform all the necessary transformations
to do our calculations. If we have a set of a
finite number of gates, that can be combined
to perform all transformations, then building
a real quantum computer will be easier. This
set of gates is called a universal set S because
we are able to solely use gates in S to construct
possible circuits [Williams, 2011]. The set of
the three rotational gates R, and phase shift
U : q 0 q 1 7→ U 0 ⊗ I 1 q 0 q 1 = q̃ 0 q 1 . (2.4)
7
Where the subscript denotes which qubit the
gate acts on. The identity matrix I represents a "do-nothing" gate, since I |q 1 i = |q 1 i.
Combining gates acting on individual qubits
using the Kronecker product like this, we can
pick qubits to manipulate, and leave others unchanged. These 1-qubit gates act individually
on each qubit, so that an initial product state
will remain a product state after the operation. As an extension of this, we can also create gates operating over multiple qubits. Using Eq. (2.4), we express the action of U on
the circuit shown in Fig. (2.2) as
More generally, the rotation matrices defined below are more versatile then the Pauli
matrices, since the Pauli matrices are special
cases of the rotation matrices with the parameters α, β, γ = π
cos α2 −i sin α2
Rx (α) = e
=
−i sin α2
cos α2
cos β2 − sin β2
−iβ Y2
Ry (β) = e
=
cos β2
sin β2
−i γ
2
0
e
−iγ Z
γ
Rz (γ) = e 2 =
.
(2.7)
0
ei 2
−iα X
2
U : q 0 q 1 7→ U 0 ⊗ U 1 q 0 q 1 = q̃ 0 q̃ 1 . (2.5)
We can also describe Rx in terms of the others as
If U is a 2 × 2 matrix, the resulting product
U0 ⊗ U1 will be a 4 × 4 matrix. When applied,
the new big matrix operates on the whole register at once.
|q 0 i
U0
|q 0 i
U1
=
U
Rx (α) = Rz (π/2) · Ry (α) · Rz (π/2).
(2.8)
|q̃ 0 i
Phase Gate
|q̃ 1 i
If a global phase δ is applied to a state, the result will be eiδ |Ψi. A phase shift gate will
not alter the result of the circuit, because
upon measuring a state |Ψi, the probabilities
are only related to the magnitudes, not their
phases. This fact is a key component in the
Grover algorithm, discussed below. eiδ |Ψi and
|Ψi are then indistinguishable, because they
will give the same result when measured. We
get the matrix
Figure 2.2: U acting on both qubits, producing
a compound gate acting on the whole register.
We are now ready to present the matrices
representing the gates of interest.
Rotation Gates
The Pauli matrices X, Y , Z, and the identity matrix I are Hermitian and constitute a
unitary operator basis in our 1-qubit Hilbert
space.
0 1
0 −i
X=
Y =
1 0
i 0
1 0
1 0
Z=
I=
(2.6)
0 −1
0 1
P h(δ) = e
iδ
1 0
.
0 1
(2.9)
The purpose of this gate then is to make sure
the state is in the right phase after the rotation
around the Bloch sphere [Williams, 2011].
The Pauli Gates
We can use the Pauli matrices to rotate the
state of a single qubit, |q0 i, around the state
axes of the Bloch sphere by π radians. Note
that we will have to rotate 4π radians to be
back in the original state.
The X-gate represents the bit-flip and is
equivalent to the classical NOT-gate as it
maps |0i to |1i and |1i to |0i by rotating
the state π radians around the x-axis. However, we also need to compensate for the phase
8
change with the phase shift matrix.
π
0 −i
1 0
·i
X = Rx (π) · P h( ) =
−i 0
0 1
2
0 1
=
.
(2.10)
1 0
where it will pick up the first term if the qubit
is in state |0i and the second if the qubit is
in state |1i corresponding to the signs in Eq.
(2.14). The Hadamard gate will transform the
state of the qubit onto the Hadamard basis
{|+i , |−i} by performing the transformation
The Z-gate represents the phase-flip and
will leave the |0i unaffected and negate the
magnitude of the |1i state with a rotation
around the z-axis with π radians so that it
becomes − |1i, but just as in Eq. (2.10) we
also need to compensate for the phase change.
1 π
0
1 0
i
·i
Z = Rz (π) · P h( ) =
0 i
0 1
2
1 0
=
.
(2.11)
0 −1
1
|0i → √ (|0i + |1i) = |+i
2
1
|1i → √ (|0i − |1i) = |−i .
2
In the Hadamard basis we will be able to alter
the phase, an operation which is impossible to
do on the classical bit. This property is one
source of the power of several quantum algorithms.
It is possible to construct the Hadamard matrix using the gates in the universal set S
by the combination of two rotations; π radians around the X-axis followed by π/2 radians
around the Y-axis, and lastly a phase shift.
The Y -gate is identical to the combined operation iXZ and will map |0i to i |1i and |1i to
−i |0i with a rotation around the y-axis with
π radians and a phase shift [Williams, 2011].
π
π
H = Rx (π) · Ry ( ) · P h( )
2
2
√ #
" √2
0 −i
−√ 22
1 0
2
√
=
· 2
·i
2
−i 0
0 1
2
2
√ 2 0 1
1 −1
= (−i)i
·
1 1
2 1 0
1 1 1
=√
.
(2.15)
2 1 −1
0 −1
1 0
Y = Ry (π) · P h(π) =
· −1
1 0
0 1
0 −i
=
.
(2.12)
−i 0
Hadamard Gate
The Hadamard transform is a discrete Fourier
transform in 2n dimensions. The Hadamard
matrix Hn can be calculated recursively by:
1 1 1
H0 = 1, H1 = √
2 1 −1
1 Hn−1 Hn−1
Hn = √
2 Hn−1 −Hn−1
= H1 ⊗ Hn−1
(2.13)
This is not necessarily the best way to construct the Hadamard gate in the hardware of
a quantum computer or even when constructing the matrix in a simulation of a quantum
computer. It just shows that it is possible to
build it with these gates, that the set S is universal, and that we don’t need any other gates,
even if it may not be the best way to build the
larger gates.
The 2n -dimensional Hn maps n qubits to a
superposition of all 2n orthogonal states of the
Hilbert space with equal probability. The operator representation for one qubit is
H=
|0i + |1i
|0i − |1i
√
h0| + √
h1|
2
2
Controlled-Universal Gate
In Grover’s algorithm we need a controlled operation to do “if-then-else” tasks. For example: "negate the second qubit (the target) if
and only if the first qubit (the control) is in
(2.14)
9
the state |1i". This example describes the
controlled-NOT gate cNOT, which is analogous to the classical XOR gate. However, since
the control qubit can be in a superposition, the
target qubit may become entangled.
1 0 0 0
0 1 0 0
cN OT = P0 ⊗ I + P1 ⊗ X =
0 0 0 1
0 0 1 0
(2.16)
In the cNOT-gate we use the projection operators Pi |ji = δij |ji for the control part as
they tell us if a qubit is in state 0 or 1.
1 0
P0 = |0i h0| =
0 0
0 0
P1 = |1i h1| =
(2.17)
0 1
The Toffoli gate can also be constructed
by the gates in the universal set S
[Shende V. and Markov L., 2008].
In the circuit it has the symbols visualized
in Fig. (2.3).
2.2
|1i
|1i
•
first two qubits will not purely be in the state
|1i and the operation will be proportional
to how close the actual state is to the |1i state.
ccU = P0 ⊗ P0 ⊗ I + P1 ⊗ P1 ⊗ U +
+ P0 ⊗ P 1 ⊗ I + P1 ⊗ P0 ⊗ I =
1 0 0 0 0 0 0
0
0 1 0 0 0 0 0
0
0 0 1 0 0 0 0
0
0 0 0 1 0 0 0
0
(2.19)
=
0 0 0 0 1 0 0
0
0 0 0 0 0 1 0
0
0 0 0 0 0 0 U11 U12
0 0 0 0 0 0 U21 U22
|1i
|0i
Grover’s Algorithm
In 1996 Lov Grover presented√ a quantum search algorithm with O( N ) steps
[Grover, 1996], which is the fastest possible
quantum algorithm today. Classically, searching an unsorted database of N entries is typically finished with N/2 steps. Grover’s algorithm provides a quadratic speed-up, and the
allure of such an algorithm is clear.
Start by labeling each item of the database
that is to be searched with a corresponding
quantum state. Using our n-qubit Hilbert
space, the number of qubits n required to completely map the database, follows the relation
N = 2n , and our computational basis is described as {|q 0 i , |q 1 i , ..., |q n−1 i}. Using our
formalism from Eq. (1.3) and choosing n = 3
for simplicity, we can define the ground state
of the register as all qubits being in the |0i
state, namely
Figure 2.3: cNOT with the first qubit as the
control and second qubit as target
We can generalize the cN OT -gate by considering the target to be rotated a certain
amount around an arbitrary axis by using the
rotation matrices. If applied to the system on
two qubits with the first qubit as control and
the second qubit as target we get
1 0 0
0
0 1 0
0
cU = P0 ⊗ I + P1 ⊗ U =
0 0 U11 U12 .
0 0 U21 U22
(2.18)
Toffoli Gate
q 0 ⊗ q 1 ⊗ q 2 = |000i .
An extension of cN OT is the Toffoli gate,
also called the controlled-controlled-NOT
gate ccN OT . By adding a second control, we
can flip the third bit (the target) only if both
controls are in state |1i and |1i. Often, the
(2.20)
When we are searching a list, it helps to think
of the computational basis as |000i being the
state chosen to describe the first entry, |001i
10
|q 0 i : |0i
H
|0i+|1i
√
2
|q 1 i : |0i
H
|0i+|1i
√
2
H
|0i+|1i
√
2
|q n−1 i : |0i
..
.
Figure 2.4: Initialization of the register with
the Hadamard gate
the second, and so forth. In this way, we have
mapped 3 qubits to 23 entries. For example,
this means that the second entry in our list
is described by the state where qubits 1 and
2 have eigenvalue Sz = ~/2 and qubit 3 has
Sz = −~/2. However, this mapping is not
exclusive to qubits since classical bits also have
2 states and can be mapped in the same way.
The real supremacy of the qubit comes when
it is put in a superposition, which is done by
the Hadamard gate during the initialization.
2.2.1
Figure 2.5: The equal amplitudes of the register |ψi = H ⊗n |0i⊗n after initialization.
Marking
Define the solved problem (e.g. which state
in the computational basis that maps to the
sought-after database entry) as the unique
state |ti that satisfies the following property
for a Boolean function F
1 for x = t
F (x) =
0 ≤ x ≤ N − 1.
0 for x 6= t
(2.22)
Using this criterion, we can construct an oracle, whose purpose is to returns −1 upon being "asked" the correct question t and 1 otherwise. This selection process is called marking
because the oracle recognizes the solution by
marking the sought-after state in the computational basis with a negative sign and leaves
the rest unaltered. The oracle is then defined
as
O |xi = (−1)F (x) |xi .
(2.23)
The Algorithm
Initializing
We initialize the n qubit register |0i⊗n with the
Hadamard gate as shown in Fig. (2.4). This
puts the qubits in an equal superposition of all
N = 2n basis states, shown in Eq. (2.21).
Note that as in Fig. (2.2), the application
of n H1 gates is equivalent of applying one Hn
gate over the whole register. This linear property is convenient when we examine the effect
of this operation algebraically, because we can
use the 2n -dimensional Hadamard operator Hn
from Eq. (2.13)
Herein lies the Achilles heel of the algorithm,
because it is not clear how the oracle is constructed. Being a black box, the oracle is assumed to be provided to the quantum computer a priori, or at least be computed externally and will most certainly√have a different
time complexity than the O( N ) we promised
earlier. Additionally, the oracle must still be
implemented as a quantum gate, obeying reversibility. In practice, a 3-qubit oracle has
N −1
1 X
|xi .
|ψi = H |0i = Hn |0i = √
N x=0
(2.21)
The ket |xi is the decimal representation of
the state of the register, so in the summation
|0i = |000i , |1i = |001i, and so on. The register can now be graphed.
⊗n
⊗n
⊗n
11
the magnitudes, and by extension, probabilities are still equal. The oracle has merely rotated the phase of the correct question |ti by
θ = π Thus, we need to invoke amping to further modify the amplitudes by converting the
phase difference to a magnitude difference.
Amping
The goal of the amping stage is to amplify the
marked state at the cost of the unmarked ones.
To do this, we calculate the mean, µ (shown
in Fig. (2.6)) of the amplitudes, and then invert around it. The result will be a drop-off
of the states above the mean (i.e. the unmarked ones), and a large boost to the marked
state, as shown in Fig. (2.7). However, we
will never explicitly calculate any averages.
Instead, we use the inversion-about-the-mean
operator U = 2 |ψi hψ| − I, which does all of
this for us. We can prove that U really gets
the job done by the following theorem.
Figure 2.6: The amplitudes of the register
O |ψi = OHn |0i⊗n after querying the oracle
once. Mean amplitude µ included.
been implemented by [Figgatt et al., 2017] using a number of X and ccN OT -gates to produce the correct mark.
Returning to our demonstrative case of n =
3 qubits, the matrix representation of an oracle
O could be
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
O=
0 0 0 0 1 0 0 0 . (2.24)
0 0 0 0 0 −1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1
Theorem 1. The operator U = 2 |ψi hψ| −
I, P
where |ψi is the equal superposition
N −1
√1
√1 |ii, applied on a register
x=0 |xi =
N
N
inverts each state about the mean.
Proof. Consider
PN −1the effect of U on the genThen
eral
k=0 αk |ki.
P state
P U α2 k |ki =
2
α
|ii
hj|ki
−
α
I
|ki
=
k
ijk N k
ijk N αj |ii −
P
1
αk |ki = {k → i} =
ij 2 N αj |ii − αi |ii .
Since αk |ii hj|ki = αP
j |ii, and the definition
1
for the mean, µ =
j N αj , We now have:
P
P
1
ij 2 N αj |ii − αi |ii =
i [2µ − αi ] |ii, which
inverts each amplitude αi around µ.
This oracle will mark the state |101i, which,
by using the decimal representation from Eq.
(2.21) is the state |x = ti = |5i. Using Eq.
(2.21) and Eq. (2.23), we arrive at the state
The effect of U is shown in Fig. (2.7).
This figure shows that the unmarked
states
√
|x 6= ti are reduced by 4/N N , while
√ the
marked state |ti has grown from 1/ N to
3−4/N
√
. At measurement, |ti is now distinguishN
able from |x 6= ti, but we can do even better
with more iterations, which will further amplify |ti, and reduce |x 6= ti.
How do we implement the amping U ? We
have provided its operator representation, and
proved that it is an inversion about the mean,
N −1
1 X
(−1)F (x) |xi .
O |ψi = √
N x=0
(2.25)
The effect of the marking is shown in Fig.
(2.6).
While this looks promising since the marked
state |ti is clearly distinguishable from the
unmarked ones, a measurement of this state
will unfortunately yield no useful result since
12
|t
G|
|
/2
/2
O|
Figure 2.7: The amplitudes of the register
(2 |ψi hψ| − I)O |ψi after one iteration through
the Grover algorithm.
Figure 2.9: How the register state evolves in
the Grover algorithm
k
|0i
H
|0i
H
|0i
H
H
Oracle
H
H
2.2.2
H
2P0 − I
Result Periodicity
How many times do we have to iterate? For
simplicity, let k Grover iterations be denoted
as
H
H
Gk |ψi = [Hn (2(P0 )⊗n − I)Hn O]k Hn |0i⊗n .
(2.26)
Rewrite the superposition from Fig. (2.5) |ψi
in terms of the marked state
P |ti and the un1
marked states |αi = √N −1 x6=t |xi
Figure 2.8: √
The complete Grover algorithm
with k ∼ O( N ) iterations.
r
but we need a set of gates to actually perform it. As mentioned in the subsection about
marking, the qualitative goal of the amping U
is to utilize the phase difference between the
states and convert it to a magnitude difference.
For such an operation, the Hadamard Transform springs to mind, and it turns out that we
can use the interpretation of the Hadamard
gate as a Discrete Fourier Transform to perform just that. From Theorem (1) and Eq.
(2.21), we can rewrite U = 2 |ψi hψ| − I to
Hn (2 |0i⊗n h0|⊗n − I)Hn . Recall the projection matrix P0 = |0i h0|, and we can thus
write U as Hn (2(P0 )⊗n − I)Hn . The complete
Grover algorithm in operator representation is
⊗n
⊗n
k
then written [H
√ n (2(P0 ) − I)Hn O] Hn |0i ,
where k ∼ O( N ). This is shown in Fig. (2.8)
.
|ψi =
1
N −1X
|αi + √ |ti .
N x6=t
N
(2.27)
From this, the angle between the state of the
register and
qthe unmarked states is hα|ψi =
N −1
cos θ/2 =
. The register may now be
N
expressed as
|ψi = cos
θX
θ
|αi + sin |ti .
2 x6=t
2
(2.28)
We are now interested in how much each iteration decreases angle between the register state
and the marked state, ht|ψi. Approximating
a trigonometric identity,qwe now have θ ≈
sin θ = 2 cos 2θ sin 2θ = 2
N −1 √1
N
N
√
= 2 NN−1 ,
√
which is approximately 2/ N for N 1. The
13
number of iterations needed, i.e. the number
of θ rotations needed to reach |ti at π/2 is now
k=
2.3
2.3.1
π/2
π/2
π√
≈ √ =
N.
θ
4
2/ N
of the values are after the fourth standard deviation in a normal distribution, and we cut
the tail here. 4π divided by eight gives us the
maximum interesting value of σ = π2 and we
will not use larger values.
(2.29)
Error & Error Correction
2.3.2
Different methods to mitigate errors are available, and we have chosen to implement an
error correcting algorithm. Such algorithms
are not that common in ordinary computers
because one Boolean bit needs a relatively
large perturbation, for example a large heat
fluctuation or physical impact, to change and
the change can only be a bit flip (0 → 1 or
1 → 0). Error detection and correction are
more common in communication channels,
which can be subjects to noise, and is easily
done by simply measuring the bits and re-flip
the faulty ones. We could do this if we
can check the state in some way, either by
knowing the original state or have a checksum. Additionally is also possible to copy
classical bits, and thereby be able to measure
differences between different snapshots of the
register.
If one were to try to apply this to a quantum
system, quantum mechanics would throw
multiple gears in the wheel. Even a small
perturbation could completely destroy the
state. We have more types of errors (e.g phase
shifts) that can occur due to the wave particle
duality of the wave function; we cannot
measure the state to check if it is correct due
to the collapse of the superposition; and we
cannot copy the state of a qubit due to the nocloning theorem [Wootters and Zurek, 1982].
The quantum algorithm that we use have
to be able to correct for an error without
detecting and measuring it. We do so by
making sure that we return to the same state
independently if an arbitrary change has
occurred.
Defining the Error
There are different types of possible changes
in a qubits state: the Pauli errors include bit
flips where the state is flipped: |0i → |1i, and
phase shifts |+i → |−i. Another type of error is amplitude dampening, which is outside
the scope of this thesis. We have chosen to
simplify the effect of decoherence and operation inaccuracy. In reality, a combination of
changes might occur. We define the error by
a single qubit state change, assuming that the
decoherence process only affects the different
qubits independently and also assuming only
one gate is faulty.
Decoherence is entanglement with a state in
the environment and can be written as
E : α |0i + β |1i →
α(|e0 i |0i + |e1 i |1i)+
β(|e3 i |0i + |e4 i |1i)
(2.30)
where |ei i are states of the environment that
the qubit entangled with and thereby produce
an error [Nyman, 2009, Mermin, 2016].
Ideally, no decoherence occurs and the gates
will work perfectly. To model the error, we
introduce a 1-qubit error gate, either at a noisy
channel in the circuit or directly after a gate.
The error gate, E, will perform Pauli errors by
rotating through normally distributed angles,
with standard deviation σ
E = Rx (α) · Ry (β) · Rz (γ) · P h(δ).
Error Correction
(2.31)
We have to turn 4π radians to be back in the
original state, so it is not interesting to do simulations with rotations above 4π. Below 0.1%
We have implemented Shor’s error correcting code. During the first step in the
14
α |0i + β |1i
|0i
|0i
algorithm called the encryption, n incoming
qubits in the state |φi, are distributed to
nine qubits, 9n, highly entangling them.
The algorithm cleverly avoids the no-cloning
theorem by a basis transform. The resulting
encrypted system is now in a highly entangled
Bell state, in 29n Hilbert space. The system is
more robust in the encrypted state, and will
thereby be more resistant to changes. The
algorithm then uses the amplitudes of the
larger state to recover the original information
in the final part, called the decryption process.
A few things need to be defined before we
can get into the details of the algorithm.
We break the Pauli errors down to its two
components and build a robust state that is
able to withstand for both changes in one
qubit.
•
•
H
•
Secondly, we specify the phase shift robust
state, and we do this by expanding the
Hadamard basis. The Hadamard gate will
convert the logic qubit to the phase basis as
|000i + |111i
√
2
|000i − |111i
√
H |1L i =
2
H |0L i =
(2.32)
•
•
•
•
•
•
•
|0i
•
•
H
•
H
•
•
E
•
|0i
H
•
(2.34)
α |0i + β |1i
•
|0i
|0i
H
•
H
(2.33)
and a phase shift will lead to a change in the
sign (|+i → |−i). We want to build a robust
state for the signs too and we do this by building logic qubits of the signs as well. We can
use the circuit in Fig. (2.11) to do this too,
|0i
|0i
α |000i + β |111i
The Phase Shift Robust State
This state is achieved by entangling the qubit,
in state |ψi, with two ancillary qubits, both in
state |0i, with the use of two cN OT -gates as
shown in Fig. (2.11).
α|0i + β|1i
)
From the logic qubit will we be able to recover to the original information of the qubit
|ψi even if a bit is flipped, (|000i → |010i). We
can do this decryption to the original state of
|0i or |1i, by a majority vote with the use of
the inverse of the operations in Fig. (2.11) and
a ccN OT -gate. The state will be the same because the coefficients α and β do not change
after the bit flip [Mermin, 2016].
First thing to be defined is the 3-qubit logic
qubit, |ψL i, that will be able to withstand bit
flips.
|1L i = |111i .
•
Figure 2.11: Circuit to construct a logic qubit
The Bit Flip Robust State
|0L i = |000i ,
•
•
•
•
•
|0i
•
|0i
Figure 2.10: The Shor Code.
15
We use the Bell basis to describe highly
entangled states of qubits, and this one will
make it possible to describe the distinguished
states.
For example can we differentiate between:
but we need to add the Hadamard gate at the
end to end up in the right basis.
The Shor Code
In the Shor error code we start with the encoding to the phase shift robust state and then do
the bit flip robust state encoding, as shown in
the left side of the error gate E in Fig. (2.10),
and end up in the state of the highly entangled
logic qubit
⊗3
|000i + |111i
√
(2.35)
|0S i =
2
⊗3
|000i − |111i
√
|1S i =
.
(2.36)
2
We now examine why this final state |ψS i =
α |0S i + β |1S i is so robust.
First we look at what an error in one qubit,
|q i i, with initial state |0i does when said bit
|q i i is encoded to the phase shift robust state
of H |0L i, i.e. the first triplet
Ei H |0L i = Ei (
• if in state |0i when entangled with a
change
in the third qubit: |001i + |110i,
or a change in the second qubit: |010i+|101i
• if in state 1 when entangled with a change
in the third qubit: |001i − |110i,
or a change in the second qubit: |010i −
|101i.
If we write Eq. (2.37) in the Bell basis we get
Ei |0i =
1
= √ ((|e0 i + |e3 i)(|000i + |111i)
2 2
+ (|e0 i − |e3 i)(|000i − |111i)
+ (|e1 i + |e2 i)(|100i + |011i)
+ (|e1 i − |e2 i)(|100i − |011i). (2.40)
|0i 00i + |1i 11i
√
)
2
Then do the same for Eq. (2.38).
1
= √ ((|e0 i |0i + |e1 i |1i) |00i
2
+ (|e3 i |0i + |e4 i |1i) |11i). (2.37)
Ei |1i =
1
= √ ((|e0 i + |e3 i)(|000i − |111i)
2 2
+ (|e0 i − |e3 i)(|000i + |111i)
+ (|e1 i + |e2 i)(|100i − |011i)
+ (|e1 i − |e2 i)(|100i + |011i). (2.41)
i
Similarly if |q i’s original state was |1i:
Ei H |1L i = Ei (
|0i 00i − |1i 11i
√
)
2
1
= √ ((|e0 i |0i + |e1 i |1i) |00i
2
− (|e3 i |0i + |e4 i |1i) |11i). (2.38)
This change, either to Eq. (2.40) or to Eq.
(2.41), will only be in one triplet and we can restore the original state of the encoded qubit by
checking the other two triplets ancillary qubits
to see if the sign in the Bell superposition has
changed. The superposition of the Bell basis
is still maintained because the coefficients are
the same whether the original qubit decohered
from the state |000i + |111i or |000i − |111i.
We do this check and then correction according to the sign changed with the ccN OT -gate
as seen in the right part of Fig. (2.10).
We now describe more closely why the
decoding works to get the original state back.
This is very specifically a change in the first
qubit of the first three coupling (in the phase
robust state). To generalize this we need to
describe the state Eq. (2.37), but with the
error in an arbitrary qubit, and the need of a
larger basis rises. We expand the phase robust
state basis to the Bell basis
{|000i ± |111i ,
|001i ± |110i ,
|010i ± |101i ,
|100i ± |011i}.
(2.39)
16
The state in the Bell basis shows what went
wrong and a check of the ancilla is the same
as the encoded qubit.
For example:
• if the check of the ancilla shows to be
the second line of the right side of Eq. (2.40)
we know that the error was a sign flip (phase
shift) but no bit flip;
• if the output was the third line we know
that the error was bit flip in qubit one, but
the sign is right so no phase shift;
and if the output is the fourth line then both
the Pauli errors has occurred.
Note that we do not actually measure the
original encoded qubit, but rather measure
the error so that the original state is left
untouched.
The state is rebuilt without
giving the information about it.
Figure 2.12: Theoretical construction of the circuits producing the cU - and ccU -gate.
•
P1
=
U
I
+
U
P0
•
I
•
I
U
(a) cU -gate.
P1
=
P1
U
P0
+
P1
P1
+
I
(b) ccU -gate.
17
P0
I
P0
+
P0
I
Chapter 3
Simulation & Results
3.1
Simulation in Python
The Toffoli Gate Matrix
The Toffoli gate uses qubits |q c1 i and |q c2 i as
controls and |q t i as target. The matrix is constructed as
Here we describe how we simulated the quantum computer in Python using NumPy with
the register as a state vector and the gates
as transformation matrices. The one qubit
gates are implemented as their 2x2-matrices
as they’re written in Sec. (2.1). A gate applied on qubit i in the register with n qubits
is written with the identity matrix on the unaffected qubits as
U i : q 0,...,n 7→
I
0,...,(i−1)
i
⊗U ⊗I
(i+1),...,n
q
ccU c1 ,c2 ,t =
I 0,... ⊗ U t ⊗ I ... ⊗ P1c1 ⊗ I ... ⊗ P1c2 ⊗ I ...,n
+ I 0,... ⊗ P0c1 ⊗ I ... ⊗ P0c2 ⊗ I ...,n
+ I 0,... ⊗ P0c1 ⊗ I ... ⊗ P1c2 ⊗ I ...,n
+ I 0,... ⊗ P1c1 ⊗ I ⊗ P0c2 ⊗ I ...,n ,
(3.3)
where we need to permute through the four
states that the two controls can be in. This is
visualized in Fig (2.12b). This is a theoretical application of how to combine the 1-qubit
matrices of the cU -gate and might not necessarily be convenient to implement outside of
simulations.
0,...,n
= q 0,...,(i−1) q̃ i q (i+1),...,n ,
(3.1)
so the identity matrix ensures the correct dimension.
The cU -gate Matrix
The Measurement
With the control qubit |q c i in position c and
the target qubit |q t i in position t, we permute through the different possibilities, i.e.
the state of the target. This is done by
We implement the measurement of a qubit as a
generated random number of 0 or 1, governed
by the probability p. If the register is in state
|Ψi we can then express the probability that
qubit i is in state 0 by expressing the state
vector as a density matrix |Ψi hΨ|, and taking
the trace of the state when acted on by the
projector P0i
cU c,t = I 0,...,(t−1) ⊗ U t ⊗ I (t+1),...,(t+c−1) ⊗
⊗ P1c ⊗ I (c+1),...,n +
+ I 0,...,(c−1) ⊗ P0c ⊗ I (c+1),...,n ,
(3.2)
where the first term corresponds to the action
of the gate if qubit c is found in state |1i, and
the second term corresponds to the action of
the gate (i.e. apply U on |q t i) if the qubit is
found in state |0i. This is achieved by applying
P1c , and P0c respectively. This is visualized in
Fig (2.12a).
p( q i = |0i) = T r(|Ψi hΨ| P0i ).
(3.4)
If the random number is 0 then the rest of the
register will fall to the state
|Ψmeasured i =
18
P0i
kP0i |Ψik
2.
(3.5)
Iteration Probability of measuring |ti
1
0.6172
0.7948
2
3
0.9468
0.9996
4
5
0.9276
6
0.7656
n
1
2
3
4
5
6
7
8
9
10
11
12
Table 3.1: How the probabilities in Grover’s
algorithm with 5 qubits evolve with the number of iterations. The optimal number of iterations is marked in bold.
Time [ms]
4.01
5.01
6.02
7.02
10.0
13.1
29.7
116
675
4.25 · 103
2.99 · 104
2.21 · 105
√
(a) Time taken for π4 2n iterations
(b) Logarithmic time plot for√the simulated
Grover algorithm to execute π4 2n iterations
Figure 3.1: The oscillations of continuous iterations of Grover’s algorithm
3.2
Grover’s Algorithm
Efficiency
Evolution of Probabilities
As seen in Fig. (2.9), the algorithm has a
periodicity, which makes it possible to overcount, and for the qubit state to retract from
the target state. Thus, the probabilities oscillate around the target |ti, as see in Table
(3.1), and in Fig (3.1). With n = 5 qubits (i.e.
the graph with 25 = 16 items), the optimal
number of iterations
is expected to be, as per
√
Eq. (2.29): π4 25 = 4.44. To illustrate the algorithm overcounting, 12 iterations were done
for each of the three simulations.
Using sparse matrices, the algorithm becomes
quite efficient at low qubits. First at n = 10,
the calculations become non-instantaneous,
finishing at 4.26 s on a machine with eight
2.6 GHz cores. The logarithmic time taken
in milliseconds for the algorithm to iterate
the optimal number of iterations for each
qubit is shown in Fig. (3.2b). This behavior is expected, due to the O(n2.8 ) complexity in NumPy matrix multiplications using the
Strassen algorithm.
19
σ
π
32
π
16
π
8
π
4
π
2
Probability of measuring |0i
0.5
0.5
0.5
0.5
0.5
Table 3.2: How the probabilities of measuring
0 changes with σ.
3.3
Grover’s
with Error
σ
0
π
32
π
16
π
8
π
4
π
2
Algorithm
We can place the same error gate from Eq.
(2.31), without any error correction whatsoever, directly after the oracle in Grover’s algorithm to see how resilient it is. In this way,
we can simulate an error due to the oracle, or
a noisy transportation between the oracle and
the amping gate. The error gate is placed on
|q 0 i to simulate a noisy oracle. This can be extended by applying the 1-qubit gate over more
qubits.
3.4
Probability of measuring |ti
0.9996
0.9912
0.9669
0.8908
0.7298
0.5710
(a) Table showing the probability of finding the
marked state after it applying an error gate
directly after the oracle. 4 iterations (optimal)
ran for each σ.
/32
/8
/2
No error
Error Correction Code
Error in One Qubit
We initialized the original qubit to be guarded
in a state with probability of measuring either
|0i or |1i to p = 0.5 as:
1
|ψi = √ (|0i + |1i)
2
(b) Plot of the results with three different standard deviations, along with an unperturbed
plot.
(3.6)
Figure 3.3: How the probability of measuring
|ti varies after placing an error gate on |q 0 i
after the oracle with a normally distributed
error with standard deviation σ. n =√5, so
we expect the first peak to show at π4 25 =
4.44 iterations. Each Grover iteration ran 1000
times to reduce fluctuations.
and the eight rest in state 0. Then we apply
the encoding as shown in the left side of Fig.
2.10 followed by the application of the error
gate on the first qubit E 0 |ψ00000000i. We
apply the error gate with different standard
deviations σ in the distribution of the random
angles of Eq. (2.31). We then decode the register and measure the first qubit to see if it
has returned to its original state by checking
the probability of measuring |0i. The measurements are written in Table 3.2.
We then investigate if the measurement is
the same for a 100 runs with the same stan20
3.5
dard deviation σ = π/2 and same initial state
as in Eq. 3.6. All the measurements gave
p(|qi = |0i) = 0.5 and the whole run took
around 140 seconds. This means that the incoming superposition was conserved, and that
the error was successfully removed by the algorithm.
Grover’s
Algorithm
with Error correction
We were not able to simulate the two algorithms together because Grover’s algorithm
needs at least two qubits to work and the
Shor code adds nine to each. At 18 qubits
the memory of the simulating computer runs
out because using Grover’s algorithm with n =
2 qubits, we get (non-sparse) matrices with
(22·9 )2 = 68719476736 elements. If each element stored as a 8-bit complex float, a single
matrix then requires 550 gigabytes of memory.
Error in Two or More Qubits
We initialized the original qubit to be guarded
in a state with probability of measuring either
|0i or |1i to p(|q 0 i = |0i) = 0.5 as in Eq. 3.6
and the eight rest in state 0. Then we apply
the encoding, followed by the application of
the error gate on an increasing amount (2 to
9) of qubits. We apply the error gate with
the same standard deviations σ = π/2 in
the distribution of the random angles of Eq.
(2.31) with a new generated angle for each
time we apply it to a qubit. We then decode
the register and measure the first qubit to
see if it has returned to its original state by
checking the probability of measuring |0i.
We repeat this for each number of qubits a
100 times and take the mean value of the
measurements and the mean value of how
much the measurements the differ from 0.5,
we write the in Table 3.3 together with the
largest and smallest value. Each run took
about 140 seconds.
We can conclude that the Shor code works
really good for up to six perturbed qubits.
Noticing we get a difference in the algorithms
capacity to correct the error between six and
seven perturbed qubits called for more runs
with error in different qubits around seven perturbed qubits, with the same initializing and
standard deviation. This can be seen in Table 3.4. There is really a line to be drawn at
six qubits with an exception at the combination of 235678 being perturbed. We do not
know why this is. We don’t treat any of the
qubits from the other, other simulations with
six qubits works fine.
21
perturbed qubits # Mean Max.
Min.
Mean diff.
0,1
2 0.5000 0.5000 0.5000
0
0,1,2
3 0.5000 0.5000 0.5000
0
4 0.5000 0.5000 0.5000
0
0,1,2,3
0,1,2,3,4
5 0.5000 0.5000 0.5000
0
6 0.5000 0.5000 0.5000
0
0,1,2,3,4,5
7 0.4998 0.5370 0.4355 2.0 · 10−2
0,1,2,3,4,5,6
0,1,2,3,4,5,6,7
8 0.5009 0.5416 0.4459 −9.2 · 10−2
0,1,2,3,4,5,6,7,8 9 0.4998 0.5578 0.4052 1.5 · 10−2
Table 3.3: How the probabilities of measuring |0i on qubit |q 0 i, p(|q 0 i = |0i), changes with
different perturbed qubits. # is the number of perturbed qubits. Mean is the mean of the 100
values; Max. is the maximum of the 100 values; Min. is the minimum of the 100 values; and
Mean diff. is the mean value of how much the 100 measurements the differ from 0.5.
Min.
Mean diff.
perturbed qubits # Mean Max.
0,3,6
3 0.5000 0.5000 0.5000
0
6 0.5000 0.5000 0.5000
0
0,1,3,4,6,7
0,1,3,4,6,7,8
7 0.5007 0.5292 0.4778 −7.3 · 10−2
0,1,2,3,4,5,7
7 0.5002 0.5760 0.3922 2.0 · 10−2
0,1,2,3,4,5,6
7 0.5008 0.5409 0.4795 −8.0 · 10−2
0,1,2,3,4,5,6,7
8 0.4991 0.5296 0.4149 9.5 · 10−2
0,1,2,3,4,5,6,7,8 9 0.4969 0.5255 0.4052 3.0 · 10−3
0,1,2,3,4,5,6,7,8 9 0.5021 0.5468 0.4653 −2.0 · 10−3
2,3,5,6,7,8
6 0.5013 0.5495 0.4590 −1.3 · 10−3
2,3,5,6,7,8
6 0.5009 0.5552 0.4588 −1.0 · 10−3
2,3,5,6,7,8
6 0.4990 0.5456 0.4249 1.0 · 10−3
0,1,2,6,7,8
6 0.5000 0.5000 0.5000
0
3,5,6,7,8
5 0.5000 0.5000 0.5000
0
3,4,5,6,7,8
6 0.5000 0.5000 0.5000
0
1,2,3,5,6,7
6 0.5000 0.5000 0.5000
0
Table 3.4: How the probabilities of measuring |0i on qubit |q 0 i, p(|q 0 i = |0i), changes with
different perturbed qubits. # is the number of perturbed qubits. Mean is the mean of the 100
values; Max. is the maximum of the 100 values; Min. is the minimum of the 100 values; and
Mean diff. is the mean value of how much the 100 measurements the differ from 0.5. The special
combination of six perturbed qubits are in bold.
22
Chapter 4
Discussion
4.1
Simulation of a Quantum Computer
for σ/2, which is too close to 50%, i.e. when
the algorithm is not ran at all.
The Shor Code
We successfully simulated Grover’s algorithm
first by itself with up to, and including n = 12
qubits and the Shor code with 9 qubits.
We can conclude that the Shor error correction worked perfectly to erase the error in one
qubit, and the size of the error did not affect
the results.
We can further conclude from Table (3.4)
that there is a clear line to be drawn at six
qubits, but that there is an exception at the
combination of qubits 2, 3, 5, 6, 7, 8 being perturbed. We do not know why this is. We don’t
differentiate between the qubits except in the
different triplets, but other simulations with
six qubits being perturbed in other installations, 0, 1, 2, 6, 7, 8 or 3, 4, 5, 6, 7, 8 for example,
works fine.
Grover’s Algorithm
We succeeded with simulating Grover’s algorithm and successfully showed the periodicity
of the algorithm,
√ and the optimal iterations
π
number being 4 2n for n qubits. As shown in
Fig (3.1), the algorithm produces the oscillatory fashion expected, and shows probability
peaks at exactly the iterations where we expect them.
Grover’s Algorithm with Error
Grover’s Algorithm with Error Correction
In Fig. (3.3b), we see that the larger the
standard deviation of the rotations of the error gate is, the peaks become less prominent.
When the error rotation had a standard deviation of σ = π/8, the behavior of the probability evolution still resembled the unperturbed
one with distinguishable peaks at the optimal
iteration number(s). For σ = π/2, the algorithm lost almost all of its power. This result
might suggest that a 1-qubit Pauli error with
a standard deviation of σ = π/8 still is acceptable, but that the Grover algorithm breaks
when subject to a Pauli error with σ = π/2.
This point is further shown in Table (3.3a). At
σ = π/8, we still have a 89% chance of measuring |ti, whereas the probability dips to 57%
We were not able to simulate the two algorithms together due to memory limitations.
This may be solved by optimization and a supercomputer. This shows a weakness in the
simulations of quantum computers: the huge
amount of memory required.
4.2
Weakness in Grover’s
Algorithm
Grover’s search algorithm does not explain
how the oracle might be constructed. To actually build a quantum black box that rec23
ognizes the correct state might very cumbersome. However, the algorithm may still
provide useful proof of concepts due to the
rest of the algorithm being relatively straightforward. If an oracle is conjured in an efficient manner, perhaps by an external process with low enough complexity, Grover’s algorithm may still be able to provide useful
work in larger search problems. A 3-qubit
oracle as been implemented in hardware by
[Figgatt et al., 2017].
4.3
Error
Price
&
code. If we want to reuse the ancillary qubits
the next time we do the error correction code
the qubits needs to be measured and then go
through the appropriate gates to be restored
to the state |0i that they need to be in to
run the code again. This restoration process
will take up some computation time and if not
done then additional qubits will be needed for
each time the Shor code is implemented.
Our model of the error, with the error gate
E, the assumption that it will only affect one
qubit, and the placing in the circuit, is also
not a fully realistic one. The Shor code only
corrects for these errors and we may have to
use not one but many techniques to tackle the
large problem with the decoherence. How the
quantum computer is built will also give different kinds of errors, and we can not fully understand the error that we will have before we
have realized a qubit and the quantum gates.
Peter Shor mentions all of these problems, (except the restoration problem which is due to
[Mermin, 2016]) in his paper and also concludes that decoherence may be the larges obstacle to overcome before we have working
quantum computers [Shor, 1995]. Others have
also pointed at this problem and some think it
is possible to overcome, not easily and not in
the way we think now, but doable according
to [Boixo et al., 2017] at Google.
Correction
The Shor code may seem to solve the problems caused by the Pauli errors in a neat and
easy way, since we get a corrected state without a big loss in calculation time. But there
is a large cost in the amount of qubits that
is needed to run the original algorithm, e.g.
Grover’s algorithm. For each n qubits that the
original algorithm uses, the Shor code adds a
factor of 9, so the number of required qubits
in the register goes from n to 9n. In our simulation, the size of the matrix needed to be
computed for each matrix multiplication then
grows exponentially from 2n to 29n .
Another problem that arises is that this extension of every part of the computation where
error correction is needed may lead to even
larger errors. If the error occurs in the cN OT
or Hadamard gates, then additions of more
gates would add up to another type of error
than decoherence with the surroundings. Getting rid of the possible decoherence may be
gained at the loss of degree of correctness every
time the Shor code is run and the output of the
computer with all the added up error would be
totally wrong, even if this error is small. We
will then have to balance the amount of error
from the decoherence of the surroundings with
the error introduced by the correction code.
Another cost will be the restoration of the ancillary qubits. All the ancillary qubits will not
be in the state |0i after one go of the Shor
4.4
Coherence Time
The quantum computer, as mentioned above,
will have to be in the state of total coherence.
The qubits that are used today have a coherence time of milliseconds [Rigetti et al., 2012,
Wendin, 2017]. If this is enough and how long
the time we need is dictated by how long time
the calculation needs to finish. In theory the
application of a gate is instant making the
quantum algorithms really fast, but in reality
the application of a gate could take seconds
to preform making the quantum algorithms
slower than ordinary computers. Because the
realization of a perfectly applied quantum gate
on a quantum memory without errors has not
24
yet been achieved we do not know the speed
of each step in the algorithms. Will we even
be able to engineer the gates and the switch
of gates, to be fast and precise enough? This
is another obstacle to overcome before we can
fully say that we have built a quantum computer that will achieve quantum supremacy.
25
Chapter 5
Conclusion
Grover’s search algorithm was developed in
the 90’s, but have yet to be feasibly implemented in larger qubit registers due to hardships such as error and decoherence. Computer simulations of quantum computers helps
us to understand the power of the quantum
algorithms and what we could achieve with
them, but also which obstacles that we have
to overcome if we ever are to reach quantum
supremacy. From our simulations we learned
that Grover’s algorithm can be effective, that
a large enough error can destroy this efficiency, and that an error correcting algorithm
can correct rudimentary Pauli errors, but at
a high cost of ancillary qubits and computational time.
26
Bibliography
[Almlöf, 2016] Almlöf, J. (2016). Quantum
error correction. KTH Royal Institute of
Technology.
S., and Monroe, C. (2017). Complete 3Qubit Grover search on a programmable
quantum computer. Nature Communications, 8:1918.
[Bennett et al., 1996] Bennett, C. H., Bernstein, E., Brassard, G., and Vazirani, U.
(1996). Strengths and weaknesses of quantum computing. Submitted to: SIAM J. Sci.
Statist. Comput.
[Grover, 1996] Grover, L. K. (1996). A fast
quantum mechanical algorithm for database
search. eprint arXiv:quant-ph/9605043.
[Kitaev, 1997] Kitaev, A. (1997). Quantum
computations: algorithms and error correction. Russian Mathematical Surveys,
52:1191–1249.
[Bishop et al., 2017] Bishop, L. S., Bravyi, S.,
Cross, A., Gambetta, J. M., and Smolin,
J. A. (2017). Quantum volume.
[Manin, 1999] Manin, Y. I. (1999). Classical
computing, quantum computing, and shor’s
factoring algorithm. Classical computing,
quantum computing, and Shor’s factoring
algorithm.
[Boixo et al., 2017] Boixo, S., Isakov, S.,
Smelyanskiy, V., Babbush, R., Ding, N.,
Jiang, Z., Bremner, M. J., Martinis, J.,
and Neven, H. (2017).
Characterizing
quantum supremacy in near-term devices.
arXiv:1608.00263.
[Mermin, 2016] Mermin, N. D. (2016). Quantum computer science: an introduction.
Cambridge University Press.
[Chiaverini et al., 2004] Chiaverini,
J.,
Leibfried, D., Schaetz, T., Barrett, M. D.,
Blakestad, R. B., Britton, J., Itano, W. M.,
Jost, J. D., Knill, E., Langer, C., Ozeri, R.,
and Wineland, D. J. (2004). Realization
of quantum error correction.
Nature,
432:602–605.
[Nielsen and Chuang, 2016] Nielsen, M. A.
and Chuang, I. L. (2016). Quantum Computation and Quantum Information. Cambridge University Press.
[Nyman, 2009] Nyman, P. (2009). A symbolic
classical computer language for simulation
of quantum algorithms.
[Clark, 2014] Clark, K. B. (2014). Basis for
a neuronal version of grovers quantum algorithm. Frontiers in Molecular Neuroscience,
7.
[Rigetti et al., 2012] Rigetti, C., Gambetta,
J. M., Poletto, S., Plourde, B. L. T., Chow,
J. M., Córcoles, A. D., Smolin, J. A.,
Merkel, S. T., Rozen, J. R., Keefe, G. A.,
Rothwell, M. B., Ketchen, M. B., and Steffen, M. (2012). Superconducting qubit in
a waveguide cavity with a coherence time
approaching 0.1 ms. Physical Review B,
86(10):100506.
[Feynman, 1982] Feynman, R. P. (1982). Simulating Physics with Computers. International Journal of Theoretical Physics,
21:467–488.
[Figgatt et al., 2017] Figgatt, C., Maslov, D.,
Landsman, K. A., Linke, N. M., Debnath,
27
[Shende V. and Markov L., 2008] Shende V.,
V. and Markov L., I. (2008). On the
cnot-cost of toffoli gates. [1402.1128] Long
Short-Term Memory Based Recurrent Neural Network Architectures for Large Vocabulary Speech Recognition.
[Shor, 1995] Shor, P. W. (1995). PolynomialTime Algorithms for Prime Factorization
and Discrete Logarithms on a Quantum
Computer. eprint arXiv:quant-ph/9508027.
[Shor, 1995] Shor, P. W. (1995). Scheme for
reducing decoherence in quantum computer
memory. Physical Review A, 52(4):R2493–
R2496.
[Wang et al., 2015] Wang, Y., Dolde, F., Biamonte, J., Babbush, R., Bergholm, V.,
Yang, S., Jakobi, I., Neumann, P., AspuruGuzik, A., Whitfield, J., and Wrachtrup, J.
(2015). Quantum simulation of helium hydride cation in a solid-state spin register.
ACS Nano, 9:7769–7774.
[Wendin, 2017] Wendin, G. (2017). Quantum
information processing with superconducting circuits: a review. Reports on Progress
in Physics, 80(10):106001.
[Williams, 2011] Williams, C. P. (2011).
Quantum Gates. In:
Explorations in
Quantum Computing. Springer London.
[Wootters and Zurek, 1982] Wootters, W. K.
and Zurek, W. H. (1982). A single quantum
cannot be cloned. Nature, 299(5886):802–
803.
28
www.kth.se
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )