How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a...

35
Report Simulation Sciences Seminar How to solve a linear system of equations using a quantum computer Philipp Schleich Matricel number: 391779 July 11, 2019 ϕ θ x y z = |0i -z = |1i |ψi Supervisor: Prof. Dr. Benjamin Stamm

Transcript of How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a...

Page 1: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

ReportSimulation Sciences Seminar

How to solve a linear system of equationsusing a quantum computer

Philipp SchleichMatricel number: 391779

July 11, 2019

ϕ

θ

x

y

z = |0〉

−z = |1〉

|ψ〉

Supervisor: Prof. Dr. Benjamin Stamm

Page 2: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

Contents

Abstract

This seminar report gives a short summary on the capababilty of quantumcomputers to solve linear systems of equations. An introduction in quantumcomputing will be given before discussing the building blocks of the HHLalgorithm proposed by Harrow, Hassadim and Lloyd in 2009. At last, it willbe discussed on a 4x4 system, and a outlook on advanced topics like theerror analysis on it will be provided.

Contents

1 Introduction 3

2 Basic concepts of quantum mechanics and quantum computing 42.1 Quantum mechanics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2 Quantum computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.2.1 Qubits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.2.2 Quantum circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.3 Some examples of physical realizations . . . . . . . . . . . . . . . . . . . 16

3 The HHL algorithm 173.1 The problem statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.2 The big picture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.3 Important subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3.3.1 Hamiltonian Evolution . . . . . . . . . . . . . . . . . . . . . . . . . 183.3.2 The Quantum Fourier Transform and the phase estimation proce-

dure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203.3.3 How to invert a number on a quantum-computer . . . . . . . . . 23

3.4 Putting everything together - the HHL algorithm . . . . . . . . . . . . . . 253.5 Application on a low-dimensional example . . . . . . . . . . . . . . . . . 28

4 Additional remarks on the HHL algorithm 31

5 Conclusions and outlook 33

References 34

2

Page 3: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

1 Introduction

1 Introduction

Solving linear systems of equations is task that arises in all areas of science, engineeringor economics. It is one of the tasks, that are known for a long time, well understood, butstill tedious to solve, especially for large systems. Usually, the goal is to increasinglylarger as this in some manner gives more insight in the underlying problem. Whensolving partial differential equations, this means better accuracy, when dealing withmachine learning applications this allows to use more data to improve the model. Butsolving these problems typically has cubic complexity (Gauss-Elimination), in the bestcases it is linear (Conjugate Gradient for symmetric positive definite matrices). Thus, ifone wants to go to even larger amounts of data, larger systems, one might want to lookinto a different direction.

Quantum computing is currently one of the fastest changing fields with a lot of po-tential, that might disrupt the landscape of computing as of today. It promises a lotof fancy, yet almost magic features such as teleportation of information. On the otherhand, one of the biggest advantages of quantum computers is the capability to storeand operate on exponentially more data than the units of information it consists of.Therefore, it might be a promising candidate to approach these high-dimensional prob-lems. Apart from that, it has the potential to be a game-changer in artificial intelligenceor computational quantum physics/chemistry.

In the following, a short introduction into quantum mechanics aswell as quantumcomputing will be given. Then, the linear system that we want to solve is introduced,and the conceptual idea of the algorithm by Harrow, Hassadim and Lloyd [HHL09] isstated. Afterwards, the subroutines necessary to implement the algorithm on a quan-tum computer are explained and assembled to the HHL algorithm. Finally, an applica-tion to a very specific linear system is discussed. The report is closed by a few additionalremarks on further topics and a conclusion.

3

Page 4: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

2 Basic concepts of quantum mechanics and quantumcomputing

In order to be able to study algorithms for quantum computers, one needs to be fa-miliar with certain concepts in quantum mechanics and their extension on quantumcomputing.

2.1 Quantum mechanics

At first, some technicalities of quantum systems will be introduced before discussingthree of the postulates of quantum mechanics. The latter will then allow to make thetransition to quantum computing.

Quantum mechanics describes our world in a framework that holds also on the nano-scale. Meaning, quantum mechanics allows us to study the behaviour of buildingblocks of matter, such as molecules, atoms, nuclei and elementary particles.

In a quantum system, the particles obey the Schrodinger equation, which was postu-lated in 1925 by Erwin Schrodinger:

ih∂

∂tψ = Hψ (1)

where i2 = −1 stands for the imaginary unit, h denotes the so called Planck’s con-stant, H represents the Hamiltonian operator (which is a respresentation for the sys-tem’s total energy) andψ is the wavefunction. The latter is a function of space and timeψ(x1, . . . , xi, , . . . , xN, ; t) and describes the state of a N-particle system.

As the Schrodinger equation (1) is linear, it allows several interesting properties, ofwhich the most important for the problem dealt with here is superposition. Thus, ifψ1,ψ2 solve (1), so does αψ1 +βψ2,α,β ∈ C.

Further, we shall introduce bracket or Dirac notation, where |ψ〉 denotes our wave-function and 〈ψ| a linear functional, and we define 〈ψ|φ〉 as the inner product betweenthe two states.

〈ψ|φ〉 =∫

R3Nψ∗φdx1 . . . dxN (2)

4

Page 5: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

The so called Born-rule states, that 〈ψ|ψ〉 =∫

R3N|ψ(x; t)|2dx1 . . . dxN describes the

probability of finding our N-particle system in state |ψ〉 given x and t. This requiresthat 〈ψ|ψ〉 = 1 and thus, ψ has to be square-integrable, meaning ψ ∈ L2(R3N;C). Asthe Hamiltonian operator H in (1) typically contains a second derivative, one usuallyrequiresψ ∈ H1(R3N;C) s.th. the derivative is defined at least in the weak sense. This isalso called the form domain of H. To be more precise, as one is looking for normalizedfunctions with 〈ψ|ψ〉 = 1, these are equivalence classes with the equivalence relationψ ∼ αψ, for some α ∈ C\{0}.

This can all be translated into a discrete setting. Then, |ψ〉 do not anymore representfunctions but vectors, which now live in a finite-dimensional vector space, that is still aHilbert space (more about that in first postulate). The adjoint of |ψ〉 now is the adjointvector, 〈ψ| = ψ† = (ψ∗)T . The inner product 〈ψ|φ〉 thus reads ψ†φ =

∑iψ∗iφi. [Kib18;

NC10]Now, three postulates of quantum mechanics1 (following [NC10]) will be introduced,

as we will rely on them later when precising what a physical representation of a quan-tum computer is exptected to fulfil.

1. Any isolated physical system has an associated complex, complete linear spaceequipped with an inner product (i.e. a Hilbert space). This space is called statespace. A system is thus described by its state vector (or state function in the continu-ous case). This vector is a unit vector in the associated space (cf. Born-rule). Also,superposition of states as mentioned above stems from this postulate (linearity ofthe associated space).

2. Unitary transformations describe the evolution of closed quantum systems. Thatmeans, |ψ(t)〉 = U |ψ(t ′)〉, where U depends only on t, t ′. In this case, U is alsocalled the time evolution operator or propagator. This postulate also implies thatclosed quantum systems obey the Schrodinger equation (equation (1)). To seethis, remark that e−

ih Ht is unitary for hermitian H, where t ′ from above is chosen

t ′ = 0.

1There are more postulates, though these three are the most important for the concept of quantum com-puting.

5

Page 6: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

3. Measurements in quantum mechanics are described by a set of Mm measurementoperators, which act on the state space. There is usually a discrete set of possibleoutcomes, where m refers to an element of this set. If the state is |ψ〉, then theprobability to obtain outcomem in a measurement writes

pm = 〈ψ|M†mMm |ψ〉 (3)

Obviously, the measurement operators have to satisfy the so called completenessrelation,

∑mM

†mMm = I, I being the identity, as the sum of the probabilty over

all m outcomes has to sum up to one. This postulate also implies the expecta-tion value of some hermitian operator E (usually called observables, i.e. mea-surable properties of a quantum system such as location, momentum, kinetic en-ergy, total energy), as M†

