This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

\history

Date of publication xxxx 00, 0000, date of current version xxxx 00, 0000. 10.1109/ACCESS.2022.0122113

\tfootnote

Part of this work was supported by the National Science Foundation under Grant 2046220.

\corresp

Corresponding author: Hiu Yung Wong (email: [email protected]). A. Zaman and H. J. Morrell have equal contributions.

A Step-by-Step HHL Algorithm Walkthrough to Enhance Understanding of Critical Quantum Computing Concepts

ANIKA ZAMAN1    HECTOR JOSE MORRELL2, HIU YUNG WONG.3    Department of Electrical Engineering, San Jose State University, San Jose, CA 95192 USA (email: [email protected]) Department of Electrical Engineering, San Jose State University, San Jose, CA 95192 USA (email: [email protected]) Department of Electrical Engineering, San Jose State University, San Jose, CA 95192 USA (email: [email protected])
Abstract

After learning basic quantum computing concepts, it is desirable to reinforce the learning using an important and relatively complex algorithm through which students can observe and appreciate how qubits evolve and interact with each other. Harrow-Hassidim-Lloyd (HHL) quantum algorithm, which can solve linear system problems with exponential speed-up over the classical method and is the basis of many important quantum computing algorithms, is used to serve this purpose. The HHL algorithm is explained analytically followed by a 4-qubit numerical example in bra-ket notation. Matlab code corresponding to the numerical example is available for students to gain a deeper understanding of the HHL algorithm from a pure matrix point of view. A quantum circuit programmed using qiskit is also provided for real hardware execution in IBM quantum computers. After going through the material, students are expected to have a better appreciation of the concepts such as basis transformation, bra-ket and matrix representations, superposition, entanglement, controlled operations, measurement, quantum Fourier transformation, quantum phase estimation, and quantum programming. To help readers review these basic concepts, brief explanations augmented by the HHL numerical examples in the main text are provided in the Appendix.

Index Terms:
Harrow-Hassidim-Lloyd (HHL) quantum algorithm, Quantum Fourier transform (QFT), inverse quantum Fourier transform (IQFT), quantum phase estimation(QPE),linear system problem (LSP), Quantum Education
\titlepgskip

=-15pt

I Introduction

Quantum Computing is promising in solving challenging engineering [1], biomedical [2] and finance [3] problems. It has a tremendous advancement in the last two decades and, recently, quantum breakthrough has been demonstrated using a 53-qubit system [4].However, according to the paper [5], due to less efficient hardware implementation till date, the goal to reach superconducting quantum supremacy is yet to achieve. Therefore, the training of a quantum technology workforce is an imminent goal for many countries (e.g. [23]) to support this fast-growing industry. However, quantum technology is based on concepts very different from our daily and classical experiences. In the early stage of learning quantum computing, although linking to daily and classical experience may enhance the understanding of certain quantum concepts and such an approach should not be de-emphasized, we believe a fast and robust way of training a quantum workforce is to train the students to be able to emulate a quantum processor and trace the evolution of the qubits. This is particularly useful in learning quantum algorithms without a quantum mechanics background. Such an approach obviates the students from cognitive conflicts, which can be resolved later, if possible, after they understand how quantum computing works. This also embraces the “Shut up and calculate!” approach proposed by Mermin on how to deal with the uncomfortable feeling toward quantum mechanics interpretation [6].

Besides analytical equations, matrix representation and computer simulations are important tools to enhance the understanding of qubit evolution. However, available examples that include computer simulations are usually of simple algorithms and, very often, without matrix representation. There is a lack of examples of important and relatively complex algorithms which combine some of the most important quantum computing concepts and basic algorithms. Such examples are desirable to allow students to appreciate the roles and the interplay of various basic concepts in a more realistic quantum algorithm. Harrow-Hassidim-Lloyd (HHL) quantum algorithm [7][8] which can be used to solve linear system problems (LSP) and can provide exponential speedup over the classical conjugate gradient method [9] is chosen for this purpose. HHL is the basic of many more advanced algorithms and is important in various applications such as machine learning [10] and modeling of quantum systems [2][11]. HHL solves system of linear equation which is a discretization of [12][13]. In this paper, we detail the qubit evolution in Harrow-Hassidim-Lloyd (HHL) quantum algorithm analytically with a 4-qubit circuit as a numerical example. Although HHL examples are available elsewhere (e.g. [14][15]), this paper has certain characteristics which are not all found in those examples. Firstly, the HHL algorithm is discussed analytically step-by-step and is self-contained. Secondly, a numerical example is given in bra-ket notation mirroring the analytical equations. Thirdly, a Matlab code corresponding exactly to the numerical example is available to enhance the understanding from a matrix point of view. The Matlab code allows the students to trace how the wavefunction evolves instead of just seeing the magnitudes of the coefficients as in IBM-Q. Fourthly, a qiskit code written in python [16] corresponding to the numerical example is available and can be run in IBM simulation and hardware machines [17]. Finally, in the example, all the 4 qubits are traced throughout the process without simplification.

The readers are assumed to have the following background concepts which are further enhanced through the step-by-step walkthrough of the HHL algorithm: basis transformation, bra-ket and matrix representations, superposition, entanglement, encoding, controlled operations, measurement, quantum Fourier transformation, and quantum programming. To make this paper self-contained and to help the readers better appreciate the roles of these basic concepts in the HHL, an Appendix is devoted to briefly explaining these concepts using the examples from the main text. A more detailed explanation of these concepts using a similar approach as in this paper can be found in [19].

I-A How to use this paper

For readers who have a fresh memory of the basic concepts, they can start reading from Section II, in which the HHL algorithm is discussed step-by-step analytically followed by a numerical example in Section III. The basic concepts mentioned in the Appendix are referred to in the main text and readers are encouraged to review them when needed.

For readers who need reviews on the basic concepts first, they are encouraged to go over the Appendix first before reading the main text.

For readers who have devoted substantial time to learning HHL elsewhere but just need a numerical example to reinforce the understanding, they might start with the numerical example in Section III.

Equations in the Appendix begin with ’V’. If the equations are examples from the main text, the same equation number is used in the Appendix.

II HHL Algorithm

II-A Definitions and Overview

We will first give an overview of the problem and the HHL algorithm. Details will be discussed in the following subsections with reference to the Appendix for reviewing basic concepts. A linear system problem (LSP) can be represented as the following

Ax=bA\vec{x}=\vec{b} (1)

where AA is a Nb×NbN_{b}\times N_{b} Hermitian matrix and x\vec{x} and b\vec{b} are NbN_{b}-dimensional vectors. For simplicity, it is assumed Nb=2nbN_{b}=2^{n_{b}}, where nbn_{b} is the number of qubits in the quantum circuit, and NbN_{b} is the total combinations due number of qubits,nbn_{b}. In matrix representation, qubits are represented by their total combinations(Nb×NbN_{b}\times N_{b}), or we can say for NbN_{b} number of unknowns, we need nbn_{b} qubits to solve unknowns. Dummy equations can be added otherwise to convert the system satisfy this assumption. AA and b\vec{b} are known and x\vec{x} is the unknown to be solved, i.e.

x=A1b\vec{x}=A^{-1}\vec{b} (2)
Refer to caption
Figure 1: Schematic of the HHLHHL quantum circuit flowing from left to right. The circuit is decomposed into top and bottom portions for clarity. Note that the lowest qubit in the diagram is the most significant bit (MSBMSB) while the top one is the least significant bit (LSBLSB).

As an example, A=(113131)A=\begin{pmatrix}1&-\frac{1}{3}\\ -\frac{1}{3}&1\\ \end{pmatrix}, b=(01)\vec{b}=\begin{pmatrix}0\\ 1\\ \end{pmatrix}, and x=(3898)\vec{x}=\begin{pmatrix}\frac{3}{8}\\ \frac{9}{8}\\ \end{pmatrix} with nb=1n_{b}=1 and Nb=21=2N_{b}=2^{1}=2. Readers may refer to Appendix V-13 and Appendix V-14 to review how LSP is solved classically using Gaussian Elimination and Conjugate Gradient Method, respectively.

AA is assumed to be Hermitian (See Appendix V-1). If it is not Hermitian, the AA can be converted to (0AA0)\begin{pmatrix}0&A\\ A^{\dagger}&0\\ \end{pmatrix}, which is Hermitian. Readers may refer to [20] for the more advanced treatment when AA is not Hermitian.

Figure 1 shows the schematic of the HHLHHL algorithm and the corresponding circuit to solve LSP. In the HHL quantum algorithm, the NbN_{b} components of b\vec{b} and x\vec{x} are encoded as the amplitudes/coefficients (amplitude encoding) of basis states of the nbn_{b}-qubits, |b\ket{\;}_{b}, which form a Nb\mathbb{C}^{N_{b}} Hilbert space. These nbn_{b} qubits are called b-register. Qubit nbn_{b} is chosen to be large enough to encode b\vec{b}, i.e. 2nb2^{n_{b}} needs to be the same as the length of the vectors b\vec{b} and x\vec{x}. The matrix AA is simulated through Hamiltonian encoding by encoding it as the Hamiltonian of a unitary gate. Appendix V-9 reviews examples of various encoding schemes.

The HHL algorithm has 5 main components, namely state preparation, quantum phase estimation (QPE), ancilla bit rotation, inverse quantum phase estimation (IQPE), and measurement. In this paper, the little-endian convention is used. In a little-endian convention, the rightmost (ending) qubit represents the least significant bit (LSB). For example, in a 4-qubit system, |0001\ket{0001} in binary is |1\ket{1} in decimal because the 11 in the basis state |0001\ket{0001} is the LSB, representing 202^{0} instead of 232^{3} (if it were the most significant bit, MSB). Moreover, in the circuit diagrams, the lowest qubit represents the MSB and the topmost qubit represents the LSB, which is a convention used in qiskit [16] and the IBM-Q platform [17]

