Amira Abbas: Quantum Computing Lecture at Wits University PDF
Amira Abbas: Quantum Computing Lecture at Wits University PDF
Amira Abbas
Quantum Research Group
University of KwaZulu-Natal
Quantum Research Group
● Global/local partnerships
● Programmes/conferences/summer schools
Amira Abbas Source: Supervised Learning on Quantum Computers: Schuld & Petruccione 2018 Wits QC SS 2019
Quantum-classical machine learning
● Problem:
- want to predict if a passenger survived or not given how much they paid
and their cabin number
Amira Abbas Source: Supervised Learning on Quantum Computers: Schuld & Petruccione 2018 Wits QC SS 2019
Squared-distance classifier
[0910] [2105]
8500 1200
x1 = y1 = 1 x2 = y2 = 0
[0910] [2105]
8500 1200
x1 = y1 = 1 x2 = y2 = 0
[0.390] [0.990]
0.921 0.141
x1 = y1 = 1 x2 = y2 = 0
[0910] [2105]
8500 1200
x1 = y1 = 1 x2 = y2 = 0
[0.390] [0.990]
0.921 0.141
x1 = y1 = 1 x2 = y2 = 0
[0.500]
0.866 y new = ?
x new =
1 new
wm = 1 − | x − x m |2 for M data points
c
1 new
wm = 1 − | x − x m |2 for M data points
c
11
pxnew(y new = 0) =
∑
wm
χ i m|y m
=0
1 1
pxnew(y new = 1) =
∑
wm
χ M − i m|y m=1
[0.390] [0.990]
0.921 0.141
x1 = y 1
=1 x2 = y 2
=0
[0.500] [0.500]
0.866 0.866
x new = x new =
● Amplitude encoding
[0.390] [0.500]
0.921 0.866
x1 = x new =
[0.990] [0.500]
0.141 0.866
x2 = x new =
● Amplitude encoding
1 | 000⟩
[0.390] [0.500]
0.921 0.866 1 | 001⟩
x1 = x new =
1 | 010⟩
1 1 | 011⟩
[0.990] [0.500]
x2 =
0.141
x new =
0.866 8 1 | 100⟩
1 | 101⟩
1 | 110⟩
1 | 111⟩
● Amplitude encoding
0.921 | 000⟩
[0.390] [0.500]
0.921 0.866 0.390 | 001⟩
x1 = x new = | 010⟩
0.141
0.990 | 011⟩
[0.990] [0.500]
0.141 0.866 0.866 | 100⟩
x2 = x new =
0.500 | 101⟩
0.866 | 110⟩
0.500 | 111⟩
● Amplitude encoding
0.921 | 000⟩ y1 = 1
[0.390] [0.500]
0.921 0.866 0.390 | 001⟩ y1 = 1
x1 = x new = | 010⟩ y2 = 0
0.141
0.990 | 011⟩ y2 = 0
[0.990] [0.500]
0.141 0.866 0.866 | 100⟩
x2 = x new =
0.500 | 101⟩
0.866 | 110⟩
0.500 | 111⟩
● Amplitude encoding
0.921 | 000⟩ y1 = 1
[0.390] [0.500]
0.921 0.866 0.390 | 001⟩ y1 = 1
x1 = x new = | 010⟩ y2 = 0
0.141
0.990 | 011⟩ y2 = 0
[0.990] [0.500]
0.141 0.866 0.866 | 100⟩ y1 = 1
x2 = x new = y1 = 1
0.500 | 101⟩
0.866 | 110⟩ y2 = 0
0.500 | 111⟩ y2 = 0
Index Label
0.921 | 000⟩ | 1⟩
0.390 | 001⟩ | 1⟩
0.141 | 010⟩ | 0⟩
0.990 | 011⟩ | 0⟩
0.866 | 100⟩ | 1⟩
0.500 | 101⟩ | 1⟩
0.866 | 110⟩ | 0⟩
0.500 | 111⟩ | 0⟩
11 1
px new(y new = 0) = (1 − | x new − x m |2 )
∑
χ i m|y c
m =0 The measurement statistics of
the label qubit are the same
as the result of the classical
squared distance classifier!
1 1 1
px new(y new = 1) = (1 − | x new − x m |2 )
∑
χ M − i m|y m =1 c
index1 | 0⟩
index2 | 0⟩
index3 | 0⟩
label | 0⟩
index1 | 0⟩ H
index2 | 0⟩ H
index3 | 0⟩ H
label | 0⟩
| 000⟩
| 001⟩ 1
1
| 010⟩
1
| 011⟩ 1 1
→
| 100⟩ 8 1
| 101⟩ 1
1
| 110⟩ 1
Amira Abbas | 111⟩ Wits QC SS 2019
Quantum squared-distance classifier
index1 | 0⟩ H RY
index2 | 0⟩ H RY
index3 | 0⟩ H
RY
label | 0⟩
0.921 | 000⟩
Encode data
0.390 | 001⟩
0.141 | 010⟩
0.990 | 011⟩
0.866 | 100⟩
0.500 | 101⟩
0.866 | 110⟩
0.500 | 111⟩
Amira Abbas Wits QC SS 2019
Quantum squared-distance classifier
index1 | 0⟩ H RY
index2 | 0⟩ H RY
index3 | 0⟩ H
RY
label | 0⟩ X X X X
index1 | 0⟩ H RY H
index2 | 0⟩ H RY
index3 | 0⟩ H
RY
label | 0⟩ X X X X
0.921 | 000⟩ | 1⟩
Hadamard
0.390 | 001⟩ | 1⟩
transform
0.141 | 010⟩ | 0⟩
0.990 | 011⟩ | 0⟩
0.866 | 100⟩ | 1⟩
0.500 | 101⟩ | 1⟩
0.866 | 110⟩ | 0⟩
0.500 | 111⟩ | 0⟩
Amira Abbas Wits QC SS 2019
Quantum squared-distance classifier
index1 | 0⟩ H RY H
index2 | 0⟩ H RY
index3 | 0⟩ H
RY
label | 0⟩ X X X X
Conditional
measurement
index1 | 0⟩ H RY H
index2 | 0⟩ H RY
index3 | 0⟩ H
RY
label | 0⟩ X X X X
Conditional
measurement
| 0⟩
| 0⟩ Do something
U(x) ⟨Observable⟩
⋮ else
| 0⟩
Prepare some Encode data Other
Measure
initial state operations
Classical Quantum
● Eigenvalue/vector problem
● Variational circuits
● Quantum gradients
● Eigenvalue/vector problem
● Variational circuits
● Quantum gradients
f(x) = y
f(x) = y
y
f
f(x) = y
Approximate
y y
f
g(x; θ) = ŷ g
x x
f(x) = y
y y
f
g(x; θ) = ŷ g
x Update θ x
g→f
Amira Abbas Wits QC SS 2019
Cost/loss function
cost(θ, y,̂ y)
cost(θ, y,̂ y)
f(x) = y g(x; θ) = ŷ
cost(θ, y,̂ y)
f(x) = y g(x; θ) = ŷ
y y
f g
x x
cost(θ, y,̂ y)
f(x) = y g(x; θ) = ŷ
y y
f g
x x
cost(θ*, y,̂ y)
f(x) = y g(x; θ*) = ŷ
y y
f g
x x
cost(θ, y,̂ y)
cost(θ, y,̂ y)
cost
θ
Amira Abbas Wits QC SS 2019
Optimisation
cost
θ* θ
Amira Abbas Wits QC SS 2019
Gradient-based optimisation
cost
θ1 θ
Amira Abbas Wits QC SS 2019
Gradient-based optimisation
cost
θ1 θ
Amira Abbas Wits QC SS 2019
Gradient-based optimisation
cost
θ1 θ
Amira Abbas Wits QC SS 2019
Gradient-based optimisation
cost
θ2 θ1 θ
Amira Abbas Wits QC SS 2019
Gradient-based optimisation
cost
θ2 θ1 θ
Amira Abbas Wits QC SS 2019
Optimisation
cost
θ1 θ
Amira Abbas Wits QC SS 2019
Optimisation
cost
θ1 θ
Amira Abbas Wits QC SS 2019
Optimisation
cost
θ1 θ
Amira Abbas Wits QC SS 2019
Optimisation
| 0⟩
| 0⟩
| 0⟩
Prepare some
initial state
| 0⟩
| 0⟩
| 0⟩
| 0⟩
| 0⟩ U ⟨S⟩
| 0⟩
| 0⟩
| 0⟩ U(θ) ⟨Sθ⟩ = g(x; θ)
| 0⟩
| 0⟩
| 0⟩ U(θ) ⟨Sθ⟩ = g(x; θ)
| 0⟩
Cost fn
| 0⟩
| 0⟩ U(θ) ⟨Sθ⟩ = g(x; θ)
| 0⟩
Cost fn
∇θ Sθ
Amira Abbas Wits QC SS 2019
Variational circuits
| 0⟩
| 0⟩ U(θ) ⟨Sθ⟩ = g(x; θ)
| 0⟩
Update θ Cost fn
∇θ Sθ
Amira Abbas Wits QC SS 2019
Variational circuits
| 0⟩
| 0⟩ U(θ) ⟨Sθ⟩ = g(x; θ)
| 0⟩
Update θ Cost fn
∇θ Sθ
Amira Abbas Wits QC SS 2019
Problem?
| 0⟩ | 0⟩
∇θ Sθ = | 0⟩ U(θ + h) − | 0⟩ U(θ − h)
| 0⟩ | 0⟩
| 0⟩ | 0⟩
∇θ Sθ = | 0⟩ U(θ + h) − | 0⟩ U(θ − h)
| 0⟩ | 0⟩
∇θ Sθ = ⟨Sθ+h⟩ − ⟨Sθ−h⟩
| 0⟩
| 0⟩ U(θ*) ⟨Sθ*⟩
| 0⟩
Update θ Cost fn
● Hint: 12
3 Score: 3 + 1 + 3 = 7
3 2
1 3
3 MaxCut solution: 3 + 2 + 3 + 1 + 3 = 12
3 2
1 3
C
2
1
A
1 B
C
2
1
A
1 B
23 = 8 possibilities
C
2
1
A
1 B
CBA
3
2 = 8 possibilities | 000⟩
| 001⟩
C | 010⟩
2
| 011⟩
1 | 100⟩
A
| 101⟩
1 B | 110⟩
| 111⟩
Ĥ CBA
0000000000000000000000000000000
2 0 0 0 0 0 0 0 | 000⟩
0 −1 0 0 0 0 0 0 0 | 001⟩
0 0 0 0 0 0 0 0 0 | 010⟩
0 0 0 −1 0 0 0 0 0 | 011⟩
0 0 0 0 −1 0 0 0 0 | 100⟩
0 0 0 0 0 0 0 0 0 | 101⟩
0 0 0 0 0 0 −1 0 0 | 110⟩
0 0 0 0 0 0 0 2 0 | 111⟩
https://www.scottaaronson.com/qclec/25.pdf
Ĥ | 000⟩
0000000000000000000000000000000
2 0 0 0 0 0 0 0 1
0 −1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 −1 0 0 0 0 0 0
0 0 0 0 −1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 −1 0 0 0
0 0 0 0 0 0 0 2 0 0
Ĥ | 000⟩
0000000000000000000000000000000
2 0 0 0 0 0 0 0 1 2
0 −1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 −1 0 0 0 0 0 0 0
0 0 0 0 −1 0 0 0 0 0 = 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 −1 0 0 0 0
0 0 0 0 0 0 0 2 0 0 0
Ĥ | 000⟩
Ĥ | 011⟩
0000000000000000000000000000000
2 0 0 0 0 0 0 0 0 0
0 −1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 −1 0 0 0 0 0 1 −1
0 0 0 0 −1 0 0 0 0 0 = 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 −1 0 0 0 0
0 0 0 0 0 0 0 2 0 0 0
Ĥ | 011⟩
⟨011 | Ĥ | 011⟩
0
0000000000000000000000000000000
2 0 0 0 0 0 0 0
0 −1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 −1 0 0 0 0 0 1
[00010000] 0 0 0 0 −1 0 0 0 0 0 = −1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 −1 0 0 0
0 0 0 0 0 0 0 2 0 0
⟨011 | Ĥ | 011⟩
| ψ⟩ U(θ) ⟨ψ | Ĥ | ψ⟩
Update θ Cost fn
| 0⟩ H
| 0⟩ H
| 0⟩ H
| 000⟩
| 001⟩
| 010⟩
| 011⟩
| ψ⟩ →
| 100⟩
| 101⟩
| 110⟩
Amira Abbas | 111⟩ Wits QC SS 2019
Variational Quantum Eigensolver (VQE)
| 0⟩ H Ry(θ1)
| 0⟩ H Ry(θ2)
| 0⟩ H Ry(θ3)
(Made up example)
| ψ⟩
| 0⟩ H Ry(θ1)
| 0⟩ H Ry(θ2)
| 0⟩ H Ry(θ3)
| ψ⟩ Ĥ | ψ⟩
| 0⟩ H Ry(θ1)
| 0⟩ H Ry(θ2) ⟨ψ | Ĥ | ψ⟩
| 0⟩ H Ry(θ3)
| 0⟩ H Ry(θ1)
| 0⟩ H Ry(θ2) ⟨ψ | Ĥ | ψ⟩
| 0⟩ H Ry(θ3)
̂
cost(θi, ⟨H⟩)
| 0⟩ H Ry(θ1)
| 0⟩ H Ry(θ2) ⟨ψ | Ĥ | ψ⟩
| 0⟩ H Ry(θ3)
Update θi ̂
cost(θi, ⟨H⟩)
| 0⟩ H Ry(θ1)
| 0⟩ H Ry(θ2) ⟨ψ | Ĥ | ψ⟩
| 0⟩ H Ry(θ3)
Update θi ̂
cost(θi, ⟨H⟩)
| 000⟩
| 001⟩
| 010⟩
| 011⟩
| ψ⟩ →
| 100⟩
⟨ψ | Ĥ | ψ⟩ ̂
cost(θi, ⟨H⟩)
| 101⟩
| 110⟩
| 111⟩
| 000⟩
| 001⟩
| 010⟩ C
2
| 011⟩
| ψ⟩ → 1 ̂
cost(θi, ⟨H⟩)
| 100⟩ A
| 101⟩
1 B
| 110⟩
| 111⟩
Source:https://github.com/Qiskit/qiskit-iqx-tutorials/blob/master/qiskit/advanced/aqua/optimization/max_cut_and_tsp.ipynb
• QML Book: Schuld, Maria, and Francesco Petruccione. Supervised Learning with
Quantum Computers. Vol. 17. Springer, 2018.