mMm is hermitian. Say, we have a quantum system thatcan take the states |0〉 and |1〉 in the observable E. Postulate 1 allows therefore|ψ〉 = a |0〉 + b |1〉, where |a|2 + |b|2 = 1 (a,b ∈ C). This leads to an expectationvalue of E as 〈E〉 = 〈ψ|E |ψ〉. The probabilities for the individual measurementoutcomes then can be expressed as p(0) = |a|2 and p(1) = |b|2. It is importanthere to state, that, when measuring this quantum system, the outcome is either 0or 1 in a probabilistic manner. That being said, throughout measurement, a quan-tum system collapses out of the superposition in the measured state. Thus, themeasurement operators are not unitary, as the impact of measurement cannot bereversed.

From here on, every physical constant (such as h) is set to 1.

6

Page 7: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

2.2 Quantum computing

We shall now extend what we know about quantum mechanics to the field of quan-tum information or quantum computing. A computer is a machine, that processes andstores information. Talking about a quantum computer, this machine represents a cer-tain state, manipulates its time evolution and in the end, gives the user the possibilityto take a look at the outcome (or in scientific terms, measure it), while underlying thelaws of quantum mechanics. These three general properties one requires a computer tofulfill can be directly translated to a quantum version of such a machine by means ofthe three postulates introduced before.

Nielsen and Chuang ([NC10]) name in consequence some key properties a quantumcomputer should fulfill:

• Robust representation of quantum information (first postulate)

• Cabability to perform universal family of unitary transformations (second postu-late)

• Preparation of a fiducial initial state

• Measurement of the output

The importance of the first, the third and the last point are quite obvious. In orderto work with a quantum machine, it is important, that the information it encapsulatesdoes not underly any unwanted influence from the surroundings2, that the input stateis known and that we can in some form work with the result of a computation. Thesecond point may not be that obvious, might not be necessary for simple physical re-alization, but is crucial when it comes to extended use: One wants a computer to beable to do any possible calculation, and represented by a sequence of unitary operators.The goal is to have a computer being able to perform a finite number of unitary trans-formations (which in physical realization correspond so some building block), whichthen has the consequence that one only needs a finite number of building blocks thatis able to perform any possible calculation (that can be represented by unitary trans-formations). These individual building blocks are called quantum gates, which eachrepresent a certain unitary transformation.

2Readers interested in further topics of quantum information may want to look into quantum decoher-ence

7

Page 8: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

There exist universal families of quantum gates3, that allow, to write an arbitrary unitaryoperationU up to an accuracy ε in terms of a sequence of a finite number L of membersof an universal family F. That being said, a set of quantum gates F is universal, if thereexists a finite L ∈ N, such that for any unitary operator U ‖U−UFLU

FL−1 . . . U

F1‖ ≤ ε