As shown in Figure 1, besides the b-register, which belongs to the more significant bits, there are two more sets of inputs to the algorithm. The first set is sometimes called the c-register because it is related to the time (clock) in the controlled rotation in the QPE part. Therefore, they are also called the clock qubits.The c-register stores the values of the phase of the eigenvalues of the AA matrix after the QPE. There are nn qubits in the c-register. Since basis encoding is used (i.e. the phase value is encoded as the basis number (See Appendix V-9), the value of nn determines how accurately the phase can be stored. A larger nn results in higher accuracy when the encoding is not exact. We set N=2nN=2^{n}.

The last set of qubits is the ancilla qubit |a\ket{\;}_{a} which is the LSB. The ancilla qubit, as its name implies, is important to help achieve the goal although it will be discarded at the end, as will be detailed later.

The matrix AA, which is a Hamiltonian, may be written as a linear combination of the outer products of its eigenvectors, |uiui|\ket{u_{i}}\bra{u_{i}} weighted by its eigenvalues, λi\lambda_{i},in Eq.(3), (See Appendix V-8).

A=i=02nb1λi|uiui|A=\sum_{i=0}^{2^{n_{b}}-1}\lambda_{i}\ket{u_{i}}\bra{u_{i}} (3)

Since A is diagonal in its eigenvector basis, its inverse is simply, A1=i=02nb1λi1|uiui|A^{-1}=\sum_{i=0}^{2^{n_{b}}-1}\lambda_{i}^{-1}\ket{u_{i}}\bra{u_{i}}. b\vec{b} can be also expressed in the basis formed by the eigenvectors of A, such that

|b=j=02nb1bj|uj\ket{b}=\sum_{j=0}^{2^{n_{b}}-1}b_{j}\ket{u_{j}} (4)

Therefore, Eq. (2) can be encoded as,

|x=A1|b=i=02nb1λi1bi|ui\ket{x}=A^{-1}\ket{b}=\sum_{i=0}^{2^{n_{b}}-1}\lambda_{i}^{-1}b_{i}\ket{u_{i}} (5)

by using the fact that ui|uj=δij\braket{u_{i}}{u_{j}}=\delta_{ij}. The goal of the HHL algorithm is to find the solution in this form and |x\ket{x} is stored in the b-register.Storing the right hand side of (5) in the b-register is equivalent to storing |x\ket{x} in the b-register. But the solution is encoded as the amplitudes of the basis vectors |0/|1\ket{0}/\ket{1} (the measurement basis). Therefore, the solutions are not λi1bi\lambda_{i}^{-1}b_{i}, which are the amplitudes of the eigenvector basis vectors. However, one will naturally get the correct amplitudes if it is measured in the |0/|1\ket{0}/\ket{1} basis and this is only possible if the qubits are not entangled with other qubits. This can be checked mathematically replacing |ui\ket{u_{i}} by |0/|1\ket{0}/\ket{1} based on their relationship. If |ui\ket{u_{i}} are entangled with other qubits, one cannot obtain the desired solution. This will be clear after the ancilla bit rotation to be detailed later.

The equation needs also to be prepared so that the eigenvectors, |ui\ket{u_{i}}, and |b\ket{b} are normalized so they can be properly represented as a unit vector in quantum computing. Therefore, (4) and Eq. (5) require

j=02nb1|bj|2=1\displaystyle\sum_{j=0}^{2^{n_{b}}-1}\lvert b_{j}\rvert^{2}=1
i=02nb1|λi1bi|2=1\displaystyle\sum_{i=0}^{2^{n_{b}}-1}\lvert\lambda_{i}^{-1}b_{i}\rvert^{2}=1 (7)

II-B State Preparation

There are total nb+n+1n_{b}+n+1 qubits and they are initialized as

|Ψ0=|00b|00c|0a=|0nb|0n|0\ket{\Psi_{0}}=\ket{0\cdots 0}_{b}\ket{0\cdots 0}_{c}\ket{0}_{a}=\ket{0}^{\otimes n_{b}}\ket{0}^{\otimes n}\ket{0} (8)

In the state preparation, |00b\ket{0\cdots 0}_{b} in the b-register needs to be rotated to have the amplitudes correspond to the coefficients of b\vec{b}. That is

b=(β0β1βNb1)β0|0+β1|1++βNb1|Nb1=|b\vec{b}=\begin{pmatrix}\beta_{0}\\ \beta_{1}\\ \vdots\\ \beta_{N_{b}-1}\\ \end{pmatrix}\Leftrightarrow\beta_{0}\ket{0}+\beta_{1}\ket{1}+\cdots+\beta_{N_{b}-1}\ket{N_{b}-1}=\ket{b} (9)

The vector b\vec{b} is represented in a column form on the left with coefficients βs\beta^{\prime}s. This is also a valid representation of |b\ket{b}. On the right, the corresponding basis of the Hilbert space formed by the nbn_{b} qubits is written explicitly. Therefore,

|Ψ1=|bb|00c|0a\ket{\Psi_{1}}=\ket{b}_{b}\ket{0\cdots 0}_{c}\ket{0}_{a} (10)

From now on, some of the subscripts of the kets will be omitted when there is no ambiguity. Since the state preparation depends on the actual value of b\vec{b}, it will be discussed in more detail in the numerical example.

II-C Quantum Phase Estimation

Quantum phase estimation (QPE) is also an eigenvalue estimation algorithm. QPE has three components, namely the superposition of the clock qubits through Hadamard gates, controlled rotation, and inverse quantum Fourier transform (IQFT). The goal of QPE is to estimate the phase of the eigenvalues of the unitary rotation matrix, U=eiAtU=e^{iAt}, in the controlled gate, CUC-U, (Fig. 1) used in the QPE. Again, this gate encodes the matrix AA as its Hamiltonian. It is also instructive to note that the eigenvalues of UU must be roots of unity (i.e. in the form of eiθe^{i\theta}) as UU is unitary. Therefore, the phase of the eigenvalue of the gate is proportional to the eigenvalue of AA. As a result, by using QPE in the HHL algorithm, it is expected the eigenvalues of AA will be encoded in the c-register after the QPE, i.e. at |Ψ4\ket{\Psi_{4}}. As it will be clear later, the eigenvalues are only encoded through basis encoding. The c-register does not store the exact eigenvalues.

Here we assume the readers are already familiar with IQFT and it will not be explained in detail. Readers may review the basic concepts in Appendices V-11 and V-12.

In the first step of QPE, Hadamard gates are applied to the clock qubits to create a superposition of the clock qubits,

|Ψ2\displaystyle\ket{\Psi_{2}} =\displaystyle= InbHnI|Ψ1\displaystyle I^{\otimes n_{b}}\otimes H^{\otimes n}\otimes I\ket{\Psi_{1}} (11)
=\displaystyle= |b12n2(|0+|1)n|0\displaystyle\ket{b}\frac{1}{2^{\frac{n}{2}}}(\ket{0}+\ket{1})^{\otimes n}\ket{0} (12)
Refer to caption
Figure 2: The controlled-rotation part of QPE. UU is replaced by eiAte^{iAt} in the HHL algorithm.

In the controlled rotation part, controlled gates are applied to |b\ket{b} with the clock qubits as the controlling qubits (Figure 2). The number of the qubit, nn, of the c-register determines the number of the controlled gates. The gates are in the form of U2rU^{2^{r}}, where rr is the index of the clock qubit. Also, U=eiAtU=e^{iAt}. For the most significant bit in the c-register, |cn1\ket{c_{n-1}}, it controls the gate U2n1U^{2^{n-1}} on the b-register while the least significant one, |c0\ket{c_{0}}, controls the gate U20=UU^{2^{0}}=U on the b-register.

To understand how it works, we begin by assuming that |b\ket{b} is an eigenvector of UU with eigenvalue e2πiϕe^{2\pi i\phi}. The eigenvalue is written in this form so that the phase, ϕ\phi, will be encoded as the basis state in the c-register (See Eq. (II-C)). Therefore, based on the definition of eigenvalues and eigenvectors (See Section V-8),

U|b=e2πiϕ|bU\ket{b}=e^{2\pi i\phi}\ket{b} (13)

When the control clock qubit is |0\ket{0}, |b\ket{b} will not be affected. If the clock bit is |1\ket{1}, UU will be applied to |b\ket{b}. This is equivalent to multiplying e2πiϕ2je^{2\pi i\phi 2^{j}} in front of the |1\ket{1} of the jjth clock qubit, |cj\ket{c_{j}}, as one can assign the prefactor to the controlling qubit. Therefore, after the controlled-UU operation, we have

|Ψ3\displaystyle\ket{\Psi_{3}} =|b(12n2(|0+e2πiϕ2n1|1)(|0+\displaystyle=\ket{b}\otimes\big{(}\frac{1}{2^{\frac{n}{2}}}(\ket{0}+e^{2\pi i\phi 2^{n-1}}\ket{1})\otimes(\ket{0}+
e2πiϕ2n2|1)(|0+e2πiϕ20|1))|0a\displaystyle e^{2\pi i\phi 2^{n-2}}\ket{1})\otimes\cdots\ \otimes(\ket{0}+e^{2\pi i\phi 2^{0}}\ket{1})\big{)}\otimes\ket{0}_{a}
=|b12n2k=02n1e2πiϕk|k|0a\displaystyle=\ket{b}\frac{1}{2^{\frac{n}{2}}}\sum_{k=0}^{2^{n}-1}e^{2\pi i\phi k}\ket{k}\ket{0}_{a} (14)

In the IQFT part,(II-C), only the clock qubits are affected. Note that in certain literature, this is called Quantum Fourier Transform (QFT) (Appendix V-11).

|Ψ4\displaystyle\ket{\Psi_{4}} =|bIQFT(12n2k=02n1e2πiϕk|k)|0a\displaystyle=\ket{b}\textrm{IQFT}(\frac{1}{2^{\frac{n}{2}}}\sum_{k=0}^{2^{n}-1}e^{2\pi i\phi k}\ket{k})\ket{0}_{a}
=|b12n2k=02n1e2πiϕk(IQFT|k)|0a\displaystyle=\ket{b}\frac{1}{2^{\frac{n}{2}}}\sum_{k=0}^{2^{n}-1}e^{2\pi i\phi k}(\textrm{IQFT}\ket{k})\ket{0}_{a}
=|b12nk=02n1e2πiϕk(y=02n1e2πiyk/N|y)|0a\displaystyle=\ket{b}\frac{1}{2^{n}}\sum_{k=0}^{2^{n}-1}e^{2\pi i\phi k}(\sum_{y=0}^{2^{n}-1}e^{-2\pi iyk/N}\ket{y})\ket{0}_{a}
=12n|by=02n1k=02n1e2πik(ϕy/N)|y|0a\displaystyle=\frac{1}{2^{n}}\ket{b}\sum_{y=0}^{2^{n}-1}\sum_{k=0}^{2^{n}-1}e^{2\pi ik(\phi-y/N)}\ket{y}\ket{0}_{a} (15)

Due to interference, only |y\ket{y} satisfying the condition ϕy/N=0\phi-y/N=0 will have a finite amplitude of k=02n1e0=2n\sum_{k=0}^{2^{n}-1}e^{0}=2^{n}. Otherwise, the amplitude is k=02n1e2πik(ϕy/N)=0\sum_{k=0}^{2^{n}-1}e^{2\pi ik(\phi-y/N)}=0 due to destructive interference. By ignoring the states with zero amplitude, we may rewrite |Ψ4\ket{\Psi_{4}} as

|Ψ4\displaystyle\ket{\Psi_{4}} =12n|bk=02n1e2πik0|Nϕ|0a\displaystyle=\frac{1}{2^{n}}\ket{b}\sum_{k=0}^{2^{n}-1}e^{2\pi ik\cdot 0}\ket{N\phi}\ket{0}_{a}
=|b|Nϕ|0a\displaystyle=\ket{b}\ket{N\phi}\ket{0}_{a} (16)

Therefore, in QPE, the clock qubits are used to represent the phase information of UU, which is ϕ\phi, and the accuracy depends on the number of qubits, nn.

Since in Hamiltonian encoding, UU is related to AA through

U=eiAtU=e^{iAt} (17)

where tt is the evolution time for that Hamiltonian. UU is also diagonal in AsA^{\prime}s eigenvector, |ui\ket{u_{i}}, basis. If |b=|uj\ket{b}=\ket{u_{j}},

U|b\displaystyle U\ket{b} =\displaystyle= eiλjt|uj\displaystyle e^{i\lambda_{j}t}\ket{u_{j}} (18)

By equating iλjti\lambda_{j}t to 2πiϕ2\pi i\phi in Eq. (13), we get ϕ=λjt/2π\phi=\lambda_{j}t/2\pi and Eq. (II-C) becomes

|Ψ4=|uj|Nλjt/2π|0a\ket{\Psi_{4}}=\ket{u_{j}}\ket{N\lambda_{j}t/2\pi}\ket{0}_{a} (19)

Thus the eigenvalues of AA have been encodeded in the clock qubits (basis encoding). However, in general, given in (4), by superposition,

|Ψ4=j=02nb1bj|uj|Nλjt/2π|0a\ket{\Psi_{4}}=\sum_{j=0}^{2^{n_{b}}-1}b_{j}\ket{u_{j}}\ket{N\lambda_{j}t/2\pi}\ket{0}_{a} (20)

The λj\lambda_{j} are usually not integers. We will choose tt so that λj~=Nλjt/2π\tilde{\lambda_{j}}=N\lambda_{j}t/2\pi are integers. Therefore, λj~\tilde{\lambda_{j}} are usually scaled version of λj\lambda_{j}.

Ψ4\Psi_{4} can be rewritten as

|Ψ4=j=02nb1bj|uj|λj~|0a\ket{\Psi_{4}}=\sum_{j=0}^{2^{n_{b}}-1}b_{j}\ket{u_{j}}\ket{\tilde{\lambda_{j}}}\ket{0}_{a} (21)

II-D Controlled Rotation and Measurement of the Ancilla Qubit

The next step is to rotate the ancilla qubit, |0a\ket{0}_{a}, based on the encoded eigenvalues in the c-register, such that,

|Ψ5=j=02nb1bj|uj|λj~(1C2λj~2|0a+Cλj~|1a)\ket{\Psi_{5}}=\sum_{j=0}^{2^{n_{b}}-1}b_{j}\ket{u_{j}}\ket{\tilde{\lambda_{j}}}(\sqrt{1-\frac{C^{2}}{\tilde{\lambda_{j}}^{2}}}\ket{0}_{a}+\frac{C}{\tilde{\lambda_{j}}}\ket{1}_{a}) (22)

where CC is a constant. The goal is to show why this is useful.

When the ancilla qubit is measured, the ancilla qubit wavefunction will collapse to either |0\ket{0} or |1\ket{1}. If it is |0\ket{0}, the result will be discarded and the computation will be repeated until the measurement is |1\ket{1}. Therefore, the final wavefunction of interest is

|Ψ6=1j=02nb1|bjCλj~|2j=02nb1bj|uj|λj~Cλj~|1a\ket{\Psi_{6}}=\frac{1}{\sqrt{\sum_{j=0}^{2^{n_{b}}-1}\lvert\frac{b_{j}C}{\tilde{\lambda_{j}}}\rvert^{2}}}\sum_{j=0}^{2^{n_{b}}-1}b_{j}\ket{u_{j}}\ket{\tilde{\lambda_{j}}}\frac{C}{\tilde{\lambda_{j}}}\ket{1}_{a} (23)

where the prefactor is due to normalization after measurement. Since |Cλj~|2\lvert\frac{C}{\tilde{\lambda_{j}}}\rvert^{2} is the probabily of obtaining |1\ket{1} when the ancilla bit is measured, CC should be chosen to be as large as possible. Compared to (5), the result resembles the answer |x\ket{x} that we are looking for. However, we can only obtain the correct result if the b-register is measured in the eigenvector basis (i.e. |uj\ket{u_{j}} instead of |0/|1\ket{0}/\ket{1}). However, the b-register is entangled with the clock qubits, |λj~\ket{\tilde{\lambda_{j}}}. This means that we cannot factorize the result into a tensor product of the c-register and b-register (See the discussion after (5) and Appendix V-6). As a result, we cannot convert the b-register into the |0/|1\ket{0}/\ket{1} measurement basis with the desired amplitudes. We will need to uncompute the state so that it gives the right results in the |0/|1\ket{0}/\ket{1} measurement during which the b-register and c-register will be unentangled.

The measurement of the ancilla qubit can be and is usually performed after uncomputation. However, since the ancilla bit is not involved in any operations after the controlled rotation, measuring the ancilla bit before the uncomputation gives the same result. For simplicity in the derivation, it is thus performed before the uncomputation.

II-E Uncomputation - Inverse QPE

The uncomputation is done by using inverse QPE. Firstly, QFT is applied to the clock qubits as,

|Ψ7\displaystyle\ket{\Psi_{7}} =1j=02nb1|bjCλj~|2j=02nb1bjCλj~|ujQFT|λj~|1a\displaystyle=\frac{1}{\sqrt{\sum_{j=0}^{2^{n_{b}}-1}\lvert\frac{b_{j}C}{\tilde{\lambda_{j}}}\rvert^{2}}}\sum_{j=0}^{2^{n_{b}}-1}\frac{b_{j}C}{\tilde{\lambda_{j}}}\ket{u_{j}}QFT\ket{\tilde{\lambda_{j}}}\ket{1}_{a}
=1j=02nb1|bjCλj~|2j=02nb1bjCλj~|uj\displaystyle=\frac{1}{\sqrt{\sum_{j=0}^{2^{n_{b}}-1}\lvert\frac{b_{j}C}{\tilde{\lambda_{j}}}\rvert^{2}}}\sum_{j=0}^{2^{n_{b}}-1}\frac{b_{j}C}{\tilde{\lambda_{j}}}\ket{u_{j}}
(12n/2y=02n1e2πiyλj~/N|y)|1a\displaystyle\cdot(\frac{1}{2^{n/2}}\sum_{y=0}^{2^{n}-1}e^{2\pi iy\tilde{\lambda_{j}}/N}\ket{y})\ket{1}_{a} (24)

Then inverse controlled-rotations of the b-register by the clock qubits are applied with U1=eiAtU^{-1}=e^{-iAt}. Similar to the forward process, when the controlling rrth clock qubit is |0\ket{0}, |uj\ket{u_{j}} will not be affected. If the rrth clock qubit is |1\ket{1}, (U1)2r(U^{-1})^{2^{r}} will be applied to |uj\ket{u_{j}}. This is equivalent to multiplying eiλjtye^{-i\lambda_{j}ty} if the c-register is |y\ket{y}. This is due to the similar argument in Eq. (II-C) and the fact that 2πiϕ=iλjt2\pi i\phi=i\lambda_{j}t. Therefore,

|Ψ8\displaystyle\ket{\Psi_{8}} =\displaystyle= 12n/2j=02nb1|bjCλj~|2j=02nb1bjCλj~|uj\displaystyle\frac{1}{2^{n/2}\sqrt{\sum_{j=0}^{2^{n_{b}}-1}\lvert\frac{b_{j}C}{\tilde{\lambda_{j}}}\rvert^{2}}}\sum_{j=0}^{2^{n_{b}}-1}\frac{b_{j}C}{\tilde{\lambda_{j}}}\ket{u_{j}}
(y=02n1eiλjtye2πiyλj~/N|y)|1a\displaystyle\cdot(\sum_{y=0}^{2^{n}-1}e^{-i\lambda_{j}ty}e^{2\pi iy\tilde{\lambda_{j}}/N}\ket{y})\ket{1}_{a} (25)

Since we earlier chose to set λj~=Nλjt/2π\tilde{\lambda_{j}}=N\lambda_{j}t/2\pi, therefore, the two exponential terms cancel each other and

|Ψ8\displaystyle\ket{\Psi_{8}} =\displaystyle= 12n/2j=02nb1|bjCλj~|2j=02nb1bjCλj~|ujy=02n1|y|1a\displaystyle\frac{1}{2^{n/2}\sqrt{\sum_{j=0}^{2^{n_{b}}-1}\lvert\frac{b_{j}C}{\tilde{\lambda_{j}}}\rvert^{2}}}\sum_{j=0}^{2^{n_{b}}-1}\frac{b_{j}C}{\tilde{\lambda_{j}}}\ket{u_{j}}\sum_{y=0}^{2^{n}-1}\ket{y}\ket{1}_{a}
=\displaystyle= C2n/2j=02nb1|bjCλj|2|xy=02n1|y|1a\displaystyle\frac{C}{2^{n/2}\sqrt{\sum_{j=0}^{2^{n_{b}}-1}\lvert\frac{b_{j}C}{\lambda_{j}}\rvert^{2}}}\ket{x}\sum_{y=0}^{2^{n}-1}\ket{y}\ket{1}_{a} (26)

The clock qubits and the b-register are now unentangled and the b-register stores |x\ket{x}. By applying the Hadamard gate on the clock qubits, finally, we have

|Ψ9\displaystyle\ket{\Psi_{9}} =1j=02nb1|bjCλj|2j=02nb1bjCλj|uj|0n|1a\displaystyle=\frac{1}{\sqrt{\sum_{j=0}^{2^{n_{b}}-1}\lvert\frac{b_{j}C}{\lambda_{j}}\rvert^{2}}}\sum_{j=0}^{2^{n_{b}}-1}\frac{b_{j}C}{\lambda_{j}}\ket{u_{j}}\ket{0}^{\otimes n}\ket{1}_{a}
=Cj=02nb1|bjCλj|2|xb|0cn|1a\displaystyle=\frac{C}{\sqrt{\sum_{j=0}^{2^{n_{b}}-1}\lvert\frac{b_{j}C}{\lambda_{j}}\rvert^{2}}}\ket{x}_{b}\ket{0}_{c}^{\otimes n}\ket{1}_{a} (27)

If CC is real and by using (7),

|Ψ9\displaystyle\ket{\Psi_{9}} =1j=02nb1|bjλj|2|xb|0cn|1a\displaystyle=\frac{1}{\sqrt{\sum_{j=0}^{2^{n_{b}}-1}\lvert\frac{b_{j}}{\lambda_{j}}\rvert^{2}}}\ket{x}_{b}\ket{0}_{c}^{\otimes n}\ket{1}_{a}
=|xb|0cn|1a\displaystyle=\ket{x}_{b}\ket{0}_{c}^{\otimes n}\ket{1}_{a} (28)

Here, the solution |x\ket{x} (Eq. 5) is stored in the b-register successfully.

III Numerical Example

We will present a numerical example and apply HHL to it step-by-step. The implementation is shown in Figure 3. Firstly, we will discuss how to implement the controlled-UU and ancilla qubit rotations.

III-A Encoding Scheme

In this example, the matrix AA and vector b\vec{b} are set to be

A=(113131)A=\begin{pmatrix}1&-\frac{1}{3}\\ -\frac{1}{3}&1\\ \end{pmatrix} (29)
b=(01)\vec{b}=\begin{pmatrix}0\\ 1\\ \end{pmatrix} (30)

The eigenvectors of AA are u0=(1212)\vec{u_{0}}=\begin{pmatrix}\frac{-1}{\sqrt{2}}\\ \frac{-1}{\sqrt{2}}\end{pmatrix}, u1=(1212)\vec{u_{1}}=\begin{pmatrix}\frac{-1}{\sqrt{2}}\\ \frac{1}{\sqrt{2}}\end{pmatrix} with eigenvalues λ0=23\lambda_{0}=\frac{2}{3} and λ1=43\lambda_{1}=\frac{4}{3} respectively. We need to using basis encoding to encode the eigenvalues in the basis formed by the clock qubit and 2 qubits are needed by encoding λ0\lambda_{0} as |01\ket{01} and λ1\lambda_{1} as |10\ket{10} so that it maintains the ratio of λ1/λ0=2\lambda_{1}/\lambda_{0}=2. This means λ0~=1\tilde{\lambda_{0}}=1 and λ1~=2\tilde{\lambda_{1}}=2 or in other words, |λ0~=|01\tilde{\ket{\lambda_{0}}}=\ket{01} and |λ1~=|10\tilde{\ket{\lambda_{1}}}=\ket{10}. This gives a perfect encoding with n=2n=2 (i.e. N=4N=4). Therefore, tt is chosen to be 3π4\frac{3\pi}{4} to achieve the encoding scheme since λj~=Nλjt/2π\tilde{\lambda_{j}}=N\lambda_{j}t/2\pi.

Since b\vec{b} is a 2-dimensional complex vector, it can be encoded using 1 qubit and, thus, nb=1n_{b}=1.

The solution to the LSP is found to be

x=(3898)\vec{x}=\begin{pmatrix}\frac{3}{8}\\ \frac{9}{8}\\ \end{pmatrix} (31)

whereby, the ratio of |x0|2\lvert x_{0}\rvert^{2} to |x1|2\lvert x_{1}\rvert^{2} is 1:91:9.

III-B Controlled-U Implementation

In reality, we expect the controlled-UU operation to be implemented by Hamiltonian simulation [18]. However, to understand the algorithm, we will derive the matrix for UU and then map this to the ControlledUControlled-U gate used in IBM-Q directly. Since n=2n=2, there are two operations needed, namely U21=U2U^{2^{1}}=U^{2} and U20=UU^{2^{0}}=U, controlled by c1c_{1} and c0c_{0}, respectively.

In order to find the corresponding matrix for U2=ei2AtU^{2}=e^{i2At} and U=eiAtU=e^{iAt}, we need to perform similarity transformation on i2Ati2At and iAtiAt, exponentiate then, and transforms back to the original basis.

The transformation matrix from the original basis to the eigenvector basis is

V\displaystyle V =(u0u1)\displaystyle=\begin{pmatrix}\vec{u_{0}}&\vec{u_{1}}\end{pmatrix}
=(12121212)\displaystyle=\begin{pmatrix}\frac{-1}{\sqrt{2}}&\frac{-1}{\sqrt{2}}\\ \frac{-1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\end{pmatrix} (32)

Since VV is real and symmetric,its conjugate, VV^{\dagger} equals itself.

The diagonalized AA, i.e. expressed in the basis formed by u0\vec{u_{0}} and u0\vec{u_{0}}, is

Adiag\displaystyle A_{diag} =VAV\displaystyle=V^{\dagger}AV
=(230043)\displaystyle=\begin{pmatrix}\frac{2}{3}&0\\ 0&\frac{4}{3}\end{pmatrix} (33)

As it is diagonal, UU can be obtained by exponentiation of the elements accordingly.

Udiag\displaystyle U_{diag} =(eiλ0t00eiλ1t)\displaystyle=\begin{pmatrix}e^{i\lambda_{0}t}&0\\ 0&e^{i\lambda_{1}t}\end{pmatrix}
=(eiπ/200eiπ)\displaystyle=\begin{pmatrix}e^{i\pi/2}&0\\ 0&e^{i\pi}\end{pmatrix}
=(i001)\displaystyle=\begin{pmatrix}i&0\\ 0&-1\end{pmatrix} (34)

where t=3π/4t=3\pi/4 as mentioned earlier is used. Also,

Udiag2=UdiagUdiag=(1001)\displaystyle U_{diag}^{2}=U_{diag}U_{diag}=\begin{pmatrix}-1&0\\ 0&1\end{pmatrix} (35)

It is worth noting that both are naturally unitary which is a requirement for a quantum operation.

To obtain UU and U2U^{2} in the original basis, we need to apply similarity transformation again in the reverse direction,

U\displaystyle U =VUdiagV\displaystyle=VU_{diag}V^{\dagger}
=(12121212)(i001)(12121212)\displaystyle=\begin{pmatrix}\frac{-1}{\sqrt{2}}&\frac{-1}{\sqrt{2}}\\ \frac{-1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\end{pmatrix}\begin{pmatrix}i&0\\ 0&-1\end{pmatrix}\begin{pmatrix}\frac{-1}{\sqrt{2}}&\frac{-1}{\sqrt{2}}\\ \frac{-1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\end{pmatrix}
=12(1+i1+i1+i1+i)\displaystyle=\frac{1}{2}\begin{pmatrix}-1+i&1+i\\ 1+i&-1+i\end{pmatrix} (36)
U2\displaystyle U^{2} =VUdiag2V\displaystyle=VU_{diag}^{2}V^{\dagger}
=(12121212)(1001)(12121212)\displaystyle=\begin{pmatrix}\frac{-1}{\sqrt{2}}&\frac{-1}{\sqrt{2}}\\ \frac{-1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\end{pmatrix}\begin{pmatrix}-1&0\\ 0&1\end{pmatrix}\begin{pmatrix}\frac{-1}{\sqrt{2}}&\frac{-1}{\sqrt{2}}\\ \frac{-1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\end{pmatrix}
=(0110)\displaystyle=\begin{pmatrix}0&-1\\ -1&0\end{pmatrix} (37)

To implement UU and U2U^{2}, a 4-parameter arbitrary unitary gate with global phase [19],

U\displaystyle U =(eiγcos(θ/2)ei(γ+λ)sin(θ/2)ei(γ+ϕ)sin(θ/2)ei(γ+ϕ+λ)cos(θ/2))\displaystyle=\begin{pmatrix}e^{i\gamma}\cos(\theta/2)&-e^{i(\gamma+\lambda)}\sin(\theta/2)\\ e^{i(\gamma+\phi)}\sin(\theta/2)&e^{i(\gamma+\phi+\lambda)}\cos(\theta/2)\end{pmatrix} (38)

By choosing θ=π,ϕ=π,λ=0,γ=0\theta=\pi,\phi=\pi,\lambda=0,\gamma=0, U2U^{2} is implemented.

By choosing θ=π/2,ϕ=π/2,λ=π/2,γ=3π/4\theta=\pi/2,\phi=-\pi/2,\lambda=\pi/2,\gamma=3\pi/4, UU is implemented.

For the IQPE part, we also need to implement U1U^{-1} and U2U^{-2}. Since in this example, (U2)1=U2{(U^{2})}^{-1}=U^{2}, one can use the same set of parameters to implement (U2)1(U^{2})^{-1}.

However,

U1\displaystyle U^{-1} =12(1i1i1i1i)\displaystyle=\frac{1}{2}\begin{pmatrix}-1-i&1-i\\ 1-i&-1-i\end{pmatrix} (39)

We need to choose θ=π/2,ϕ=π/2,λ=π/2,γ=3π/4\theta=\pi/2,\phi=\pi/2,\lambda=-\pi/2,\gamma=-3\pi/4 to implement U1U^{-1}.

The controlled version of matrix UU^{\prime} can then be constructed using

CU=I|00|+U|11|\displaystyle C-U^{\prime}=I\otimes\ket{0}\bra{0}+U^{\prime}\otimes\ket{1}\bra{1} (40)

Note that in this equation, only the controlling clock bit and the b-register are included for simplicity. For example,

CU1\displaystyle C-U^{-1} =(1001)(1000)+12(1i1i1i1i)\displaystyle=\begin{pmatrix}1&0\\ 0&1\end{pmatrix}\otimes\begin{pmatrix}1&0\\ 0&0\end{pmatrix}+\frac{1}{2}\begin{pmatrix}-1-i&1-i\\ 1-i&-1-i\end{pmatrix}
(0001)\displaystyle\otimes\begin{pmatrix}0&0\\ 0&1\end{pmatrix}
=(1000000000100000)+12(000001i01i000001i01i)\displaystyle=\begin{pmatrix}1&0&0&0\\ 0&0&0&0\\ 0&0&1&0\\ 0&0&0&0\end{pmatrix}+\frac{1}{2}\begin{pmatrix}0&0&0&0\\ 0&-1-i&0&1-i\\ 0&0&0&0\\ 0&1-i&0&-1-i\end{pmatrix}
=12(200001i01i002001i01i)\displaystyle=\frac{1}{2}\begin{pmatrix}2&0&0&0\\ 0&-1-i&0&1-i\\ 0&0&2&0\\ 0&1-i&0&-1-i\end{pmatrix} (41)

III-C Implementataion of the Controlled-Rotation of Ancilla Qubit

The coefficients of |0\ket{0} and |1\ket{1} of the ancilla bit after rotation in Eq. (22) are 1C2λj~2\sqrt{1-\frac{C^{2}}{\tilde{\lambda_{j}}^{2}}} and Cλj~\frac{C}{\tilde{\lambda_{j}}}, respectively. The sum of the square of the magnitudes of the coefficients is 11 as required. This means also Cλj~C\leq\tilde{\lambda_{j}}. Since the minimal λj~\tilde{\lambda_{j}} is 11, we will set C=1C=1 to maximize the probability of measuring |1\ket{1} during the ancilla bit measurement.

The transformation of |0a\ket{0}_{a} to 11λj~2|0a+1λj~|1a\sqrt{1-\frac{1}{\tilde{\lambda_{j}}^{2}}}\ket{0}_{a}+\frac{1}{\tilde{\lambda_{j}}}\ket{1}_{a} is known to be equivalent to RY(θ)RY(\theta) rotation,

RY(θ)=(cos(θ2)sin(θ2)sin(θ2)cos(θ2))\displaystyle RY(\theta)=\begin{pmatrix}\cos(\frac{\theta}{2})&-\sin(\frac{\theta}{2})\\ \sin(\frac{\theta}{2})&\cos(\frac{\theta}{2})\end{pmatrix} (42)

with θ=2arcsin(1λj~)\theta=2\arcsin(\frac{1}{\tilde{\lambda_{j}}}). One can check this by multiplying RY(θ)RY(\theta) to |0a\ket{0}_{a}.

RY(θ)|0a=(cos(θ2)sin(θ2)sin(θ2)cos(θ2))(10)\displaystyle RY(\theta)\ket{0}_{a}=\begin{pmatrix}\cos(\frac{\theta}{2})&-\sin(\frac{\theta}{2})\\ \sin(\frac{\theta}{2})&\cos(\frac{\theta}{2})\end{pmatrix}\begin{pmatrix}1\\ 0\end{pmatrix}
=cos(θ2)|0a+sin(θ2)|1a\displaystyle=\cos(\frac{\theta}{2})\ket{0}_{a}+\sin(\frac{\theta}{2})\ket{1}_{a} (43)

Therefore, we will establish a function to implement this rotation and this function only need to be valid when the input are the encoded eigenvalues because only encoded eigenvalues have zero magnitudes in the c-register as shown in (21). The function is defined as

θ(c)=θ(c1c0)=2arcsin(1c)\displaystyle\theta(c)=\theta(c_{1}c_{0})=2\arcsin(\frac{1}{c}) (44)

where cc is the value of the clock qubits and c1c0c_{1}c_{0} is its binary form.

Since only |λj~\ket{\tilde{\lambda_{j}}} has non-zero amplitude in (21), we only need to set up (44) such that it is correct for |c\ket{c}=|01\ket{01} and |10\ket{10}, namely

θ(1)=θ(01)=2arcsin(11)=π\displaystyle\theta(1)=\theta(01)=2\arcsin(\frac{1}{1})=\pi (45)
θ(2)=θ(10)=2arcsin(12)=π3\displaystyle\theta(2)=\theta(10)=2\arcsin(\frac{1}{2})=\frac{\pi}{3} (46)

The following function can achieve the goal,

θ(c)=θ(c1c0)=π3c1+πc0\displaystyle\theta(c)=\theta(c_{1}c_{0})=\frac{\pi}{3}c_{1}+\pi c_{0} (47)

Therefore, the controlled rotation can be implemented as

|11|IRY(π3)+|00|II+\displaystyle\ket{1}\bra{1}\otimes I\otimes RY(\frac{\pi}{3})+\ket{0}\bra{0}\otimes I\otimes I+
I|11|RY(π)+I|00|I\displaystyle I\otimes\ket{1}\bra{1}\otimes RY(\pi)+I\otimes\ket{0}\bra{0}\otimes I (48)

where the operators operate on qubits |c1\ket{c_{1}}, |c0\ket{c_{0}}, and |a\ket{a} from left to right, respectively.

III-D Quantum Circuit

An HHL circuit for the numerical example is then built and shown in Figure 3. We will then walk through the circuit using numerical substitution.

Refer to caption
Figure 3: The HHL circuit corresponding to the numerical example built to run in IBM-Q. This circuit is partitioned in the same way as the general HHL schematic in Figure 1.

III-E Numerical Substitution

The algorithm begins with

|Ψ0=|0b|00c|0a=|0000\ket{\Psi_{0}}=\ket{0}_{b}\otimes\ket{00}_{c}\otimes\ket{0}_{a}=\ket{0000} (49)

X-gate is then applied to convert |0b\ket{0}_{b} to |1b\ket{1}_{b} with

|Ψ1=XII|Ψ0=|1000\ket{\Psi_{1}}=X\otimes I\otimes I\ket{\Psi_{0}}=\ket{1000} (50)

After applying the Hadamard gates to create a superposition among the clock qubits,

|Ψ2\displaystyle\ket{\Psi_{2}} =IHnI|Ψ1\displaystyle=I\otimes H^{\otimes n}\otimes I\ket{\Psi_{1}}
=|11222(|0+|1)2|0\displaystyle=\ket{1}\frac{1}{2^{\frac{2}{2}}}(\ket{0}+\ket{1})^{\otimes 2}\ket{0}
=12(|1000+|1010+|1100+|1110)\displaystyle=\frac{1}{2}(\ket{1000}+\ket{1010}+\ket{1100}+\ket{1110}) (51)

Before applying the CU3(controlled rotation of ancillary qubit) gates in the bra-ket notation, it will be convenient to perform a basis change to the eigenvector basis of AA. Since |1=12(|u0+|u1)\ket{1}=\frac{1}{\sqrt{2}}(-\ket{u_{0}}+\ket{u_{1}}), we have b0=12b_{0}=\frac{-1}{\sqrt{2}} and b1=12b_{1}=\frac{1}{\sqrt{2}}. Therefore,

|Ψ2\displaystyle\ket{\Psi_{2}} =|112(|000+|010+|100+|110)\displaystyle=\ket{1}\frac{1}{2}(\ket{000}+\ket{010}+\ket{100}+\ket{110})
=12(|u0+|u1)12(|000+|010+|100\displaystyle=\frac{1}{\sqrt{2}}(-\ket{u_{0}}+\ket{u_{1}})\frac{1}{2}(\ket{000}+\ket{010}+\ket{100}
+|110)\displaystyle+\ket{110})
=122(|u0|000|u0|010|u0|100\displaystyle=\frac{1}{2\sqrt{2}}(-\ket{u_{0}}\ket{000}-\ket{u_{0}}\ket{010}-\ket{u_{0}}\ket{100}
|u0|110+|u1|000+|u1|010\displaystyle-\ket{u_{0}}\ket{110}+\ket{u_{1}}\ket{000}+\ket{u_{1}}\ket{010}
+|u1|100+|u1|110)\displaystyle+\ket{u_{1}}\ket{100}+\ket{u_{1}}\ket{110}) (52)

In the controlled rotation operations, when the corresponding c-register is |kc\ket{k}_{c}, a phase change of ϕj=kλjt/2π\phi_{j}=k\lambda_{j}t/2\pi is added (i.e. multiplied by e2πiϕje^{2\pi i\phi_{j}}) for |uj\ket{u_{j}}. Since t=3π4t=\frac{3\pi}{4}, λ0=23\lambda_{0}=\frac{2}{3} and λ1=43\lambda_{1}=\frac{4}{3}, we have

|Ψ3\displaystyle\ket{\Psi_{3}} =122(|u0|000e2πiϕ0|u0|010\displaystyle=\frac{1}{2\sqrt{2}}(-\ket{u_{0}}\ket{000}-e^{2\pi i\phi_{0}}\ket{u_{0}}\ket{010}
e2πi2ϕ0|u0|100e2πi3ϕ0|u0|110+\displaystyle-e^{2\pi i2\phi_{0}}\ket{u_{0}}\ket{100}-e^{2\pi i3\phi_{0}}\ket{u_{0}}\ket{110}+
|u1|000+e2πiϕ1|u1|010\displaystyle\ket{u_{1}}\ket{000}+e^{2\pi i\phi_{1}}\ket{u_{1}}\ket{010}
+e2πi2ϕ1|u1|100+e2πi3ϕ1|u1|110)\displaystyle+e^{2\pi i2\phi_{1}}\ket{u_{1}}\ket{100}+e^{2\pi i3\phi_{1}}\ket{u_{1}}\ket{110})
=122(|u0|000eiλ0t|u0|010\displaystyle=\frac{1}{2\sqrt{2}}(-\ket{u_{0}}\ket{000}-e^{i\lambda_{0}t}\ket{u_{0}}\ket{010}
ei2λ0t|u0|100ei3λ0t|u0|110+\displaystyle-e^{i2\lambda_{0}t}\ket{u_{0}}\ket{100}-e^{i3\lambda_{0}t}\ket{u_{0}}\ket{110}+
|u1|000+eiλ1t|u1|010\displaystyle\ket{u_{1}}\ket{000}+e^{i\lambda_{1}t}\ket{u_{1}}\ket{010}
+ei2λ1t|u1|100+ei3λ1t|u1|110)\displaystyle+e^{i2\lambda_{1}t}\ket{u_{1}}\ket{100}+e^{i3\lambda_{1}t}\ket{u_{1}}\ket{110})
=122(|u0|000eiπ/2|u0|010eiπ|u0|100\displaystyle=\frac{1}{2\sqrt{2}}(-\ket{u_{0}}\ket{000}-e^{i\pi/2}\ket{u_{0}}\ket{010}-e^{i\pi}\ket{u_{0}}\ket{100}
ei3π/2|u0|110+|u1|000+eiπ|u1|010\displaystyle-e^{i3\pi/2}\ket{u_{0}}\ket{110}+\ket{u_{1}}\ket{000}+e^{i\pi}\ket{u_{1}}\ket{010}
+ei2π|u1|100+ei3π|u1|110)\displaystyle+e^{i2\pi}\ket{u_{1}}\ket{100}+e^{i3\pi}\ket{u_{1}}\ket{110})
=122(|u0|000i|u0|010+|u0|100\displaystyle=\frac{1}{2\sqrt{2}}(-\ket{u_{0}}\ket{000}-i\ket{u_{0}}\ket{010}+\ket{u_{0}}\ket{100}
+i|u0|110+|u1|000|u1|010+\displaystyle+i\ket{u_{0}}\ket{110}+\ket{u_{1}}\ket{000}-\ket{u_{1}}\ket{010}+
|u1|100|u1|110)\displaystyle\ket{u_{1}}\ket{100}-\ket{u_{1}}\ket{110}) (53)

Before applying IQFTIQFT, the terms are regrouped for simplicity.

|Ψ3\displaystyle\ket{\Psi_{3}} =122((|u0+|u1)|00+(i|u0|u1)|01\displaystyle=\frac{1}{2\sqrt{2}}((-\ket{u_{0}}+\ket{u_{1}})\ket{00}+(-i\ket{u_{0}}-\ket{u_{1}})\ket{01}
+(|u0+|u1)|10+(i|u0|u1)|11)|0\displaystyle+(\ket{u_{0}}+\ket{u_{1}})\ket{10}+(i\ket{u_{0}}-\ket{u_{1}})\ket{11})\ket{0} (54)

Now apply IQFTIQFT to the clock qubits, e.g.

IQFT|10\displaystyle\textrm{IQFT}\ket{10} =IQFT|2\displaystyle=\textrm{IQFT}\ket{2}
=122/2y=0221e2πi2y/4|y\displaystyle=\frac{1}{2^{2/2}}\sum_{y=0}^{2^{2}-1}e^{-2\pi i2y/4}\ket{y}
=12(|0|1+|2|3\displaystyle=\frac{1}{2}(\ket{0}-\ket{1}+\ket{2}-\ket{3}
=12(|00|01+|10|11)\displaystyle=\frac{1}{2}(\ket{00}-\ket{01}+\ket{10}-\ket{11}) (55)

Similarly,

IQFT|00\displaystyle\textrm{IQFT}\ket{00} =12(|00+|01+|10+|11)\displaystyle=\frac{1}{2}(\ket{00}+\ket{01}+\ket{10}+\ket{11}) (56)
IQFT|01\displaystyle\textrm{IQFT}\ket{01} =12(|00i|01|10+i|11)\displaystyle=\frac{1}{2}(\ket{00}-i\ket{01}-\ket{10}+i\ket{11}) (57)
IQFT|11\displaystyle\textrm{IQFT}\ket{11} =12(|00+i|01|10i|11)\displaystyle=\frac{1}{2}(\ket{00}+i\ket{01}-\ket{10}-i\ket{11}) (58)

Therefore, applying IQFTIQFT to |Ψ3\ket{\Psi_{3}} and substituting Eq. (55) to (58),

|Ψ4\displaystyle\ket{\Psi_{4}} =IQFT|Ψ3\displaystyle=\textrm{IQFT}\ket{\Psi_{3}}
=142\displaystyle=\frac{1}{4\sqrt{2}}
((|u0+|u1)(|00+|01+|10+|11)+\displaystyle((-\ket{u_{0}}+\ket{u_{1}})(\ket{00}+\ket{01}+\ket{10}+\ket{11})+
(i|u0|u1)(|00i|01|10+i|11)+\displaystyle(-i\ket{u_{0}}-\ket{u_{1}})(\ket{00}-i\ket{01}-\ket{10}+i\ket{11})+
(|u0+|u1)(|00|01+|10|11)+\displaystyle(\ket{u_{0}}+\ket{u_{1}})(\ket{00}-\ket{01}+\ket{10}-\ket{11})+
(i|u0|u1)(|00+i|01|10i|11))|0\displaystyle(i\ket{u_{0}}-\ket{u_{1}})(\ket{00}+i\ket{01}-\ket{10}-i\ket{11}))\ket{0}
=12(|u0|01+|u1|10)|0\displaystyle=\frac{1}{\sqrt{2}}(-\ket{u_{0}}\ket{01}+\ket{u_{1}}\ket{10})\ket{0} (59)

It can be seen that after IQFTIQFT, the eigenvalues are encoded in the clock qubits as |01\ket{01} and |11\ket{11} with non-zero amplitudes due constructive interference. b0=12b_{0}=\frac{-1}{\sqrt{2}} and b1=12b_{1}=\frac{1}{\sqrt{2}}. We clearly see the entanglement between the b-register and the c-register that |u0\ket{u_{0}} goes with |01\ket{01} and |u1\ket{u_{1}} goes with |11\ket{11}.

After performing the ancilla qubit rotation,

|Ψ5\displaystyle\ket{\Psi_{5}} =j=0211bj|uj|λj~(1C2λj~2|0+Cλj~|1)\displaystyle=\sum_{j=0}^{2^{1}-1}b_{j}\ket{u_{j}}\ket{\tilde{\lambda_{j}}}(\sqrt{1-\frac{C^{2}}{\tilde{\lambda_{j}}^{2}}}\ket{0}+\frac{C}{\tilde{\lambda_{j}}}\ket{1})
=12|u0|01(1112|0+11|1)+\displaystyle=-\frac{1}{\sqrt{2}}\ket{u_{0}}\ket{01}(\sqrt{1-\frac{1}{1^{2}}}\ket{0}+\frac{1}{1}\ket{1})+
12|u1|10(1122|0+12|1)\displaystyle\frac{1}{\sqrt{2}}\ket{u_{1}}\ket{10}(\sqrt{1-\frac{1}{2^{2}}}\ket{0}+\frac{1}{2}\ket{1}) (60)

If the measurement of the ancilla bit is |1\ket{1},

|Ψ6\displaystyle\ket{\Psi_{6}} =85(12|u0|01|1\displaystyle=\sqrt{\frac{8}{5}}(-\frac{1}{\sqrt{2}}\ket{u_{0}}\ket{01}\ket{1}
+122|u1|10|1)\displaystyle+\frac{1}{2\sqrt{2}}\ket{u_{1}}\ket{10}\ket{1}) (61)

Applying QFT to the encoded eigenvalues, we have

QFT|10\displaystyle\textrm{QFT}\ket{10} =QFT|2\displaystyle=\textrm{QFT}\ket{2}
=122/2y=0221e2πi2y/4|y\displaystyle=\frac{1}{2^{2/2}}\sum_{y=0}^{2^{2}-1}e^{2\pi i2y/4}\ket{y}
=12(|00|01+|10|11)\displaystyle=\frac{1}{2}(\ket{00}-\ket{01}+\ket{10}-\ket{11}) (62)
QFT|01\displaystyle\textrm{QFT}\ket{01} =QFT|1\displaystyle=\textrm{QFT}\ket{1}
=12(|00+i|01|10i|11)\displaystyle=\frac{1}{2}(\ket{00}+i\ket{01}-\ket{10}-i\ket{11}) (63)

Therefore, applying QFT to |Ψ6\ket{\Psi_{6}} and substituting Eq. (III-E) to (III-E), we obtain

|Ψ7\displaystyle\ket{\Psi_{7}} =85(12|u012(|00+i|01|10\displaystyle=\sqrt{\frac{8}{5}}(-\frac{1}{\sqrt{2}}\ket{u_{0}}\frac{1}{2}(\ket{00}+i\ket{01}-\ket{10}
i|11)|1+122|u112(|00|01\displaystyle-i\ket{11})\ket{1}+\frac{1}{2\sqrt{2}}\ket{u_{1}}\frac{1}{2}(\ket{00}-\ket{01}
+|10|11))|1\displaystyle+\ket{10}-\ket{11}))\ket{1} (64)

For the controlled rotation, the state is multiplied by eiλjte^{-i\lambda_{j}t} and ei2λjte^{-i2\lambda_{j}t} if c0=1c_{0}=1 and c1=1c_{1}=1, respectively. Since eiλ0t=ie^{-i\lambda_{0}t}=-i, ei2λ0t=1e^{-i2\lambda_{0}t}=-1, eiλ1t=1e^{-i\lambda_{1}t}=-1, ei2λ1t=1e^{-i2\lambda_{1}t}=1, and Nt/2πNt/2\pi=3/23/2

|Ψ8\displaystyle\ket{\Psi_{8}} =85(12|u012(|00+|01+|10+|11)|1\displaystyle=\sqrt{\frac{8}{5}}(-\frac{1}{\sqrt{2}}\ket{u_{0}}\frac{1}{2}(\ket{00}+\ket{01}+\ket{10}+\ket{11})\ket{1}
+122|u112(|00+|01+|10+|11))|1\displaystyle+\frac{1}{2\sqrt{2}}\ket{u_{1}}\frac{1}{2}(\ket{00}+\ket{01}+\ket{10}+\ket{11}))\ket{1}
=1285(12|u0+122|u1)(|00+|01\displaystyle=\frac{1}{2}\sqrt{\frac{8}{5}}(-\frac{1}{\sqrt{2}}\ket{u_{0}}+\frac{1}{2\sqrt{2}}\ket{u_{1}})(\ket{00}+\ket{01}
+|10+|11)|1\displaystyle+\ket{10}+\ket{11})\ket{1}
=12(23)85(1232|u0+1432|u1)(|00+|01\displaystyle=\frac{1}{2}(\frac{2}{3})\sqrt{\frac{8}{5}}(-\frac{1}{\frac{2}{3}\sqrt{2}}\ket{u_{0}}+\frac{1}{\frac{4}{3}\sqrt{2}}\ket{u_{1}})(\ket{00}+\ket{01}
+|10+|11)|1\displaystyle+\ket{10}+\ket{11})\ket{1} (65)

Finally, by applying Hadamard gate to the clock qubits,

|Ψ9\displaystyle\ket{\Psi_{9}} =2385(1232|u0\displaystyle=\frac{2}{3}\sqrt{\frac{8}{5}}(-\frac{1}{\frac{2}{3}\sqrt{2}}\ket{u_{0}}
+1432|u1)|00|1\displaystyle+\frac{1}{\frac{4}{3}\sqrt{2}}\ket{u_{1}})\ket{00}\ket{1} (66)

It can be verified that |Ψ9\ket{\Psi_{9}} is a normalized vector as it should be because every operation in the HHL circuit is unitary and preserves the norm.

Equation (III-E) can be simplified by substituting |u0=12|0+12|1\ket{u_{0}}=\frac{-1}{\sqrt{2}}\ket{0}+\frac{-1}{\sqrt{2}}\ket{1} and |u1=12|0+12|1\ket{u_{1}}=\frac{-1}{\sqrt{2}}\ket{0}+\frac{1}{\sqrt{2}}\ket{1}. We obtain,

|Ψ9\displaystyle\ket{\Psi_{9}} =1225(|0+3|1)|00|1\displaystyle=\frac{1}{2}\sqrt{\frac{2}{5}}(\ket{0}+3\ket{1})\ket{00}\ket{1} (67)

The probability ratio of obtaining |0\ket{0} and |1\ket{1} when b-register is measured is thus 1:91:9 as expected.

III-F Simulation Results

Matlab code implementing the numerical example using matrix approach is created and available at [21]. In the Matlab code, measurement is not performed (i.e. not partical tracing of the matrix). Ψ9\Psi_{9} is found to be,

|ψ9=(0.43300.25000.00000.00000.00000.00000.00000.00000.43300.75000.00000.00000.00000.00000.00000.0000)\ket{\psi_{9}}=\begin{pmatrix}-0.4330\\ 0.2500\\ 0.0000\\ -0.0000\\ 0.0000\\ -0.0000\\ 0.0000\\ 0.0000\\ 0.4330\\ 0.7500\\ -0.0000\\ 0.0000\\ -0.0000\\ 0.0000\\ -0.0000\\ 0.0000\\ \end{pmatrix} (68)

Since |0c\ket{0}_{c} are discarded during the measurement step, only |0001\ket{0001} and |1001\ket{1001} are left. Their amplitude ratio is 0.252:0.752=1:90.25^{2}:0.75^{2}=1:9 as expected.

The circuit in Fig. 3 is also simulated in the IBM-Q system (code available at [21]). Since only the b-register and the ancilla qubit are measured, there are only four possible outputs as shown in Figure 4. Again, only |1a\ket{1}_{a} should be considered. The ratio of the measurement probability of |0b|1a\ket{0}_{b}\ket{1}_{a} to |1b|1a\ket{1}_{b}\ket{1}_{a} is 0.063:0.564=1:8.950.063:0.564=1:8.95, which is close to the expected value.

Refer to caption
Figure 4: Simulation result of the circuit in Figure 3 using IBMQIBM-Q. Only the MSB |b\ket{\;}_{b}, and the LSB |a\ket{\;}_{a} are measured.

On the other hand, due to the imperfection and noise in a real quantum computer, the hardware execution of the same circuit does not give a satisfactory result (Figure 5). The ratio of the measurement probability of |0b|1a\ket{0}_{b}\ket{1}_{a} to |1b|1a\ket{1}_{b}\ket{1}_{a} is only 0.1422:0.3612=1:2.540.142^{2}:0.361^{2}=1:2.54.

Refer to caption
Figure 5: Hardware result of the circuit in Figure 3 run in machine ibmq_santiago. Only the MSB, |b\ket{\;}_{b} and the LSB, |a\ket{\;}_{a} are measured.

IV Conclusion

In this paper, we presented the HHL algorithm through a step-by-step walkthrough of the derivation. A numerical example is also presented in the bra-ket notation. The numerical example echos the analytical derivation to help students understand how qubits evolve in this important and relatively complex algorithm. A Matlab code corresponding to the numerical example is constructed to help understand the algorithm from the matrix point of view. Qiskit circuit of the corresponding circuit which can be simulated in IBM-Q and run on their quantum computing hardware is also available. Through this self-contained and step-by-step walkthrough, the basic concepts in quantum computing are reinforced.

V APPENDIX

V-1 Hermitian matrix

A Hermitian matrix is a matrix that equals to its adjoint matrix (transpose followed by complex conjugation). That is, if AA is a Hermitian matrix, then it is defined as,

A=A=(AT)\displaystyle A=A^{\dagger}=(A^{T})^{*} (V.1)

where ATA^{T} is the transpose of AA.

In this paper, the matrix, AA, in the LPS to be solved is assumed to be Hermitian.

Another example is in (III-B), where VV is Hermitian.

V=(u0u1)\displaystyle V=\begin{pmatrix}\vec{u_{0}}&\vec{u_{1}}\end{pmatrix}
=(12121212)\displaystyle=\begin{pmatrix}\frac{-1}{\sqrt{2}}&\frac{-1}{\sqrt{2}}\\ \frac{-1}{\sqrt{2}}&\frac{1}{\sqrt{2}}\end{pmatrix} (III-B)

V-2 Bra-ket Notation

Bra-ket notation is commonly used in quantum mechanics. A vector v\vec{v} is represented as |v\ket{v} in its ket form. The bra form of the vectors forms a dual space to the space of the kets. The bra form of v\vec{v} is v|\bra{v}.

In matrix representation, ket is the complex conjugate transpose of bra and vice versa. For example, if |v=(1i)\ket{v}=\begin{pmatrix}1\\ -i\end{pmatrix}, then v|=(1i.)\bra{v}=\begin{pmatrix}1&i.\end{pmatrix}

V-3 Superposition

Superposition or Quantum Superposition is a quantum state which is the linear combination of two or more basis states. For example, a superposition state can be |v=c1|1+c2|0\ket{v}=c_{1}\ket{1}+c_{2}\ket{0} , where c1c_{1} and c2c_{2} are complex number and |1\ket{1} and |0\ket{0} are basis states. A Hadamard gate is a gate commonly used to create a superposition state (Appendix V-5).

V-4 Basis Transformation and Quantum Gate

In quantum computing, we only care about the basis transformation due to rotation in the hyperspace. The transformation is equivalent to the multiplication of the basis vectors by a unitary matrix, UU, which is the transformation matrix. All quantum gates can be defined as how the basis vectors are transformed from the initial basis vector to the final basis vectors. Usually, a quantum gate rotates a basis state into another basis state (e.g. the NOT gate) and has its classical counterpart. But there are some gates that rotate a basis state to a superposition of two or more basis states. Such gates have no classical counterparts. For example, a Hadamard gate defines how an initial basis vector is rotated to an equal superposition of two basis vectors (Appendix V-5).

V-5 Hadamard Gate

The Hadamard gate is a quantum gate that does not have a classical counterpart. It rotates the basis state to create an equal superposition of the basis states. For a 1-qubit case, this means it has equal probability (i.e. 12\frac{1}{2}) of measuring |0\ket{0} and |1\ket{1}.

The matrix form of the Hadamard gate is,

12(1111)\displaystyle\frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\ 1&-1\\ \end{pmatrix} (V.2)

When it is applied on the basis state |1\ket{1}, which is (01)\begin{pmatrix}0\\ 1\\ \end{pmatrix} in matrix form, we have,

=12(1111)(01)\displaystyle=\frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\ 1&-1\\ \end{pmatrix}\begin{pmatrix}0\\ 1\\ \end{pmatrix} (V.3)
=12(11)\displaystyle=\frac{1}{\sqrt{2}}\begin{pmatrix}1\\ -1\\ \end{pmatrix} (V.4)

which can also be represented in bra-ket form as,

|0|12\displaystyle\frac{\ket{0}-\ket{1}}{\sqrt{2}} (V.5)

In this paper, Hadamard gates are applied in clock qubit to create superposition from |ψ1\ket{\psi_{1}} to |ψ2\ket{\psi_{2}}. For example, in (11),

|Ψ2=InbHnI|Ψ1\displaystyle\ket{\Psi_{2}}=I^{\otimes n_{b}}\otimes H^{\otimes n}\otimes I\ket{\Psi_{1}} (11)

where |ψ2\ket{\psi_{2}} is obtained by applying tensor product of identity gates and an nn-qubit Hadamard gate to |ψ1\ket{\psi_{1}}. The identity gates are applied to the b-register and the ancilla qubit while the Hadamard gate is applied to the clock qubits. In this equation, the nn-qubit Hadamard gate is represented as HnH^{\otimes n}, i.e. the tensor product of nn 1-qubit Hadamard gates.

V-6 Entanglement

Entanglement refers to the quantum state of a 2- or more-qubit system that cannot be expressed as a tensor product of the individual qubit. This is an important feature that quantum computing uses often. As an example,

|Ψ=12(|00+|11)\displaystyle\ket{\Psi}=\frac{1}{\sqrt{2}}(\ket{00}+\ket{11}) (V.6)

is an entangled state. It cannot be expressed as a tensor product of two individual qubit states.

In this paper, after the ancilla bit rotation, we have

|Ψ6=85(12|u0|01|1+122|u1|10|1)\displaystyle\ket{\Psi_{6}}=\sqrt{\frac{8}{5}}(-\frac{1}{\sqrt{2}}\ket{u_{0}}\ket{01}\ket{1}+\frac{1}{2\sqrt{2}}\ket{u_{1}}\ket{10}\ket{1}) (61)

where the b-register and the c-register are entangled and |u0\ket{u_{0}} (|u1\ket{u_{1}}) always appears with |01\ket{01} (|10\ket{10}) after the measurement.

If the b-register were not entangled with the c-register, we have

|Ψ6=85(12|u0+122|u1)\displaystyle\ket{\Psi_{6}}=\sqrt{\frac{8}{5}}(-\frac{1}{\sqrt{2}}\ket{u_{0}}+\frac{1}{2\sqrt{2}}\ket{u_{1}}) (V.7)

By substituting |u0=12|0+12|1\ket{u_{0}}=\frac{-1}{\sqrt{2}}\ket{0}+\frac{-1}{\sqrt{2}}\ket{1} and |u1=12|0+12|1\ket{u_{1}}=\frac{-1}{\sqrt{2}}\ket{0}+\frac{1}{\sqrt{2}}\ket{1} and after simplification, we have

|Ψ6\displaystyle\ket{\Psi_{6}} =85(12(12|0+12|1)+122(12|0+\displaystyle=\sqrt{\frac{8}{5}}(-\frac{1}{\sqrt{2}}(\frac{-1}{\sqrt{2}}\ket{0}+\frac{-1}{\sqrt{2}}\ket{1})+\frac{1}{2\sqrt{2}}(\frac{-1}{\sqrt{2}}\ket{0}+
12|1))\displaystyle\frac{1}{\sqrt{2}}\ket{1}))
=85(14|0+34|1)\displaystyle=\sqrt{\frac{8}{5}}(\frac{1}{4}\ket{0}+\frac{3}{4}\ket{1}) (V.8)

This is the same as (67). The probability of measuring |0\ket{0} and |1\ket{1} has the ratio of 1:9 as expected.

However, when there is entanglement, the probability of measuring |0\ket{0} and |1\ket{1} would not be 1:9 because the previous grouping is impossible.

|Ψ6\displaystyle\ket{\Psi_{6}} =85(12(12|0+12|1)|01+122(12|0\displaystyle=\sqrt{\frac{8}{5}}(-\frac{1}{\sqrt{2}}(\frac{-1}{\sqrt{2}}\ket{0}+\frac{-1}{\sqrt{2}}\ket{1})\ket{01}+\frac{1}{2\sqrt{2}}(\frac{-1}{\sqrt{2}}\ket{0}
+12|1))|10\displaystyle+\frac{1}{\sqrt{2}}\ket{1}))\ket{10} (V.9)

V-7 Controlled Operation

Controlled operation requires more than one qubit. For a 2-qubit controlled gate, an operation is applied to a qubit (the target qubit), if the value of the controlling qubit is 1 in the basis vector.

For example, in Figure 2, |b\ket{b} is the target qubit and |cn1\ket{c_{n-1}} is the controlling qubit. The operation of U2n1U^{2^{n-1}} is applied to |b\ket{b} only if |cn1\ket{c_{n-1}} is 1 in the basis state (e.g. |bcn1=|01\ket{bc_{n-1}\cdots}=\ket{01\cdots}.

In general, the controlled version of a unitary gate, UU^{\prime}, can be implemented using the following equation if the LSB is the controlling qubit.

CU=I|00|+U|11|C-U^{\prime}=I\otimes\ket{0}\bra{0}+U^{\prime}\otimes\ket{1}\bra{1} (40)

which literally means that if the controlling qubit is 0, Identity gate is applied to the target qubit (MSB). Otherise, UU^{\prime} is applied to the target qubit.

V-8 Eigenvalue and Eigenvector

When a non-zero n×nn\times n matrix AA is applied to an nn-dimensional vector V\vec{V} and has the following relationship,

AV=λV\displaystyle A\vec{V}=\lambda\vec{V} (V.10)

where λ\lambda is a scalar, then, by definition, V\vec{V} and λ\lambda are the eigenvector and eigenvalue of AA, respectively. This is similar to (3), where the matrix AA is expressed as a linear combination of the outer products of its eigenvectors, |uiui|\ket{u_{i}}\bra{u_{i}}.

A=i=02nb1λi|uiui|\displaystyle A=\sum_{i=0}^{2^{n_{b}}-1}\lambda_{i}\ket{u_{i}}\bra{u_{i}} (3)

This can be checked by applying AA to its eigenvector |uj\ket{u_{j}},

A|uj\displaystyle A\ket{u_{j}} =i=02nb1λi|uiui||uj\displaystyle=\sum_{i=0}^{2^{n_{b}}-1}\lambda_{i}\ket{u_{i}}\bra{u_{i}}\ket{u_{j}} (V.11)
=i=02nb1λi|uiδij\displaystyle=\sum_{i=0}^{2^{n_{b}}-1}\lambda_{i}\ket{u_{i}}\delta_{ij}
=λj|uj\displaystyle=\lambda_{j}\ket{u_{j}}

which meets the definition in Eq. (V.10).

V-9 Different Types of Encoding

The three common types of encodings are explained here.

  • Basis Encoding- Basis encoding converts classical information such as numbers or matrix to quantum information in the form of basis states. For example,

    x=2\displaystyle x=2 binary\displaystyle\underrightarrow{\textrm{binary}} 10\displaystyle 10 quantum state\displaystyle\underrightarrow{\textrm{quantum state}} |10\displaystyle\ket{10}
    x=(23)binary(1011)quantum state|1011\displaystyle x=\begin{pmatrix}2\\ 3\end{pmatrix}\underrightarrow{\textrm{binary}}\begin{pmatrix}10\\ 11\end{pmatrix}\underrightarrow{\textrm{quantum state}}\ket{1011} (V.12)
  • Amplitude Encoding- Amplitude encoding encodes the information as the coefficients of the basis vectors. For example, for

    v=(v0v1)\displaystyle\vec{v}=\begin{pmatrix}v_{0}\\ v_{1}\end{pmatrix} (V.13)

    which is assumed to be normalized (|v|=1|v|=1), it can be encoded as in the following quantum state,

    |v=v0|0+v1|1\displaystyle\ket{v}=v_{0}\ket{0}+v_{1}\ket{1} (V.14)

    where v0v_{0} and v1v_{1} become the coefficients of the basis states, |0\ket{0} and |0\ket{0}, respectively. In the main text, Eq. (9) shows how the values of the components of vector |b\ket{b} are encoded using amplitude encoding.

  • Hamiltonian Encoding- One type of the Hamiltonian encoding is to encode the matrix as the Hamiltonian in a unitary gate. For example, in this paper, Eq. (17) shows that

    U=eiAt\displaystyle U=e^{iAt} (17)

    where it encodes matrix AA as the Hamiltonian of the unitary gate UU. Matrix AA needs to be Hermitian as it is used to represent the Hamiltonian (the energy) of the system. However, AA does not need to be unitary and UU will be unitary due to its definition in (17).

V-10 Discrete Fourier Transform (DFT)

The discrete Fourier Transform (DFT) transforms an NN-dimensional vector X\vec{X} to another NN-dimensional vector Y\vec{Y}. The transformation matrix Ω\Omega contains the powers of the NN-th root of unity, ω=ei2π/N\omega=e^{i2\pi/N}. The transformation is represented as,

Y\displaystyle\vec{Y} =\displaystyle= ΩX\displaystyle\Omega\vec{X}
(y0y1yN1)\displaystyle\begin{pmatrix}y_{0}\\ y_{1}\\ \vdots\\ y_{N-1}\end{pmatrix} =1N(ω00ω0(N1)ω10ω1(N1)ω(N1)0ω(N1)(N1))\displaystyle=\frac{1}{\sqrt{N}}\begin{pmatrix}\omega^{-0\cdot 0}&\cdots&\omega^{-0\cdot(N-1)}\\ \omega^{-1\cdot 0}&\cdots&\omega^{-1\cdot(N-1)}\\ \vdots&\ddots&\vdots\\ \omega^{-(N-1)\cdot 0}&\cdots&\omega^{-(N-1)\cdot(N-1)}\end{pmatrix}
(x0x1xN1)\displaystyle\cdot\begin{pmatrix}x_{0}\\ x_{1}\\ \vdots\\ x_{N-1}\end{pmatrix} (V.15)

V-11 Inverse Quantum Fourier Transform (IQFT) and Quantum Fourier Transform(QFT)

Mathematically, IQFT is similar to DFT (See Appendix V-10). The transformation matrix, UIU_{I}, is N×NN\times N for an NN-dimensional Hilbert space. Therefore, N=2nN=2^{n} for an nn-qubit system. Eq. (V.15) becomes

|Y=UI|X\displaystyle\ket{Y}=U_{I}\ket{X} (V.16)

and UIU_{I} has the same expression as Ω\Omega in DFT.

UI=1N(ω00ω0(N1)ω10ω1(N1)ω(N1)0ω(N1)(N1))\displaystyle U_{I}=\frac{1}{\sqrt{N}}\begin{pmatrix}\omega^{-0\cdot 0}&\cdots&\omega^{-0\cdot(N-1)}\\ \omega^{-1\cdot 0}&\cdots&\omega^{-1\cdot(N-1)}\\ \vdots&\ddots&\vdots\\ \omega^{-(N-1)\cdot 0}&\cdots&\omega^{-(N-1)\cdot(N-1)}\end{pmatrix} (V.17)

Note that in some literature, e.g. [19], this form of IQFT is called QFT. |X\ket{X} and |Y\ket{Y} are the quantum states/vectors in the NN-dimensional Hilbert space. IQFT can be treated as the rotation of |X\ket{X} to |Y\ket{Y}.

If |X\ket{X} is a basis vector |k\ket{k}, applying IQFT to |k\ket{k} using Eq. (V.17), we have

UI|k=1Nj=0N1ωjk|j\displaystyle U_{I}\ket{k}=\frac{1}{\sqrt{N}}\sum_{j=0}^{N-1}\omega^{-jk}\ket{j} (V.18)

This is the equation used often in this paper. It tells us that by applying IQFT to a basis vector, the basis vector is rotated to a superposition of all basis vectors weighted by the powers of the NN-th root of unity.

For example, in (55) in the main text,

IQFT|10\displaystyle\textrm{IQFT}\ket{10} =IQFT|2\displaystyle=\textrm{IQFT}\ket{2}
=122/2y=0221e2πi2y/4|y\displaystyle=\frac{1}{2^{2/2}}\sum_{y=0}^{2^{2}-1}e^{-2\pi i2y/4}\ket{y}
=12(|0|1+|2|3\displaystyle=\frac{1}{2}(\ket{0}-\ket{1}+\ket{2}-\ket{3}
=12(|00|01+|10|11)\displaystyle=\frac{1}{2}(\ket{00}-\ket{01}+\ket{10}-\ket{11}) (55)

where N=22=4N=2^{2}=4, k=2k=2, j=yj=y in (V.18) is used. The basis state |10\ket{10} becomes a superposition of all other basis states after IQFTIQFT.

Another more complex example is the general equation,in (II-C), for the IQFTIQFT in Figure 1.

|Ψ4\displaystyle\ket{\Psi_{4}} =|bIQFT(12n2k=02n1e2πiϕk|k)|0a\displaystyle=\ket{b}\textrm{IQFT}(\frac{1}{2^{\frac{n}{2}}}\sum_{k=0}^{2^{n}-1}e^{2\pi i\phi k}\ket{k})\ket{0}_{a}
=|b12n2k=02n1e2πiϕk(IQFT|k)|0a\displaystyle=\ket{b}\frac{1}{2^{\frac{n}{2}}}\sum_{k=0}^{2^{n}-1}e^{2\pi i\phi k}(\textrm{IQFT}\ket{k})\ket{0}_{a}
=|b12nk=02n1e2πiϕk(y=02n1e2πiyk/N|y)|0a\displaystyle=\ket{b}\frac{1}{2^{n}}\sum_{k=0}^{2^{n}-1}e^{2\pi i\phi k}(\sum_{y=0}^{2^{n}-1}e^{-2\pi iyk/N}\ket{y})\ket{0}_{a}
=12n|by=02n1k=02n1e2πik(ϕy/N)|y|0a\displaystyle=\frac{1}{2^{n}}\ket{b}\sum_{y=0}^{2^{n}-1}\sum_{k=0}^{2^{n}-1}e^{2\pi ik(\phi-y/N)}\ket{y}\ket{0}_{a} (II-C)

Here, IQFTIQFT is applied to the c-register which is a superposition of basis states, |k\ket{k}. Using the distribution law of matrix operations, IQFTIQFT is applied to individual |k\ket{k} and (V.18) is used with y=jy=j and N=2nN=2^{n}.

QFT is the inverse of IQFTIQFT and can be treated as the rotation of the basis. The rotation matrix is given by

UQ=1N(1111ω1ω(N1)1ω2ω2(N1)1ω(N1)ω(N1)(N1))\displaystyle U_{Q}=\frac{1}{\sqrt{N}}\begin{pmatrix}1&1&\cdots&1\\ 1&\omega^{1}&\cdots&\omega^{(N-1)}\\ 1&\omega^{2}&\cdots&\omega^{2(N-1)}\\ \vdots&\vdots&\ddots&\vdots\\ 1&\omega^{(N-1)}&\cdots&\omega^{(N-1)(N-1)}\end{pmatrix} (V.19)

Equivalently,

UQ|k=1Nj=0N1ωjk|j\displaystyle U_{Q}\ket{k}=\frac{1}{\sqrt{N}}\sum_{j=0}^{N-1}\omega^{jk}\ket{j} (V.20)

It can be shown that UI=UQ1U_{I}=U_{Q}^{-1} or UIUQ=IU_{I}U_{Q}=I.

V-12 Implementation of QFTQFT and IQFTIQFT

QFTQFT and IQFTIQFT are constructed using Hadamard gates, controlled phase shift gates, and SWAPSWAP gates. Readers may refer to other sources for the details (e.g. [19]). Here, we show the circuit of a 2-qubit IQFTIQFT gate (Fig. 6).

Refer to caption
Figure 6: Implementation of a 2qubit inverse quantum Fourier transformation.

In general, the phase shift angle is ϕ=2π2r\phi=\frac{-2\pi}{2^{r}}, r1r-1 is the distance between the controlling qubit and the target qubit. For the 2-qubit IQFTIQFT case, there is only one controlled phase shift gate and r=2r=2 and this results in the phase ϕ=π2\phi=\frac{-\pi}{2}.

For QFT, the circuit is the same as the IQFTIQFT, but the phase shift is negated, i.e. ϕ=2π2r\phi=\frac{2\pi}{2^{r}}. This can be appreciated by the fact that the elements in the IQFTIQFT and QFTQFT have opposition signs in (V.17) and (V.19), respectively.

V-13 Gaussian elimination method

Here, Gaussian elimination is demonstrated by solving (1) using the numerical example in Section III.

Ax=b\displaystyle A\vec{x}=\vec{b} (1)
(113131)(x0x1)=(01)\displaystyle\begin{pmatrix}1&\frac{-1}{3}\\ \frac{-1}{3}&1\end{pmatrix}\begin{pmatrix}x_{0}\\ x_{1}\ \end{pmatrix}=\begin{pmatrix}0\\ 1\end{pmatrix} (V.21)

which is rewritten as an augmented matrix followed by Gaussian method of Elimination to solve for x0x_{0} and x1x_{1},

[11301311]Row2=3×Row2+Row1[11300833]\displaystyle\begin{bmatrix}1&\frac{-1}{3}&0\\ \frac{-1}{3}&1&1\end{bmatrix}\underrightarrow{\textrm{Row2}=3\times\textrm{Row2}+\textrm{Row1}}\begin{bmatrix}1&\frac{-1}{3}&0\\ 0&\frac{8}{3}&3\end{bmatrix}
Row2=38×Row2[3100198]\displaystyle\underrightarrow{\textrm{Row2}=\frac{3}{8}\times\textrm{Row2}}\begin{bmatrix}3&-1&0\\ 0&1&\frac{9}{8}\end{bmatrix}
[3100198]Row1=13×Row1+Row2[10380198]\displaystyle\begin{bmatrix}3&-1&0\\ 0&1&\frac{9}{8}\end{bmatrix}\underrightarrow{\textrm{Row1}=\frac{1}{3}\times\textrm{Row1}+\textrm{Row2}}\begin{bmatrix}1&0&\frac{3}{8}\\ 0&1&\frac{9}{8}\end{bmatrix}

This the solution x\vec{x} is

(x0x1)=(3898)\displaystyle\begin{pmatrix}x_{0}\\ x_{1}\end{pmatrix}=\begin{pmatrix}\frac{3}{8}\\ \frac{9}{8}\end{pmatrix}

The complexity of Gaussian Elimination is O(N3)O(N^{3}). This is much slower than the classical conjugate gradient method (Appendix V-14), to which HHL is compared.

V-14 Conjugate Gradient Method

The Conjugate Gradient Method (CGM) solves the LSP with a complexity of O(N)O(N) and is the fastest known classical solver. Therefore, the speed of HHL, which has a complexity of O(log(N))O(log(N)), is often compared to the speed of CGM [22]. Thus, HHL provides an exponential speedup over the fastest known classical method.

When we solve a system of linear equation, according to (Eq.(1)),where AA is a matrix, bb is a vector and xx is to be solved. If AA is a 2×22\times 2 matrix and bb is 2×12\times 1 ,then xx can be solved easily. But is AA is a long matrix, for example 1000,000,000×1000,000,0001000,000,000\times 1000,000,000 and bb is 1000,000,000×11000,000,000\times 1 vector, and NN in this case is 1000,000,0001000,000,000. To solve xx in Classical Gaussian Elimination method we need O(N3)O(N^{3}) speed, where OO is omega. In Classical Conjugate Gradient Method with sparse matrix that contains lots of zeros, it will take O(N)O(N) speed. And for HHL Quantum Algorithm, with sparse matrix, it takes O(log(N))O(log(N)) speed.

However, according to the paper [24], the speed of inner product in HHL Quantum Algorithm is only log(mn)/ϵlog(mn)/\epsilon steps when certain amplitudes is obtained and distinguished among other amplitudes, otherwise the speed is only quadratically faster than classical algorithm.

To solve (1) in CGMCGM method,

Ax=b\displaystyle A\vec{x}=\vec{b} (1)

initial guess of x\vec{x} is used as the starting point. The residual is then found and the search direction is determined by finding the steepest descent. This is repeated until a stable condition is met.

The residual in the kkþsearch is given as,

Rk=bAxk\displaystyle R_{k}=b-A\vec{x}_{k} (V.22)

The readers do not need to understand CGM to understand HHL. Interested readers may refer to the literature (e.g. [9]) for more details.

References

  • [1] P. W. Shor, “Algorithms for quantum computation: discrete logarithms and factoring,” Proceedings 35th Annual Symposium on Foundations of Computer Science, 1994, pp. 124–134, doi: 10.1109/SFCS.1994.365700.
  • [2] C. Outeiral, M. Strahm, J. Shi, G. M. Morris, S. C. Benjamin, and C. M. Deane, “The prospects of quantum computing in computational molecular biology,” WIREs Comput. Mol. Sci., 11, e1481 (2021).
  • [3] D. J. Egger et al., “Quantum Computing for Finance: State-of-the-Art and Future Prospects,” in IEEE Transactions on Quantum Engineering, 1, pp. 1–24, 2020, Art no. 3101724, doi: 10.1109/TQE.2020.3030314.
  • [4] Arute, F., Arya, K., Babbush, R. et al. Quantum supremacy using a programmable superconducting processor. Nature 574, 505–510 (2019). doi.org/10.1038/s41586-019-1666-5
  • [5] Madsen, L.S., Laudenbach, F., Askarani, M.F. et al. Quantum computational advantage with a programmable photonic processor. Nature 606, 75–81 (2022). doi.org/10.1038/s41586-022-04725-x
  • [6] N. David Mermin, ”Could Feynman Have Said This?,” Physics Today 57 (5), 10 (2004); doi: 10.1063/1.1768652
  • [7] A. Harrow, A. Hassidim, and S. Lloyd, ”Quantum algorithm for linear systems of equations,” Phys. Rev. Lett. 103, 150502 (2009).
  • [8] Yudong Cao, Anmer Daskin, Steven Frankel, and Sabre Kais, “Quantum circuit design for solving linear systems of equations,” Molecular Physics 110, 15–16 (2011).
  • [9] R. Chandra, S.C. Eisenstat, and M.H. Schultz, ”Conjugate Gradient Methods for Partial Differential Equations,” in the Proceedings of the AICA International Symposium on Computer Methods for Partial Differential Equations, Bethlehem, Pennsylvania, June 1975.
  • [10] S. Dmitry et al., “The Potential of Quantum Computing and Machine Learning to Advance Clinical Research and Change the Practice of Medicine.” Missouri medicine 115 (5), 463–467 (2018).
  • [11] Bojia Duan, Jiabin Yuan, Chao-Hua Yu, Jianbang Huang, and Chang-Yu Hsieh, ”A survey on HHL algorithm: From theory to application in quantum machine learning”, Physics Letters A 384, 126595 (2020).
  • [12] Shengbin Wang, Zhimin Wang, Wendong Li, Lixin Fan, Zhiqiang Wei, and Yongjian Gu, “Quantum fast Poisson solver: the algorithm and complete and modular circuit design,” Quantum Information Processing 19, Article number: 170 (2020).
  • [13] H. J. Morrell and H. Y. Wong, ”Study of using Quantum Computer to Solve Poisson Equation in Gate Insulators,” 2021 International Conference on Simulation of Semiconductor Processes and Devices (SISPAD), 2021, pp. 69-72, doi: 10.1109/SISPAD54002.2021.9592604.
  • [14] Schleich, P., 2019. How to solve a linear system of equations using a quantum computer. [Online]. Available: http://www.acom.rwth-aachen.de/_media/3teaching/ 00projects/schleich.pdf.
  • [15] HHL Example using Qiskit. [Online]. Available: https://qiskit.org/textbook/ch-applications/hhl_tutorial.html.
  • [16] Gadi Aleksandrowicz, et al., (2019). Qiskit: An Open-source Framework for Quantum Computing (0.7.2). Zenodo. doi.org/10.5281/zenodo.2562111.
  • [17] IBM Quantum Site. [Online]. Available: https://quantumcomputing.ibm.com/.
  • [18] Dominic W. Berry, Graeme Ahokas, Richard Cleve, and Barry C. Sanders, ”Efficient quantum algorithms for simulating sparse Hamiltonians,” arXiv:quant-ph/0508139, 2007.
  • [19] Hiu Yung Wong, Introduction to Quantum Computing: From a Layperson to a Programmer in 30 Steps. Switzerland: Springer Nature, 2022, pp. 170. doi.org/10.1007/978-3-030-98339-0. ISBN-10: 3030983382.
  • [20] Danial Dervovic, Mark Herbster, Peter Mountney, Simone Severini, Naïri Usher, and Leonard Wossnig, ”Quantum linear systems algorithms: a primer,” arXiv:1802.08227v1.
  • [21] Matlab code and Jupyter Notebook, [Online]. Available: https://github.com/hywong2/HHL_Example.
  • [22] Vandenbrocque, Adrien. ”On Quantum Algorithms for Solving Linear Systems of Equations.”Master’s semester Project I”, 2019. [Online]. Available: https://adrienvdb.com/projects-and-reports/.
  • [23] National Strategic Overview for Quantum Information Science Report (National Science and Technology Council, 2018). [Online]. Available: https://www.quantum.gov/wp-content/uploads/2020/10/ 2018_NSTC_National_Strategic _Overview_QIS.pdf.
  • [24] Aaronson, S. Read the fine print. Nature Phys 11, 291–293 (2015). [Online]. Available: https://doi.org/10.1038/nphys3272
\EOD