Topic 4 Quantum Algorithms
Topic 4 Quantum Algorithms
量子計算導論
1
Preliminary
Classical parallelism:
Uˆ
1
2 n
0 1 2n 1
Quantum parallelism:
1 ˆ
2 n
U 0 Uˆ 1 Uˆ 2n 1
Quantum parallelism:
X x | x 0,1, 2, 2 1
n
x Constant: f(X) = 0, or f(X) = 1
Task: which f ?
f ( x) f ( X / 2) 0
Balanced:
f ( X / 2) 1
• Example: for n = 3, at worst, Alice will need to query Bob with x = 0, 1, 2, 3, 4 to obtain
f(0), f(1), f(2), f(3), f(4), to determine f.
• For the classical case, at worst, Alice will need to query Bob at least 2n-1 + 1 times to
determine f.
4
Deutsch-Jozsa algorithm
• Quantum circuit of the Deutsch-Jozsa algorithm:
0 0 00
• n-qubit computational basis in the decimal representation:
n
1 0 01
n
n 1 n2 0
x x1 2 x2 2 xn 1 21
xn 2 2 010
n 1
x x1 , x2 , x3 , , xn | x 0,1, 2, , 2 n
3 011
n
n
n
2 1
111
5
n
Deutsch-Jozsa algorithm
• Quantum circuit of the Deutsch-Jozsa algorithm:
0 1
n
2 1
1
2n
n
0 1 2 2 1 Hˆ 1
1
2n
x 0
x
2
• Important technique:
0 1 0 1 0 1 000 001 010 011 100 101 110 111
6
0 1 2 3 4 5 6 7
Deutsch-Jozsa algorithm
• Quantum circuit of the Deutsch-Jozsa algorithm:
1 2n 1
0 1 1 2n 1
0 2 f ( x) 1 2 f ( x)
2 Uˆ f 1 f
Uˆ x
2
x
2
2n x 0 2n x 0
0 1
n
1 2 1
( 1) f ( x)
x
2
2n x 0
0 2 0 12 0 0 1
0 2 f ( x) 1 2 f ( x) 2 2 0 1
(1) f ( x )
2 0 2 1 1 2 1
0 1 2
7
2 2
Deutsch-Jozsa algorithm
• Quantum circuit of the Deutsch-Jozsa algorithm:
9
Nature 536, 63 (2016)
Grover’s algorithm
• Also known as quantum search algorithm. It was proposed by Lov Grover in 1996.
• How do you search M objects through N elements? For a classical computer, this can be
represented by a function f:{0, 1,…, N-1}→{0, 1}, which returns value f(x) = 1 if x is a
solution to the search problem, and f(x) = 0 otherwise. Typically, this takes O(N) steps.
• For a quantum computer with a quantum oracle Ô capable of recognizing the solution
to the search problem, then this can be represented with one more oracle qubit as:
Oˆ
x 0 x 0 f ( x)(mod 2) .
• The oracle qubit is |1⟩ if x is a solution, and is |0⟩ otherwise.
• The representation can be more concise if the oracle qubit is prepared in a superposition:
0 1 Oˆ 0 1 Oˆ
(1) x (1)
f (x) f (x)
x x x
2 2
• Namely, the oracle marks the solutions to the search problem by flipping the phase of
the solution.
• For an N-item search problem with M solutions, a quantum computer need only O( N / M )
steps, faster than a classical one.
10
Grover’s algorithm
• Schematic of the overall quantum search algorithm:
Grover operator
N 1
1
• The n-qubit state after the Hadamard transform: Hˆ n
0
N
x ,N 2 .
x 0
n
Steps 2~4
• The Grover operator Ĝ consists of four steps. The combined effect of steps 2~4 is
Hˆ n (2 0 0 Iˆ) Hˆ n 2 Iˆ → Reflection about the state |ψ〉!
• The overall effect of the Grover operator is written as Ĝ = (2|ψ〉
〈ψ|-Î)Ô. 11
Grover’s algorithm
• A 2-qubit example; N = 4, M = 1.
• The oracles corresponding to each desired solution :
f (0) 1 f (1) 1 f (2) 1 f (3) 1
f ( x ) 0, x 0 f ( x ) 0, x 1 f ( x ) 0, x 2 f ( x) 0, x 3
1 3 3 1 /3 /3
• The state before the Grover iteration is
4 x0
x
2
2
cos
2
sin
2
.
• Single Grover iteration moves |𝜓⟩ to |𝛽 ⟩. The measurement on the top two qubits gives
exactly the desired solution.
13
Grover’s algorithm
• Experimental demonstrations.
14
Phys. Rev. A 72, 050306(R) (2005) Nat. Commun. 8, 1918 (2017)
Quantum Fourier transform
1 N 1 i 2 j
1 2 2
i 2
2
i ( N 1)
e
i
1 N 1 i 2 jk
y1 N
xj ( x0 e x1 e
N N
x2 e N xN 1 )
yk
N j 0
e N
x j N j 0 N
N 1 i 2 2 j 2 2 2
1 1 i 2 i 4 i (2 N 2)
y2
N
e
j 0
N
xj
N
( x0 e N
x1 e N
x2 e N xN 1 )
15
Quantum Fourier transform
• n-qubit quantum Fourier transform in the decimal representation:
Orthonormal basis in the decimal representation: 0 , 1 , 2 , 3 , , 2 1
n
2n 1 i 2 jk
1
j
F
Fˆ j : e 2n
k
n
2 k 0
2n 1
n
2 1
n
2 1 2n 1 1 2n 1 i 2 jk
x j j
F
Fˆ x j j x j Fˆ j x j n e 2n
k
j 0 j 0 j 0 j 0 2 k 0
2
2n 1 1
2n 1 i n jk 2n 1
x j e 2 k yk k
k 0 j 0 2n k 0
2n 1 2n 1
x j j
yk kF
j 0 k 0
16
Quantum Fourier transform
• n-qubit quantum Fourier transform in the binary representation:
2n 1 i 2 j k 1 1 k1 2n1 k2 2n2 kn2 22 k n1 21 kn 20
1 1 i 2 j
j j1 j2 jn
F
Fˆ j : e 2n
k e 2n
k1k2 kn 2 k n 1kn
2 n
k 0 2 n
k1 0 kn 0
n
1
1 2 2 1 2n1 22 2 1
i 2 j n i 2 j n i 2 j n i 2 j
Fˆ j n / 2 0 00 e
2
0 01 e 2
010 e 2
011 e 2n
111
2
n n n n n
1
n1 n 2 2
2
i 2 j n
2
i 2 j n
2
i 2 j n
2
i 2 j n 1
i 2 j n
n/2 0 e 2 1 0 e 2
1 0 e 2 1 0 e 2 1 0 e 2 1
2
1 n2 1 n 1
j 2 j j 2 jn1 2 jn j 2 jn1 21 jn
1 j
i 2 n i 2 n1 2 n i 2 2 i 2 1
n/2 0 e 2
1 0 e 2
1 0 e 2n1
1 0 e 2n
1
2
1
n / 2 0 ei 2 (0. jn ) 1 0 ei 2 (0. jn1 jn ) 1 0 ei 2 (0. j2 j3 jn1 jn ) 1
2
0 ei 2 (0. j1 j2 j3 jn1 jn ) 1
2 2 j1 2n j2 2n 2 jn 1 21 jn
i 2 j n i 2 ( j1 2 j2 2 jn 1 2 jn ) n i 2
n 1 n2 1
i 2
2 2 2n 2n 1
• Meaning of digits:
decimal: 1234 1103 2 102 3 101 4 100
0.123 1 101 2 102 3 103
binary: 1101 1 23 1 22 0 21 1 20 13
1 0 1
0.101 1 21 0 22 1 23 0.625 17
2 4 8
Quantum Fourier transform
• n-qubit quantum Fourier transform in the binary representation:
1 2 1 n 1 1
j 2 j j 2 jn1 2 jn j 2 jn1 2 jn
1 j
i 2 n1 2 n i 2 n2 i 2 1
Fˆ j1 j2 jn n / 2 0 e
i 2 n
1 0 e 1 0 e 1 0 e 1
3 n
2 2 2 2
2
1
n / 2 0 ei 2 (0. jn ) 1 0 e i 2 (0. jn1 jn ) 1 0 ei 2 (0. jn2 jn1 jn ) 1 0 ei 2 (0. j1 j2 jn ) 1
2
• Quantum circuit of the quantum Fourier transform (up to swap operations):
1 0 1 0 1 0 1 0 1 0
where Rk 2 R1 2 R2 2 R3 2
0 e 2
i k
0 ei 2 0 1 0 e 2
i 2
0 e 2
i 3
1
H 0 (0 1) j
21/ 2 1 i 2 k 1
• Note that H jk 1/ 2 ( 0 e 2 1 ) 1/ 2 ( 0 ei 2 (0. jk ) 1 )
H 1 1 ( 0 1 ) 2 2
21/ 2
• We need n(n+1)/2 gates plus n/2 swap gates. → a Θ(n2) algorithm.
18
• Classical FFT needs Θ(n2n) gates.
Quantum Fourier transform
• Experimental demonstration.
19
Nature 536, 63 (2016)
Phase estimation
• Given a unitary operator (of any dimension) Û, it can be expressed in terms of the
eigenvalue decomposition Uˆ ei 2 u u .
u
• Suppose that we have an unknown unitary operator Û (sometimes known as oracles) with
an eigenstate |u〉 (could be also unknown) prepared in advance, such that Uˆ u ei 2 u .
What is the corresponding phase φ?
• Not that φ lies between 0 and 1; 0 < φ < 1.
• Schematic of the overall phase estimation procedure:
t-qubit register
Second stage
First stage
20
Phase estimation
• Output state:
1
2n / 2
0 e
i 2 2t 1
1 0 e
i 2 2t 2
1
0 e i 2 2 2
1 0 e i 2 21
1
0 e i 2 20
1 u
• Suppose that φ can be exactly expressed with t digits in the binary representation
as φ = 0.φ1φ2…φt-1φt. Then
1
2 n/2
0 ei 2 (0.t ) 1 0 ei 2 (0.t1t ) 1 0 ei 2 (0.2 t 1t ) 1 0 ei 2 (0.12t1t ) 1 u
• In fact, we do not know the exact number of t in advance. The number of qubits t depends
21
on the accuracy we wish to have in the estimation of φ.
Phase estimation
• [Problem] Suppose that x and N are given, we want to find the order r such that xr =
1(mod N).
• The basis of L-qubit register in the decimal representation:
y | y 0,1, 2, , N 1, N , , 2 1 0 0
L
00 , 1 0 01 , 2 010 , 3 011 , , 2 1 111
L
L L L L L
xy (mod N ) , 0 y N 1
• Consider the unitary operator: Uˆ y
y (mod N ) , N y 2 1
L
1 r 1 2 s k k
• For integer 0 ≤ 𝑠 ≤ 𝑟 − 1, the state us exp i x (mod N ) is an eigenstate
r k 0 r
of Û with eigenvalue exp(i2πs/r).
Example: x = 5, N = 31
2 s 1 2 s 2
1 0 i i
us 5 (mod 31) e 3
51
(mod 31) e 3
5 2
(mod 31)
3
2 s1 2 s2
1 i i
1(mod 31) e 3
5(mod 31) e 3
25(mod 31)
3
2 s 1 2 s 2
1 i i
Uˆ us 51
(mod 31) e 3
5 2
(mod 31) e 3
53
(mod 31)
3
2 s 1 2 s 1 2 s 2 2 s
i 1 i i i
e 3 e
3
5 (mod 31) e 3 5 (mod 31) 1(mod 31) e 3 us
1 2
24
3
Order-finding
s s
25
Order-finding
• [Issue 1] Suppose that we know Û|y〉= |xy(mod N), 0 ≤ y ≤ N-1. How can we compute
j
the sequence of controlled-U2 ?
• Modular exponential xz(mod N)
z y z Uˆ zt 2 Uˆ z3 2 Uˆ z2 2 Uˆ z1 2 y z x zt 2 x z3 2 x z2 2 x z1 2 y (mod N )
t 1 2 1 0 t 1 2 1 0
t 1
z3 2 2 z2 21 z1 20
z x zt 2 y (mod N ) z x z y (mod N ) .
• We use t 2 L 1 log 2 2 (2 ) 1 qubits in the first register and prepare the second
register in |1〉.
• Schematic of the overall order-finding procedure:
26
Order-finding
r 1
1
• The output state of the inverse FT (before performing the measurement) is
r
s 0
s us .
s
i 2
Uˆ us e r us
s s
r 1 r 1
s 1 1
0 us s
PhaseEstimation
us , s
r
0 1
r
s 0
0 us
PhaseEstimation
r
s 0
s us
• [Issue 3] Suppose that we have measured one φs. It is an approximation to the correct s/r
accurate to 2L+1 bits. How can we retrieve r from φs?
• The continued fraction is the representation of a real number by a sequence of integers:
1
a0 , a1 , , aM : a0 e.g. 31 2 5 2 1 2 1 2 1
2, 2,1,1, 2
1 13 13 13 3 1
a1 2 2
1 5 5 1
1
aM 1
1
2
• Suppose that φs = [a0, a1,…, aM] is a good approximation to s/r, i.e., |(s/r) - φs | ≤ 1/(2r2),
then s/r is a convergent of the continued fraction, i.e., [a0, a1,…, am] for 0 ≤ m ≤ M.
• [Final solution] By cutting the continued fraction for φs at different lengths, we obtain
several convergents for the candidate s’/r’. We then check whether these r’ are the
answer to the order-finding problem xr = 1(mod N).
Example: x = 5, N = 31, L = 5, t = 12
1365 1 1
1 0.333252... 0
1
0, 3,1365 0 0 0,3 0
4096 3 3
1365
1365 1 1 1 1 2
2 0.666504... 0,1,1,1, 682 0,1 0 1 0,1,1 0 1 0,1,1,1 0 1
2048 1 1 2 1 3
1 1
1
1 28
Factoring
29
Factoring
Theorem
Suppose N is an L-bit composite number, and 1 ≤ x ≤ N is a non-trivial
solution to the equation x2 = 1 (mod N), that is, neither x = 1 (mod N) nor
x = -1 = N-1 (mod N). Then at least one of gcd(x-1, N) and gcd(x+1, N) is
a non-trivial factor of N that can be computed using O(L3) operations.
Theorem
Suppose N = p1a1… pmam is the prime factorization of an odd composite
positive integer. Let 1 ≤ x ≤ N-1 be an integer chosen at random, subject
to the requirement that x is co-prime to N. Let r be the order of x modulo
N. Then
p(r is even and xr/2 ≠ -1(mod N)) ≥ 1 – 2-m.
30
Factoring
Factoring algorithm
1. Determine if N is trivially factorisable.
2. Randomly choose 1 ≤ x ≤ N-1. If gcd(x, N) > 1, return it.
3. To find the order r of x modulo N.
4. If r is even and xr/2 ≠ -1(mod N), then compute gcd(xr/2 -1, N) and
gcd(xr/2 +1, N). Each of these two integers may be a non-trivial factor
of N.
5. If not, repeat step 2.~4.
32
Factoring
• Experimental demonstrations of factoring 21 = 3 x 7.
33
Amplitude estimation
• Given a unitary operator 𝑈 acting on n+1 qubits such that 𝑈|0⊗ ⊗ |0⟩ =
1 − 𝑎|𝜓 ⟩ ⊗ |0⟩ + 𝑎|𝜓 ⟩ ⊗ |1⟩, where 𝑎 ∈ [0,1] is unknow and |𝜓 ⟩ and |𝜓 ⟩
are two n-qubit (normalized) states, not necessarily orthogonal. How to estimate 𝑎?
• The AE algorithm was first introduced in [Contem. Mathemat. 305, 53-74 (2002)]. It
combines the phase estimation (PE) and the Grover’s algorithm.
• Defining the oracle ˆ ˆ Uˆ † Sˆ ,
Qˆ US 0 0 where Sˆ 0 Iˆ 2 0 n
0 n 0 0 and Sˆ0 2 0 n 0 n Iˆ.
• Quantum circuit for the AE algorithm (notice the similarity to the PE algorithm):
P̂ 34
Amplitude estimation 0 0
Uˆ 0 n 1
• Similarly, the AE algorithm can be understood in a geometric manner.
a
• Note that Uˆ 0 n 0 1 a 0 0 a 1 1
1 1
sin a 0 0 cos a 1 1 , 0 a 1
P̂
• The first stage of the algorithm is to prepare the eigen state |𝜓 ⟩ with Pˆ
0 n 1 .
36
Amplitude estimation
P̂
1
n / 2 0 ei 2 (0.m ) 1 0 ei 2 (0. m1m ) 1 0 ei 2 (0.2 m1 m ) 1 0 ei 2 (0.12 m1m ) 1 .
2
37
(binary representation of θa in m digits)
Amplitude estimation
P̂
• May not necessary efficient to extract full information of the solution 𝑥⃗.
• Typically for solving the expectation value 𝑥⃗ ⋅ 𝑀 ⋅ 𝑥⃗.
39
HHL algorithm
• A quick review how we solve linear system of equations.
• Linear system of equations: 𝐴𝑥⃗ = 𝑏
where and
• Solution:
• Now working with the basis given by the eigenvectors of A , {|𝑢 ⟩, |𝑢 ⟩,…}.
|𝑏⟩ = 𝑏 |𝑢 ⟩ + 𝑏 |𝑢 ⟩ + ⋯
𝐴 = (2𝜋𝜆 )|𝑢 ⟩⟨𝑢 | + (2𝜋𝜆 )|𝑢 ⟩⟨𝑢 | + ⋯ → Rescaling the eigenvalues such
that0 ≤ 𝜆 < 1.
• Recall the binary representation of 𝜆 in t digits.
( ) ( ) ( )
𝜆 = 0. 𝜆 𝜆 𝜆 …𝜆 = + + ⋯+ , 𝜆 ,𝜆 ,…,𝜆 ∈ {0,1}
|𝜆 = |𝜆 𝜆 …𝜆
41
HHL algorithm
• Compare with our goal |𝑥 ⟩ = ∑ |𝑢 , we need to put the eigenvalues at the denominator.
• This is achieved by the controlled Ry-rotation subroutine. 42
HHL algorithm
• Measuring the ancillary qubit and postselecting the outcome 1. Then we have
|Ψ ⟩ = |1⟩|0⟩⊗ ∑ |𝑢 .
44
HHL algorithm
• Experimental realization
45
Simulating open quantum systems
• Every quantum gate (single qubit gate or multiqubit gate) provided by quantum computing
platforms, e.g., IBM Q, is an unitary operator.
46
Simulating open quantum systems
Iˆ
• Depolarizing channel: û( ) p (1 p )
2
• Bloch sphere representation of the effect of the depolarizing channel:
47
Simulating open quantum systems
1 0 0
• Amplitude damping channel: û( ) Eˆ1 Eˆ1† Eˆ 2 Eˆ 2† , Eˆ1 , ˆ
E
2
0 1 0 0
• Bloch sphere representation of the effect of the amplitude damping channel:
non-Markovian AD non-Markovian DP
50
Hybrid quantum-classical algorithms
• The computing power of near-term quantum computers remains limited due to, e.g.,
noises, qubit lifetime, intrinsic limitations of the physical devices, lack of appropriate
quantum algorithms, …
• An alternative approach is to combine quantum and conventional computers.
• We briefly introduce three examples:
1. Quantum support vector machine
2. Variational quantum eigensolver
Variational quantum algorithms
3. Quantum neural network
51
Quantum support vector machine
• Support vector machine (SVM) is a well-developed machine algorithm.
The basic idea underlying SVM is to construct a hyperplane to separate the datasets belonging to
distinct classes. More specifically, considering a binary classification task with training dataset
{(𝑥⃗ , 𝑦 )}, where 𝑥⃗ ∈ ℝ is the feature and 𝑦 ∈ {𝑅𝑒𝑑, 𝐵𝑙𝑢𝑒} is the label. Suppose that the data is
linearly separable, then goal of SVM is to find a vector 𝑤 ∈ ℝ and a parameter 𝑤 ∈ ℝ such that
𝑤 𝑥⃗ + 𝑤 ≥ 0, 𝑓𝑜𝑟 𝑦 = 𝑅𝑒𝑑
𝑤 𝑥⃗ + 𝑤 ≤ 0, 𝑓𝑜𝑟 𝑦 = 𝐵𝑙𝑢𝑒
,
meanwhile maximize the margin, which is the distance between the closest training points (the
support vectors) and the separating hyperplane 𝑤 𝑥⃗ + 𝑤 = 0.
• In most practical problems, the datasets are not linear separable. Then we need further
techniques.
• Feature map: mapping the data to higher dimensional parameter space.
• Kernel matrix 𝐾 = [𝑘(𝑥⃗ , 𝑥⃗ )]: estimation of the similarity between data points in the
higher dimensional parameter space without explicitly refer to the feature map.
52
• Then the classifier can be trained based on the kernel matrix 𝐾 .
Quantum support vector machine
• QSVM was first proposed in 2014. However, one of the critical issues is the assumption
that the data can be efficiently accessed quantum mechanically.
• Quantum feature map was introduced in 2019 to overcome the data accessibility.
53
Quantum support vector machine
• Advantage of QSVM was proved for a heuristic problem.
54
Variational quantum algorithms
• VQAs are hybrid algorithm combining the computing power of quantum and
classical computers.
• VQAs implement parametrized quantum circuits on quantum computers and
optimize the parameters with classical computers.
• Prominent applications include the variational quantum eigensolver and quantum
neural network.
55
Variational quantum eigensovler
57