with some ε > 0. The significancy of this is revealed by the fact, that L = O(log2 (ε−1)),and therefore exponential accuracy is obtained by using only a polynomial number ofgates (Solovay-Kitaev theorem, e.g. [NC10].

Apart from that, it is worth mentioning, that any computation feasible on a classicalmachine is also realizable on quantum computers. Intuitively, this is possible, as theToffoli-gate, which is universal on classical computers, has a direct quantum equivalent.[NC10]

2.2.1 Qubits

Information on classical computers is stored by means of a so called bit as the funda-mental unit of information, while a bit system can have a value x ∈ {0, 1}, which formsthe computational basis. Any integer k can thus be represented in form of a bit string∑Ni=0 ki2

i, whereas a real numbers can be represented up to some decimal precision byadding an integer with some j

2m = 0.jn−m+1 . . . jn. In comparison to that, on quantumcomputers, the qubit is the fundamental unit of information, possible values being |0〉and |1〉. Thus, {|0〉 , |1〉} have to form an orthogonal basis in the associated Hilbert space,C2. Due to the quantum nature of a qubit, it can additionaly take any superposition ofthese 2 values, with the restriction that it is normalized, meaning |ψ〉 = a |0〉 + b |1〉,while |a|2 + |b|2 = 1, a,b ∈ C. Again, to be more precise, |ψ〉 is from the subspace ofC2 modulo the equivalence relation (a,b) ∼ (αa,αb) for some nonzero, complex α. Asqubits are finite-dimensional, there also exits a vector form:

|0〉 =(1

0

), |1〉 =

(0

1

), |ψ〉 = a |0〉+ b |1〉 =

(a

b

). (4)

3We shall not worry about how these look here.

8

Page 9: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

It is also possible, analogeous to the classical bit-string, to represent numbers on aquantum computer, which then of course also requires more than one qubit. Multiplequbits are combined via the tensor product, meaning the joint state of |φ〉, |ψ〉 reads as|φ〉 ⊗ |ψ〉 = |φ〉 |ψ〉, while the last expression is introduced as short notation. Observingthat |φ〉 = a |0〉+ b |1〉 and |ψ〉 = c |0〉+ d |1〉,

|φ〉 ⊗ |ψ〉 = ac |0〉 ⊗ |0〉+ ad |0〉 ⊗ |1〉+ bc |1〉 ⊗ |0〉+ bd |1〉 ⊗ |1〉 (5)

= ac |00〉+ ad |01〉+ bc |10〉+ bd |11〉 .

Here, {|0〉 ⊗ |0〉 , |0〉 ⊗ |1〉 , |1〉 ⊗ |0〉 , |1〉 ⊗ |1〉} form an orthonormal basis of C4 ∼ C2 ⊗C2, corresponding to the computational basis of a 2-qubit system. Introducing vectornotation, the same expression can be rewritten to

|φ〉 |ψ〉 =

ac

ad

bc

bd

. (6)

Extending this to even more qubits, it is easy to see thatN qubits live in a 2N-dimensionalHilbert space, C2

N∼ C2 ⊗ C2 ⊗ · · · ⊗ C2, and thus can represent 2N units of informa-

tion. This is exponentially more than a classical computer can process with the samenumber of bits. But one has to emphasize, that a quantum computer outperforms aconventional one only in processing information. If one is interested in reading outthis information, measurement collapses each qubit in one certain state andN qubits fi-nally only give an output of anN-dimensional bitstring, similar to classical computing.Consider an integer k =

∑2n

l=1 2n−lkl. As a bit-string this writes

k = (k1k2 . . . kn), wherekl ∈ {0, 1}. (7)

The quantum notation is simply

|k〉 = |k1k2 . . . kn〉 . (8)

As an example, k = 3 = 21 + 20 = (11), with its quantum complement |3〉 = |11〉.Decimal numbers are can be represented by division by some approbiate power of 2:

k

2m= 0.kn−m+1 . . . kn. (9)

9

Page 10: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

At this point, the concept of entanglement will be explained briefly on a system oftwo qubits. Let |ψA〉 ∈ HA and |ψB〉 ∈ HB from two Hilbert spaces HA,HB. In thecase of qubit states, these both are C2. The system’s Hilbert space then becomes HA ⊗HB ∼ C4, with the basis {|0〉A ⊗ |0〉B , |0〉A ⊗ |1〉B , |1〉A ⊗ |0〉B , |1〉A ⊗ |1〉B}. A state iscalled factored or separable, if |ψ〉 can be expressed as |ψ〉 = |ψA〉 ⊗ |ψB〉, meaning iscan be decomposed into terms from separate Hilbert spaces, which are combined viathe tensor product. If that is not possible, they are called entangled. An example fora factored state is |0〉A ⊗ 1√

2(|0〉B + |1〉B). A quite famous set of entangled states are

the Bell states, of which the first one is 1√2(|0〉A ⊗ |1〉B + |1〉A ⊗ |0〉B). Multiple-qubit

systems represent in most cases entangeled states.Now, again only a single qubit will be considered, as this will enable us to give a

nice intuition for qubits and a smooth transition to manipulating qubits by qugates. Asingle qubit state |ψ〉 can be represented by (x,y, z, t) on the unit sphere S3 in R4:

C2 → S3 : a |0〉+ b |1〉 7→ (x,y, z, t), (10)

while a = x+ iy and b = z+ it. Furthermore, it is possible to depict (x,y, z, t) as apoint of the sphere S2 in R3 expressed by (r = 1, θ,ϕ). Indeed, up to a global phase4 ,|ψ〉 can be written as

|ψ〉 = cosθ

2|0〉+ eiφ sin

θ

2|1〉 , 0 ≤ θ ≤ π, 0 ≤ ϕ ≤ 2π. (11)

Remember from quantum mechanics, that a state can always only be defined up to aglobal phase, which means we can discard this. The sphere S2 is usually called Blochsphere. Mathematically, the transition to the Bloch sphere can be identified with thecomplex projective line or a Hopf-fibration from the three- to the two-sphere. [Kib18]

Now, if one wants to change the state of this qubit by means of unitary transforma-tions, this can be represented as a rotation around an axis in the Bloch sphere. Forinstance, if |ψ〉 = |0〉, this can be transformed into a |1〉 by a rotation around x by π.This is further discussed in the next section.[Der+18; EHI00; NC10]

4Here, we do not talk about the parameter ϕ. This is a local phase and necessary to describe the state.

10

Page 11: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

ϕ

θ

x

y

z = |0〉

−z = |1〉

|ψ〉

Figure 1: Bloch sphere

2.2.2 Quantum circuits

Being familiar with qubits, it is no possible to take a step further and look at how onecan manipulate their states in order to perform computations. In accordance to classicalgates, these parts are calles qugates on quantum computers. Conventional computersperform arbitrary computations using a finite sequence of logical gates, such as AND,OR, XOR. Qugates represent unitary transformations on a quantum state, and thusenable the user to evolve the quantum system that is represented by the computersqubits.

Single-qubit gates To begin, consider a one-qubit system (figure 1). As already men-tioned, unitary transforms on a single qubit can be represented by rotations around anaxis in the Bloch sphere. This again can be decomposed into single rotations aroundthe three axes x,y, z. It turns out, that the Pauli matrices, which for instance arise whendescribing the spin of quantum-mechanical particles, exactly correspond to rotationsaround these axes by π/2:

σx = X =

(0 1

1 0

),σy = Y =

(0 −i

i 0

),σz = Z =

(1 0

0 −1

). (12)

One can assure oneself, that this holds, if one applies the Pauli matrices to the expres-sions from equation (4) and writes the state as in equation (11).

11

Page 12: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

The Pauli gates can aswell be used to implement rotations of an arbitrary angle. Tosee this, remark that Ri(θ) = exp(−iθσi). As an example, using X in the previousexpression yields

exp

(−iθ

(0 1

1 0

))= I2 − iθX−

θ2

2I2 − i

θ3

6X+ · · · = (13)

= cos θI − i sin θX =

(cos θ −i sin θ

−i sin θ cos θ

)≡ Rx(θ).

Moreover, recognize, that the quantum X-gate corresponds to the classical NOT-gate.Simply apply X in matrix-form on a state |ψ〉, which gives |0〉 X

−→ |1〉 and |1〉 X−→ |0〉.

Another important gate is the Hadamard-gate, which represents the so called Hadamard-transform. It can be represented in matrix-form as

H =1√2

(1 1

1 −1

). (14)

Elementary algebra reveals the following relations:

H |0〉 = |+〉 = 1√2(|0〉+ |1〉) and H |+〉 = |0〉 (15)

H |1〉 = |−〉 = 1√2(|0〉− |1〉) and H |−〉 = |1〉 . (16)

Remark that an additional application of the Hadamard transformH(H |ψ〉) = H2 |ψ〉 =I |ψ〉 returns the initial state. The Hadamard transform is closely related to the Fouriertransform, whose quantum counterpart will be introduced later.

Apart from the gates introduced above, there is a whole zoo of single-qubit opera-tions. But as they basically all only represent some rotation around an axis in the Blochsphere, and as for the means understanding how to solve a linear system on a quantumcomputer, the already mentioned gates are sufficient. [Kib18; NC10]

12

Page 13: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

Controlled unitary operations Often, it is necessary, that certain operations only takeplace, if some condition is fulfilled. Quantum information allows such a construct inthe form of so called controlled or conditional gates.

First, take a look at a classical way to express this:

i f ( express ion = true ) :do work

e l s e i f ( express ion = f a l s e ) :do nothing

This can be translated to quantum conditioned gates, with a subtle difference. Whereason in conventional computing, the work is either done or not done at all, a controlledunitary gate acts only on the |1〉-part of a state, as superpositions are possible. As a firstexample, the CNOT-gate is introduced, which leaves the |0〉-part as is and applies a NOT-operation on the |1〉-part. In matrix notation for the previously defined computationalbasis of a two-qubit system, this reads

CX =

1 0 0 0

0 1 0 0

0 0 0 1

0 0 1 0

, (17)

which can be recognized as a permutation matrix that swaps the lower entries whenacting on a vector. And indeed, when applying (17) on the two-qubit system in (5) and(6), one obtains

CX |φψ〉 =

1 0 0 0

0 1 0 0

0 0 0 1

0 0 1 0

ac

ad

bc

bd

=

ac

ad

bd

bc

= ac |00〉+ ad |01〉+ bd |10〉+ bc |11〉 .

(18)This means, CX acts conditioned on |φ〉. If 0, corresponding to the a-part, then nothinghappens. If 1, which corresponds to b, then the X-gate is applied on |ψ〉.

13

Page 14: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

As a second example, controlled y-rotation is discussed. Recall that a y-rotationaround an arbitrary angle θ ∈ R can be expressed as Ry(θ) = exp (−iθσy).

Ry(θ) =

(cos θ − sin θsin θ cos θ

)(19)

We denote the conditioned y-rotation around an angle θ as Uθ, which is the d-finiteapproximation5 of θ:

Uθ : |θ〉 |0〉 7→ |θ〉(cos θ |0〉+ sin θ |1〉

)(20)

|θ〉 |1〉 7→ |θ〉(− sin θ |0〉+ cos θ |1〉

)Thus,

Uθ = |θ〉 〈θ|⊗ exp(−iθσy) (21)

This can be shown in a straightforward manner by the matrix notation of Ry in (19) andthe vector notation of the basis |0〉, |1〉. The left part of (21) acts as the identity on |θ〉,the right part rotates the input vector then around y by θ. [Der+18]

Quantum circuits Let us here introduce shortly the notion of quantum circuits. Theyare graphical representations of a quantum algorithm, read from the left to the right. Onthe very left, the individual qubits (or, if one wants to summarize a collection of qubits,such as when approximating a real number by a bit string), the quantum registers canbe found. From there on to the right, there is a line, called a wire, that describes theevolution of the register during computation. On this wire, one can apply unitary op-erations at a certain point, by means of quantum gates. The gates from the equations 12and 14 depicted in a quantum circuit can be found in figure 2.

5i.e. using d qubits

14

Page 15: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

|0〉 X |1〉⇒ p(|0〉) = 0,p(|1〉) = 1

|0〉 Y |i〉⇒ p(|0〉) = 0.5,p(|1〉) = 0.5

|0〉 Z |0〉⇒ p(|0〉) = 1,p(|1〉) = 0

|0〉 H1√2(|0〉+ |1〉) ⇒ p(|0〉) = 0.5,p(|1〉) = 0.5

Figure 2: The introduced single qubit gates in a quantum circuit with measurement inthe end; probabilites assuming the states are coherent and not perturbed (e.g.through measurement errors)

The quantum circuit notation thus combines the demands we put on a quantum com-puters: Quantum bits or registers are written under each other, and represent the state.The direction to the right along the wire, unitary transformations take care of the timeevolution of the states. Finally, the state is measured (and thereby transferred to someclassical information, which is illustrated by the double-line wire). A crossed wire rep-resents a wire bundle, which means that the associated state consists of multiple qubits.

The CX-gate discussed in the previous section is shown in figure 3a. Another use-ful gate is the SWAP-gate, which is able to exchange the states of two single qubits. Itsgraphical representation is depicted in figure 3b. Its matrix notation in the usual com-putational basis is represented by

SWAP =

1 0 0 0

0 0 1 0

0 1 0 0

0 0 0 1

(22)

|φ〉

|ψ〉

(a) Depiction of a CNOT-gate, correspond-ing to equation (18)

|0〉 |1〉

|1〉 |0〉

(b) Depiction of a SWAP-gate, correspond-ing to equation (22)

Figure 3: Selected multiple-qubit gates

[Der+18; EHI00; Kib18]

15

Page 16: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

2 Basic concepts of quantum mechanics and quantum computing

2.3 Some examples of physical realizations

In this section, a few ideas on how quantum computers can be realized in practice arementioned very briefly. The goal is just to give the reader a conceptual idea. Detailedexplanations, including advantages and disadvantages, can be found e.g. in [NC10].

• Harmonic oscillator quantum computer

– n qubits via energy levels |0〉 , |1〉 , |2n〉 of a single quantum oscillator

– Unitary evolution via matching the eigenvalue spectrum of the unitary op-erators with those given by the system’s Hamiltonian

– Just conceptual, so no initial state preparation or readout considered

• Optical photon quantum computer

– Location of a single photon between two modes |01〉 , |10〉 or polarization

– Unitary evolution via so called phase shifters (Rz rotations) and beam split-ters (Ry rotations)

– Initial states via creation of single photon states (e.g. lasers)

– Readout via detection of single photons

• Trapped ion quantum computers

– Qubits represented by nuclear spin (so called hyperfine states) of an atom orlowest level vibrational modes of trapped atoms

– Unitary evolution can be realized by application of laser pulses

– Initial state can be created by cooling down atoms to motional ground state

– Readout by measurement of the population of the hyperfine states

• . . . and more

The optical quantum computer has the advantage, that it does not need cooling totemperatures close to absolute zero as for instance trapped ion quantum computersneed. On the other hand, they are much delicate when it comes to decoherence, andneed to operate in far shorter time scales.

16

Page 17: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

3 The HHL algorithm

We already know, that everything, a classical computer is capable of, also the quantummachine can do. And further, arithmetic manipulations can be implemented efficiently.Thus, one might think of using fast classical solution schemes, e.g. Krylov methodssuch as GMRES or Conjugate Gradient, to solve this problem on a quantum computer.And possibly, there might be some speed-up. But this is not the point of using a quan-tum computer to approach the problem. As we know by now, the quantum natureof these machines (including concepts such as the superposition of states or entangle-ment) enables the user to approach problems in ways, that are not possible on classicalcomputers. Thus, we will look into an algorithm that exploits the quantum nature toget significant (as it turns out, exponential) speedup over the best classical alternative.

In this section, the general problem statement is introduced, which will be followedby a few elementary building blocks we shall later need to assemble the HHL algo-rithm. Then, being familiar with the basic idea, we will look into how one could applythis algorithm onto solving a (very) specific, small example, following [Cao+12]. Fi-nally, an overview will be given over the results of error and complexity analysis of thealgorithm aswell extensions of it.

3.1 The problem statement

The problem statement of our linear system can be written as

Ax = b, (23)

where A ∈ RN×N, x,b ∈ RN, and A hermitian, i.e. A† = A. To solve (23) on a quantummachine, it has to be written in terms of a quantum state:

A |x〉 = |b〉 , (24)

where |x〉 = x‖x‖ , |b〉 =

b‖b‖ . Additionally, A is required to be sparse. This is not neces-

sary for the algorithm to give results, but it is required for the speedup with respect tothe best classical alternative holds. This will be further discussed in section 4.[Der+18; HHL09]

17

Page 18: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

3.2 The big picture

Now take a look at equation (24) from a different perspective. For A hermitian, onecan write A =

∑Nj=1 λj |uj〉 〈uj|, where λj ∈ R are eigenvalues, and |uj〉 ∈ RN the

respective eigenvectors. Alongside, the right-hand side can be expressed as |b〉 =∑Nj=1 |uj〉 〈uj|b〉 =

∑Nj=1 βj |uj〉. Now, as the system matrix is avaible in diagonal form,

the solution to (24) can be easily computed:

|x〉 = A−1 |b〉 =N∑j=1

βj

λj|uj〉 . (25)

Thus, if there were quantum routines, that allow to give the spectral decompositionof the system matrix and apply the inverted eigenvalues on the right-hand side, thiswould be a first idea for a linear systems algorithm. And indeed, Harrow, Hassadimand Lloyd proposed such an algorithm in [HHL09], and furthermore proved, that it isin some sense optimal and cannot be improved significantly.

3.3 Important subroutines

At this point, the key subroutines of the linear systems algorithms will be presentedsubsequently, without any relation to each other. This has the aim to give the reader aunderstanding on how these algorithms work, such that the actual algorithm later canbe read somewhat fluently and details can be looked up here.

3.3.1 Hamiltonian Evolution

Hamiltonian evolution or simulation refers to the second postulate proposed in sec-tion 2.1. Recall (1)

i∂t |ψ〉 = H |ψ〉 , (26)

then the time evolution of the state |ψ〉 can be expressed as

|ψ(t)〉 = e−iHt |ψ〉 . (27)

On one hand, observe, that e−iHt is unitary6. Hence, every unitary operatur U canbe written in terms of eiH for some hermitian H. This fact will be interesting whenintroducing the phase estimation procedure.

6This can easily be showed by the fact, that H is hermitian and the definition of the matrix exponential.

18

Page 19: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

|p〉register L eiHt0

|s〉register M

Figure 4: Conditional Hamiltonian simulation

For the purposes of this report, we shall not further worry about what e−iHt looks likewhen implemented on a quantum computer. Interested readers are referred to the liter-ature (either a textbook such as [NC10], and also [Der+18] gives a good introduction tothis topic). Remember, that by means of a universal family of quantum gates, it is possi-ble, to write an arbitrary unitary operation in terms of a sequence of these fundamentalgates. What usually is done now, is to find such an approximation for a unitary oper-ation by a sequence of gates via an optimization algorithm, such as the Group Leaderalgorithm [DK11] – which in the following will be assumed to be done, whenever anon-elementary transformation such as Hamiltonian evolution is encountered.

Hamiltonian simulation can be implemented efficiently for large N, if the systemmatrix (here: H) is sparse [Der+18]. This is the only subroutine, where sparsity on thesystem matrix actually is required in order to get the full speedup of the HHL algo-rithm.

Before moving on to the next routine, conditional Hamiltonian simulation will be de-scribed. Consider a quantum circuit as in figure 4. There are two registers L andMwithl,m qubits respectively. Starting with a state of

∑2l−1λ=1

∑2m−1µ=1 |pλ〉 |sµ〉 (pλ, sµ ∈ {0, 1}),

Hamiltonian simulation via exp (iHt0) conditioned on registerM yields

2l−1∑λ=1

2m−1∑µ=1

|pλ〉 |sµ〉exp (iHt0)−→ 2l−1∑

λ=1

2m−1∑µ=1

eiHt0sµ |pλ〉 |sµ〉 . (28)

Observe, that the Hamiltonian simulation is applied if |sµ〉 = |1〉, if not the exponentialis 1 and for any |sµ〉 = |0〉, the state is left as is. As this notation is rather cumbersome,we will omit the indices λ,µ in most cases from now on, and write the sum over s,p.Although this is abuse of notation, we will keep in mind, that in a

∑i |i〉, in general, the

state |i〉 for ith summand corresponds to the bitstring in binary notation up to the ithentry. For instance, in equation (33), this relation is visible between the third and fourthexpression.

19

Page 20: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

3.3.2 The Quantum Fourier Transform and the phase estimation procedure

QFT The discrete Fourier transfrom writes as

DFT : yk → 1√N

N−1∑n=0

e2πiN knxn (29)

DFT† : xn → 1√N

N−1∑n=0

e−2πiN knyk. (30)

Remark that the Fourier basis states are orthogonal, which means that the Fourier trans-formation itself is a unitary transformation. One can see this, as the adjoint of the DFToperator is indeed the inverse. This means, that the quantum analogue, the QFT, canbe implemented by a sequence of elementary quantum gates.

The Quantum Fourier transformations can be analogeously written as

QFT : |j〉→ 1√N

N−1∑k=0

e2πiN jk |k〉 (31)

QFT† : |k〉→ 1√N

N−1∑j=0

e−2πiN jk |j〉 . (32)

Now, we take N = 2n and look at some integer k =∑2n

l=1 2n−lkl, while we denote

this as k = k1k2 . . . kn, fractions of this are written as k2m = 0.kn−m+1 . . . kn. Further,

assume, that |0〉 . . . |2n−1〉 is a basis on our quantum computer. Performing the Fouriertransform, a straightforward calculation or a look in [NC10] reveals

|j〉 = |j1 . . . jn〉QFT−→ 1

2n/2

2n−1∑k=0

e2πiN jk |k〉 = 1

2n/2

1∑k1=0

· · ·1∑

kn=0

e2πiN j(

∑nl=1 kl2

−l) |k1 . . . kn〉

(33)

= . . .

=1

2n/2

(|0〉+ e2πi 0.jn |1〉

) (|0〉+ e2πi 0.jn−1jn |1〉

)· · ·(|0〉+ e2πi 0.j1j2...jn |1〉

)QPE An important application of the QFT is the phase estimation procedure (QPE).The name phase estimation comes from the fact, that the eigenvalues of a unitary op-erator U can be written as U |uj〉 = λj |uj〉 = e2πiϕj |uj〉. The phase estimation there-fore is able to determine ϕj ∈ [0, 1], or more precisely, to get an n-bit approximationϕj ≈ ϕj = 0.ϕj,1ϕj,2 . . . ϕj,n.

20

Page 21: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

. . .

. . .

. . .

. . .

. . .

|0〉⊗tClock register

H

QFT† |ϕj〉H

H

H

|ψ〉State register U1 U2 U4 U2

t−1 |ψ〉

Figure 5: Quantum phase estimation circuit

Two registers, one of size t prepared in the |0〉⊗t state, and one with m qubits, |ψ〉 ∈C2

m, of which we assume for now, that it is an eigenvector of U. The notation |0〉⊗t

means, that t qubits of the same state are combined together with the tensor product,|0〉 ⊗ · · · ⊗ |0〉. The choice of t depends on how accurate one wants to represent theeigenvalues and on the desired probability of success of the procedure. The next stepis to apply a Hadamard-transform on the t qubits to create a superposition of states.Formally,

|0〉⊗t |ψ〉 H⊗n⊗I−→ 1

2t/2(|0〉+ |1〉)⊗t |ψ〉 . (34)

Now, the controlled U2k-operation is applied. Meaning, U2

0conditioned on the first

qubit in the first register operates on the second register, U21

conditioned on the secondqubit on the first register, and so on until U2

t−1.

Remembering that U |ψ〉 = e2πiϕ |ψ〉, we end up with the following expression for thefirst register. This can be identified with the QFT, when comparing with (33).

1

2t/2

(|0〉+ e2πi 2t−1ϕ |1〉

) (|0〉+ e2πi 2t−2ϕ |1〉

)· · ·(|0〉+ e2πi 20ϕ |1〉

)(35)

=1

2t/2

(|0〉+ e2πi 0.ϕt |1〉

) (|0〉+ e2πi 0.ϕt−1ϕt |1〉

)· · ·(|0〉+ e2πi 0.ϕ1ϕ2...ϕt |1〉

)=1

2t/2

2t−1∑k=0

e2πiϕk |k〉

21

Page 22: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

|0〉⊗tclock register

H QFT†

|ψ〉state register U2

k

Figure 6: Phase estimation procedure

Applying the inverse QFT, one obtains for the full state:

1

2t/2

2t−1∑k=0

e2πiϕk |k〉 |ψ〉 QFT†

−→ 1

2t

2t−1∑x=0

2t−1∑k=0

e−2πik2t

(x−2tϕ)|x〉 |ψ〉 . (36)

This is expression peaks near x = b2tϕc. The reason therefore is, that sums like∑M−1k=0 e

2πikx/M are zeros except x is integer-divisible by M. If x is an integer, thex = 2tϕ, and |2tϕ〉 |ψ〉 can be obtained by measurement with high probability. If xis not an integer, this measurement has to be repeated, for which an upper bound ofrepetitions until success can be derived [NC10]. Recall, that we represent ϕ only by ant-bit approximation ϕ ≈ ϕ =

∑tm=1ϕm2

−m. We will keep the tilde-notation for binaryapproximations from now on, and only express the sum explicitly, if the number ofqubits used is not clear from the context.

At this point, recall the fact, that the Hamiltonian evolution operator e−iHt is unitary.Furthermore, e−iHt |uj〉 = e−iλjt |uj〉. Thus, substituting U in the QPE by the evolutionoperator, gives an estimation of the Hamiltonian H, or in general, any hermitian ma-trix. The first register from before is in this case usually called the clock register, as it isresponsible for the time evolution.

A physical intuition can be given via the von Neumann scheme of measurement.[Q] Here, consider the first register as a ”pointer” register (basically the clock above),which we continue to call clock register for reasons, that will get clearer in a moment.Further, denote, that an application of the momentum operator p ”pushes” the stateforward in time. The idea now is, to ”push” the pointer register, such that it contains theeigenvalues. Pointer and system have the initial state |0〉 |uj〉, and undergo the unitarytransformation e−itp⊗H, which gives the final state |λjt〉 |uj〉. It turns out, that translatinge−itp⊗H |0〉 |uj〉 to a quantum computer gives exactly the QPE-scheme [Q]7.

7The IBM Q-Experience website has been rebuilt during the work on this report. Under the suppliedlink, you still find the derivation via the von Neumann measurement, the new site provides the same

22

Page 23: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

|0〉⊗lregister L

H Rzz |λ−1〉

|0〉⊗mregister M

H eiH0t0 |garbage〉Input |λ〉register I

|λ〉

Figure 7: Quantum circuit to invert a number

An interesting fact for the linear systems algorithm is, that one does not need to haveaccess to an eigenvector |uj〉. Any quantum state can be decomposed into an arbitrary,orthogonal basis, which here will be chosen to be the eigenbasis of the unitary operatorU:

|ψ〉 = I |ψ〉 =∑j

|uj〉 〈uj|ψ〉 =∑j

βj |uj〉 . (37)

To wrap up, the QPE-procedure applied to an arbitrary state |ψ〉 yields

|0〉 |ψ〉 =∑j

βj |0〉 |uj〉QPE−→ ∑

j,k

αj,kβj |ϕk〉 |uj〉 , (38)

where αj,k is a preconstant resulting from the QPE-procedure. If the QPE is perfect,αj,k = 1 and |ϕk〉 = |λj〉, which we assume in this report.[Der+18; NC10]

3.3.3 How to invert a number on a quantum-computer

The QPE gives the eigenvalues of the system matrix, but as we shall see, it is required,that the inverse eigenvalues λ−1j are available. Usually, in papers that do not deal withthe implementation but only with the algorithm, this is omitted, as one can show, thatarithmetic manipulations on a quantum machine can be achieved easily [Bac06].

To give an idea, the way to invert the eigenvalues proposed in [Cao+12] will be ex-plained briefly.

Figure 7 shows the quantum circuit of the algorithm. Input is a state |λ〉with T qubits,containing one or also possibly multiple numbers one wants to invert. Apart from that,register L contains l and registerM containsm qubits.

derivation as [NC10]

23

Page 24: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

Here we assume, that |λ〉 is available from a previous computation. The outcomeof register M is not further needed and therefore a so called |garbage〉-state, that wasproduced along the way when aiming for some other outcome.

The algorithm starts with a Hadamard-transfrom of the with |0〉 initialized registersL and M. Then, a conditional phase shift Rzz on register L is applied, which results inthe state

2l−1∑s=0

2m−1∑p=0

eip2mt0 |s〉L |p〉M |λ〉I . (39)

Superscripts over the quantum states denote to which register they relate to. Thenext step is the Hamiltonian evolution eiH0t0 of M conditioned on L and I. Here,H0 = diag(1, 2, . . . 2m−1), which is clearly hermitian. The double conditioning can beinterpreted as follows: The klth qubit of L aswell as the jth eigenvalue of I8 controls a

e−ip(

λj2m

1

2l−klt0) simulation acting onM. The final state thus reads

n∑j=1

2l−1∑s=0

2m−1∑p=0

ei p

2m+l t0(2l−λjs) |s〉L |p〉M |λj〉I . (40)

Note the color coding to recognize the conditioning relations better.Using t0 = 2π, the final state is sharply peaked for states, when s = 2l

λj.

Writing the register L as | 2l

λj〉, one can observe, that the algorithm yielded the desired

inverse up to a known constant.[Cao+12]

8This again is in some sense abuse of notation, but makes the relations quite clear. If one wants to bemore precise, the eigenvalues can be decomposed in binary form, which then also alters the upperlimit for the sum over j. But if the eigenvalues were as in3.5, the given expression would be true, andthe control would actually act on the jth qubit.

24

Page 25: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

3.4 Putting everything together - the HHL algorithm

Now, it is possible to assemble the steps to the linear systems algorithm, which is de-picted in figure 8. One starts off with some initial state |initial〉, and assuming thatthere exists a unitary operation B, that can prepare the input |b〉I efficiently, one ob-tains the latter state. Efficiently means here, such that it does not harm the complexityof O(logN) in the end. This can be for instance achieved by the qRAM suggested in[Der+18]. Any errors in creation of the input state are neglected. The algorithm startswith the phase estimation procedure, for which the clock register should be preparedin the state

|Ψ0〉C =

√2

T

T−1∑τ=0

sin (π(τ+ 1

2)

T) |τ〉C , (41)

which minimizes a certain cost function [BDM99]. The reason for preparing the clockin a manner that is optimal in some sense, is that the pre-constant resulting of phaseestimation as in (38) can be bound from above, which turns out to be very useful inthe error analysis of the algorithm. This can be done in polylogarithmic time [GR02].T is the number of computational steps, that is needed, to compute the Hamiltonianevolution eiAt for 0 ≤ t ≤ t0, when A is sparse. Thus, t0T corresponds to the step size ofthe Hamiltonian simulation.

The next step is the phase estimation procedure, while here, the eigenvalues of theunitary eiAt are the subject of desire. As A is hermitian, eiAt is unitary with eiAt |uj〉 =eiλjt |uj〉, while λj are also eigenvalues of A. Applying

∑T−1τ=0 |τ〉 〈τ|

C ⊗ eiAτt0/T condi-tional on the clock register, the registers C and I read

|Ψ0〉C |b〉I∑T−1τ=0 |τ〉〈τ|

C⊗eiAτt0/T

−→ √2

T

N∑j=1

βj

(T−1∑τ=0

eiλjτt0T sin (

π(τ+ 12)

T)

)|uj〉I . (42)

The inverse QFT yields

(42) QFT†

−→ N∑j=1

βj

T−1∑k=0

(√2

T

T−1∑τ=0

eiτT (λjt0−2πk) sin (

π(τ+ 12)

T)

)︸ ︷︷ ︸

:=αk,j

|k〉C |uj〉I (43)

For the following, we will abbreviate the bracket expression in (43) with αk,j ∈ R. Onecan show, that αk,j ≤ 8

π2, which is important for the error analysis of the algorithm.

Further, the upper bound holds whenever |k− λj t02π | ≥ 1. αk,j is large only if λj ≈ 2πkt0

.Now, we rename the states in the clock register to this expression, namely λj ≈ 2πk

t0.

25

Page 26: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

The current state in numerical approximation (tilde-notation) can thus be written as

N∑j=1

βj

T−1∑k=0

αk,j |λk〉C|uj〉I , (44)

as λ depends also on k. At this point, an arbitrary algorithm to invert for the eigen-values can be applied, such as the one proposed in [Cao+12]. To keep things simplerhere, assume, register C now contains the inverse eigenvalues (or, to be more exactly, astate proportional to the inverse eigenvalues). As already mentioned, this is the usualprocedure in the literature, as arithmetic on quantum states can be accomplished easily.

Now, an ancilla register is adjoined, which is initialized in the state |1〉S. A Ry(θ)

rotation conditioned on register C is applied, again assuming that C now contains theinverse eigenvalues. Now conditional y-rotation around θ = −γλ−1k ,γ ∈ R as in 21 willbe applied (recalling the results of section 3.3.3 θ = 2lλ−1k ). This results in

N∑j=1

βj

T−1∑k=0

αk,j |1〉S |λ−1k 〉C|uj〉I

Ry(λ−1k )

−→ N∑j=1

βj

T−1∑k=0

αk,j

(√1−

γ2

λ2k|0〉S + γ

λk|1〉S

)|λ−1k 〉

C|uj〉I . (45)

If the phase estimation was perfect, αk,j = 1 for λk = λj, which we assume in this report.The state can thus be written as

N∑j=1

βj

(√1−

γ2

λ2j|0〉S + γ

λj|1〉S

)|λ−1j 〉

C|uj〉I . (46)

Now, the end is almost in sight, although we are not yet finished.As the current state between the individual qubits and registers is entangled, a mea-

surement in one register is highly compromitted by the others, if their content is notneeded anymore9. This is the case for the clock register containing the (inverse) eigen-values at this point. As there is no possibility in quantum computing, to simply deletethe information, a procedure called uncomputation is used.

9When measuring, one has to capture the whole state of all registers combined (via the tensor product).This means, that each state, that is in a superposition, contributes to the system’s global probabilitydistribution. Thus, it is highly advantageous to set the states one is not interested in to |0〉. |1〉 wouldalso be possible, but the former is practically easier to achieve.

26

Page 27: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

QPE Ry(λ−1) Uncomputation

Ancilla |1〉register S

Ry |1〉

Clock |0〉⊗nregister C H⊗n QFT† QFT H⊗n |0〉⊗n

Input |b〉register I U U† |x〉

Figure 8: HHL algorithm, subdivided in QPE (quantum phase estimation) to determinethe eigenvalues, controlled rotation Ry to ”extract” the eigenvalue informationand uncomputation to revert the phase estimation

This can be achieved by an application the adjoint of the unitary transformation sofar , which corresponds to undoing all computations. Thus, the clock register can be setback to |0〉C this way. Recall the note on entanglement in section 2.2.1, in particular theexamples for factored and entangled states. One can see, that after uncomputation, afactored state can be achieved.

The final step is a measurement on the Ancilla register, while postselecting on |1〉.This can be expressed by a projection onto the |1〉-subspace of the register S, thus dis-carding the |0〉-part:

(46)|1〉〈1|S−→ N∑

j=1

βj

(√1−

γ2

λ2j〈1|0〉+ γ

λj〈1|1〉

)|1〉S |0〉C |uj〉I (47)

Finally, the solution to A |x〉 = |b〉 up to a (known, global) constant factor γ is obtainedin re-normalized form in the input register:

|x〉 = 1√∑Nj=1 γ

2β2j/λ2j

N∑j=1

γβj

λj|uj〉I . (48)

27

Page 28: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

Ancilla |1〉register S

Ry(24

λ1) Ry(

24

λ2) Ry(

24

λ3) Ry(

24

λ4) |1〉

Clock |0〉⊗4register C

H

QFT†

U†

|0〉⊗4H

H

H

Input |b〉register I eiA

2π16

20

eiA2π16

21

eiA2π16

22

eiA2π16

23 |x〉

Figure 9: HHL algorithm for a specific 4-dimensional system; U† includes uncompu-tation of the QPE aswell as of the swap-gate. Observe, that the conditionedrotation on 4 qubits needs to be decomposed according to the eigenvalues

3.5 Application on a low-dimensional example

The linear systems algorithm shall now be applied to a very specific 4× 4-system after[Cao+12]. In the beginning, let us take a look at the quantum circuit.

The system that will be solved for has the form of equation (24), while

A =1

4

15 9 5 −3

9 15 3 −5

5 3 15 −9

−3 −5 −9 15

(49)

and the right-hand side

|b〉 = 1

2(1, 1, 1, 1)T . (50)

First, one can see, that A is real and symmetric, thus also hermitian. Secondly, it justhappens to be, that the eigenvalues of A are λj = 2j−1, j = 1, . . . , 4 with the correspond-ing eigenvectors |uj〉 = 1

2

∑4i=1(−1)

δij |i〉C, i.e. |u1〉 = 12 (− |0001〉+ |0010〉+ |0100〉+ |1000〉).

Now, observe that |b〉 can be rewritten as |b〉 =∑4j=1 βj |uj〉, while βj = 1

2 for allj = 1, . . . , 4. This means, the input register can be prepared by starting with |0〉⊗2,and applying a Hadamard-gate at each qubit, which yields |b〉 as in (50) in the compu-tational basis.

The corresponding quantum circuit that will be used can be found in figure 9. Thefirst step, having prepared |b〉, is as usual the QPE. The unitary operations U2

kin this

case are eiAt0/16, eiAt0/8, eiAt0/4 and eiAt0/2, with k = 0, 1, 2, 3with t0 = 2π.

28

Page 29: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

Furthermore, the simulation time T according to the number of qubits is T = 24 = 16.This gives the state

4∑j=1

1

2︸︷︷︸βj

|λj〉C |uj〉I (51)

As the eigenvalues are integers, the QPE can be assumed to be exact.At this point, the inversion procedure from section 3.3.3 could be applied. But con-

sidering the specific properties of the system, we can take a shortcut. The goal is tohave states of the form | 2

4

λj〉 (compare to section 3.3.3, last paragraph). Now, write the

eigenvalues in binary form as λ1 = 1 = |0001〉 , λ2 = 2 = |0010〉 , λ3 = 4 = |0100〉 , λ4 =8 = |1000〉.

Observe, that

λ−14 = |1000〉−1 → 1

8· 24 = |0010〉 = |

24

λ4〉 (52)

λ−13 = |0100〉−1 → 1

4· 24 = |0100〉 = |

24

λ3〉

λ−12 = |0010〉−1 → 1

2· 24 = |1000〉 = |

24

λ2〉

λ−11 = |0001〉−1 → 1

1· 24 = 24 |0001〉 = |

24

λ1〉 .

This means, that to get the inverse eigenvalue in desired form, it is only necessaryto swap the first and third qubit of the clock register here. Thus, it is now possibleto adjoin the ancilla register S and to rotate conditioned on the inverse eigenvalues.Before the projective measurement of the ancilla, uncomputation is performed in theusual manner (this also includes undoing the swap of the eigenvalues).

Finally, we end up in a state 1√85(8 |u1〉+ 4 |u2〉+ 2 |u3〉+ |u4〉)I ⊗ |0000〉C + |1〉S. This

can be rewritten in the basis {|00〉 , |01〉 , |10〉 , |11〉}, giving

|x〉 = 1√340

(− |00〉+ 7 |01〉+ 11 |10〉+ 13 |11〉) ∝1

32(−1, 7, 11, 13)T = x. (53)

Thus, we have the solution of the linear system up to a constant. Note, that only twoqubits are necessary here to encode a R4-vector. This also means, that the solution stillis encoded in the quantum state. To read it out, one would have to perform (multiple!)measurements on the input, to end up with a probability distribution corresponding tothe final state.

29

Page 30: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

3 The HHL algorithm

0 00

00 0

00

0000

10

0 00

01 0

00

0001

10

0 00

10 0

00

0010

10

0 00

11 0

00

0011

10

0 01

00 0

00

0100

10

0 01

01 0

00

0101

10

0 01

10 0

00

0110

10

0 01

11 0

00

0111

10

0 10

00 0

00

1000

10

0 10

01 0

00

1001

10

0 10

10 0

00

1010

10

0 10

11 0

00

1011

10

0 11

00 0

00

1100

10

0 11

01 0

00

1101

10

0 11

10 0

00

1110

10

0 11

11 0

00

1111

10

1 00

00 0

01

0000

10

1 00

01 0

01

0001

10

1 00

10 0

01

0010

10

1 00

11 0

01

0011

10

1 01

00 0

01

0100

10

1 01

01 0

01

0101

10

1 01

10 0

01

0110

10

1 01

11 0

01

0111

10

1 10

00 0

01

1000

10

1 10

01 0

01

1001

10

1 10

10 0

01

1010

10

1 10

11 0

01

1011

10

1 11

00 0

01

1100

10

1 11

01 0

01

1101

10

1 11

10 0

01

1110

10

1 11

11 0

01

1111

10

0.0

0.1

0.2

0.3

0.4

0.5

Figure 10: Result of the HHL algorithm applied on the 4× 4-system using the tool of[Adr18]; The y-axis shows the amplitude, while the x-Axis represents theindividual qubits. On the very left, one can identify the vector |b〉, and in themiddle the solution of the system. Observe, that this result matches with thediagram in [Cao+12]

There can be found several tools online to play around with this implementation.On 10, you can find an implementation on Quirk, which is a tool to simulate quantumcircuits that can be built with a graphical interface. Another very nice implementationis given by [Adr18], available on GitHub under 11. This tool gives up to numericalprecision the same result as 53, and a plot for the final qubit state, which is depictedin figure 10. It makes especially sense to try it out, if one is interested in the entireexperimental procedure, as it also provides a heuristic optimization algorithm that ap-proximates the unitary transformations.

10https://goo.gl/v4JbRw or https://quantumcomputing.stackexchange.com/questions/3743/erro

r-simulation-of-quantum-algorithm-for-linear-systems-of-equations-for-411https://github.com/nelimee/quantum-hhl-4x4

30

Page 31: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

4 Additional remarks on the HHL algorithm

4 Additional remarks on the HHL algorithm

Dealing with ill-conditioned systems The algorithm relies on an eigendecomposi-tion of A and inverting for its eigenvalues. Now, suppose some of these eigenvaluesare close to zero. As they are slightly perturbed by numerical precision, this has theconsequence, that the system is ill-conditioned in the subspace spanned by the eigen-vectors corresponding to these eigenvalues. To overcome this, [HHL09] proposed filterfunctions, that allow, to either only invert on the well-conditioned subspace or estimatethe ill-conditioning of the system. The idea is to have functions f(λ),g(λ), that have tofulfil certain continuity properties, and add an extra three-qubit register

|h(λ)〉 =√1− f(λ)2 − g(λ2) |nothing〉+ f(λ) |well〉+ g(λ) |ill〉 , (54)

where nothing means no inversion took place, well and ill express well- and incondi-tionedness. Now, the technique of amplitude amplification is applied, which for in-stance is also used in Grover’s algorithm. This can be understood such that the well-part is amplified and the ill-part is dampened by means of some special unitary opera-tors. In the end, postselecting on |well〉 is applied.

This routine though not anymore unitary due to the filter functions. This introducesan error and requires some repetition, until the true result is obtained with certainty.[Der+18; HHL09]

Dealing with non-hermitian systems Suppose now A non-hermitian. Then define

C =

(0 A

A† 0

). Solving Cy = b∗ with y = (0, x)T and b∗ = (b, 0)T gives the desired

solution, as C now is hermitian. This can be also extended to non-square cases, whichare further discussed in [Der+18; HHL09].

31

Page 32: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

4 Additional remarks on the HHL algorithm

Error analysis and complexity Harrow et. al assume, that the errors due to Hamil-tonian simulation and preparing the initial state are neglegible, which holds, as theycan be implemented efficienctly. The main influence of errors thus arises from the post-selecting when using the filter functions, as there is still some information left in the|ill〉-part, that is discarded. They show, that finally, the error with respect to the exactsolution is of order O(κ/t0), where κ represents the condition number and t0 the sim-ulation time chosen for the Hamiltonian simulation. Taking t0 = O(κ/ε), this gives anerror of ε on the final state. With this information, it is now possible, to calculate thenumber of qubits needed to obtain a solution up to an error ε.

The overall complexity in the end from the initial state to the solution (both in form ofa quantum state) turns out to be O(κ2/εs2 logN), where s is the sparsity of the system.In comparison to that, solving a linear system by Gauss elimination takes O(N3), theconjugate gradient algorithm for sparse, symmetric positive definite matrices needsO(Nsκ log 1

ε).If interested, the detailed error analysis can be found in [HHL09], and in even more

detail described in [Der+18].

32

Page 33: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

5 Conclusions and outlook

5 Conclusions and outlook

After having introduced some basic concepts of quantum mechanics and how thesecan be used to store and process information (building a computer), the so called HHL-Algorithm aswell as some important subroutines were presented. This algorithm hasthe potential to be a powerful tool in the future, as soon as quantum computers are ac-cessible to the public or at least a larger range of people. As mentioned before, the HHLalgorithm gives the solution (up to a known constant) of a linear system encoded in aquantum state. Assuming efficient preparation of |b〉 and sparsity ofA, this can be donein time O(logN), which is exponentially faster than the best known classical algorithmfor solving a linear system, the Conjugate Gradient method (O(N)). But looking at itsharply, this speedup can be achieved only if one is not interested in reading out theentries of x explicitly. A possible outcome then might be some global expectation value〈x|M|x〉 to some hermitianM. A strong field of application for this algorithm thereforeis machine learning on quantum computers. In machine learning, one usually has a lotof data - the advantage of the algorithm here is, that one only requires logN qubits toencodeN bits of data. Furthermore, one is usually not interested in each bit of data, butlooks out for global properties. For example [Zha+18] uses the HHL algorithm appliedon a deep learning problem. An implementation in python, that can be used to run theHHL algorithm on quantum computers by Rigetti, can be found under 12.

Another use might be to use the algorithm calculating functions of some hermitianoperator A13, as f(A) =

∑j f(λj) |uj〉 〈uj|. Now, instead of calculating the inverse of

the eigenvalue, one applies some function f on it. The rest of the algorithm can stay[HHL09].

Another point to adress is the (once understood) simplicity of the algorithm, to invertthe matrix using the eigendecomposition. Here, the algorithm is not approximative, butwould give arithmetically the exact solution considering having exact eigenvalues. Thisis the bottleneck though, as the phase-estimation procedure indeed is of iterative, ap-proximating nature, and is the main point contributing to the error analysis in [HHL09].Another peculiarity of the QPE is the Hamiltonian simulation, which has to run for acertain time. As current quantum computers are quite suscepible for noise from thesurroundings, this comparably long time needed for the simulation can be a fatal dueto quantum decoherence.

12https://gitlab.com/apozas/bayesian-dl-quantum/blob/master/HHL_Rigetti.py13or the hermitian extension of an arbitrary operator

33

Page 34: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

5 References

In other applications, when eigenvalues are needed, such as quantum chemistry, an-other approach is used: Instead of simulating the entire Hamiltonian, it is decomposedin small blocks using second quantization [Per+14]. Unfortunately, for the purposes ofsolving linear systems, this method is not applicable, as it returns the eigenvalues interms of expectation values of the individual parts of the decomposed Hamiltonian.

The HHL algorithm has also already been applied on Finite-Elements [MP16], andresearch has been done on improving it by preconditioning [CJS13]. It turns out, thatwhen using the preconditioner, a polynomial speedup can achieved by using the quan-tum algorithm. Thus, the algorithm is not only valuable for fields as machine learning,but also classical disciplines of scientific computing.

The HHL algorithm provides a universal tool to the field of quantum computing. Atthis point (2019), more than ten years after being published, the main problem that itis not yet in wider use, are availability and accesibility of quantum computers with asignificant number of qubits. So we can curiously look forward to the future, where anew era of computing will await us.

References

[Adr18] CERFACS Adrien Suau. Implementation the HHL for a 4x4 system. 2018. URL:https://github.com/nelimee/quantum-hhl-4x4.

[Bac06] Dave Bacon. Quantum Computing Reversible Classical Circuits and the Deutsch-Jozsa Algorithm. Tech. rep. Department of Computer Science and Engineer-ing, Universtiy of Washington, 2006. URL: https://courses.cs.washington.edu/courses/cse599d/06wi/lecturenotes6.pdf.

[BDM99] V. Buzek, R. Derka, and S. Massar. “Optimal quantum clocks”. In: PhysicalReview Letters 82.10 (1999), pp. 2207–2210. arXiv: 9808042v2 [arXiv:quant-ph].

[Cao+12] Yudong Cao et al. “Quantum circuit design for solving linear systems ofequations”. In: Molecular Physics 110.15-16 (2012), pp. 1675–1680. arXiv: arXiv:1110.2232v2.

[CJS13] B. D. Clader, B. C. Jacobs, and C. R. Sprouse. “Preconditioned quantumlinear system algorithm”. In: Physical Review Letters 110.25 (2013), pp. 1–5.arXiv: arXiv:1301.2340v4.

[Der+18] Danial Dervovic et al. “Quantum linear systems algorithms: a primer”. In:(2018). arXiv: 1802.08227. URL: http://arxiv.org/abs/1802.08227.

34

Page 35: How to solve a linear system of equations using a quantum ...€¦ · This seminar report gives a short summary on the capababilty of quantum computers to solve linear systems of

References

[DK11] Anmer Daskin and Sabre Kais. “Decomposition of unitary matrices for find-ing quantum circuits: Application to molecular Hamiltonians”. In: Journal ofChemical Physics 134.14 (2011). arXiv: arXiv:1009.5625v3.

[EHI00] Artur Ekert, Patrick Hayden, and Hitoshi Inamori. “Basic concepts in quan-tum computation”. In: 3 (2000), pp. 1–37. arXiv: 0011013 [quant-ph]. URL:http://arxiv.org/abs/quant-ph/0011013.

[GR02] Lov Grover and Terry Rudolph. “Creating superpositions that correspondto efficiently integrable probability distributions”. In: (2002), pp. 1–2. arXiv:0208112 [quant-ph]. URL: http://arxiv.org/abs/quant-ph/0208112.

[HHL09] Aram W. Harrow, Avinatan Hassidim, and Seth Lloyd. “Quantum algo-rithm for linear systems of equations”. In: Physical Review Letters 103.15(2009), pp. 1–15. arXiv: arXiv:0811.3171v3.

[Kib18] Maurice Robert Kibler. “Quantum information and quantum computing:an overview and some mathematical aspects”. In: 1 (2018), pp. 1–40. arXiv:1811.08499. URL: http://arxiv.org/abs/1811.08499.

[MP16] Ashley Montanaro and Sam Pallister. “Quantum algorithms and the finiteelement method”. In: Physical Review A 93.3 (2016), pp. 1–16. arXiv: arXiv:1512.05903v2.

[NC10] M. Nielsen and I. L. Chuang. Quantum Computation and Quantum Informa-tion: 10th Anniversary Edition. 10th. New York, NY, USA: Cambridge Uni-versity Press, 2010, pp. 500–527, 582–607. arXiv: arXiv:1011.1669v3.

[Per+14] Alberto Peruzzo et al. “A variational eigenvalue solver on a photonic quan-tum processor”. In: Nature Communications 5.2 (2014), pp. 1–10. arXiv: arXiv:1304.3061v1.

[Q] IBM Q. IBM Q Experience Full User Guide. URL: https://quantumexperience.ng.bluemix.net/proxy/tutorial/full-user-guide/introduction.html

(visited on 06/21/2019).

[Zha+18] Zhikuan Zhao et al. “Bayesian Deep Learning on a Quantum Computer”.In: (2018), pp. 1–11. arXiv: 1806.11463. URL: http://arxiv.org/abs/1806.11463.

35