HiPEAC'19 Tutorial on Quantum algorithms using QX - 2019-01-23
1. Quantum algorithms
on the QX Simulator
HiPEAC 2019, Valencia
Ir. Aritra Sarkar
Dr. Carmen G. Almudever
Prof. Dr. Koen Bertels
{A.Sarkar-3/C.GraciaAlmudever-1/K.L.M.Bertels}@tudelft.nl
Quantum Computer Architecture Lab
Delft University of Technology
2. 2
Using a QC 101
• For this part of the Tutorial, assume
– You have a “big” quantum computer
– The qubits are “perfect”
• What would you do with it?
– https://math.nist.gov/
• How would you do it?
– Quantum Programming
• Circuit builder
• QASM
• High-level language
4. 4
Necessary evil
a
2
b
2
• No-cloning theorem
– Qubits cannot be copied for QEC encoding
– Good for communication secrecy; bad for computing
• Participatory observer
– Measurement projects the superposition state probabilistically onto the basis states
• ۧ𝜓 = 𝛼 ۧ0 + 𝛽| ۧ1
• P +1 = 𝛼 2
• P −1 = 𝛽 2
– Non-unitary, non-reversible
– Fundamental indeterminacy, not measurement error!
– 1 measurement cannot reveal the initial state
• however, decides its final state
One can extract only the same amount of data from a quantum computer that one could from a classical computer of the same size
5. 5
Classical computing
• NAND gate + FanOut = all logic for classical Boolean algebra
• How to do classical computing with just 1 quantum gate?
– The Toffoli gate (a.k.a. CC-NOT; CCX)
• 2 control bits flip the target when both are high
• NAND: CCX = xy1, FanOut: CCX = 1x0
• How about an adder?
FANOUT
cba y
000 0
001 1
010 0
011 1
100 0
101 1
110 1
111 0
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0
6. 6
Dissecting a quantum algorithm
Superpose
Soln. Space
Encode
Function
Clever
Process
Measure
Initialize
|0ۧ⊗n
Classical
Output
Classical
Input
1. Prepare all-zero state for n-qubits (not so trivial experimentally as it sounds)
2. Full superposition in computational basis (H-gate on all qubits)
– OR, superposition of classical input space
3. Transform superposition to evaluate the function (using 1 & 2 qubit gates)
– OR, evaluate function based on classical input space
4. Somehow* increase the amplitude of the solution space
5. Measure out the state
6. Repeat Steps 1-5 to access the modal classical output
* the quantum magic of interference
7. 7
Objective randomness
• Pseudo-random numbers (PRN)
– Galois field e.g. PN-15 repeats after (215-1) cycles
– Randomizing a randomizer randomly to generate true random number (TRN)
• nope! PRN + PRN ≠ TRN (true entropy missing)
• knowing the seed can still predict the PRN with a TRN seed (e.g. from random.org)
– Wolfram Automata – deterministic, repeatable
– Digits of π or φ (Golden Mean)
– Chaotic system: small differences in the initial conditions results in unpredictable outcomes (complex but still deterministic)
• Random numbers are too important to be left to chance
• Objectively random: experiment controlling all causal parameters still leaves some random outcome
– Hidden variable theories reject the view that nature contains irreducible randomness
• “I am convinced God does not play dice.” - Albert Einstein
• “Don’t tell God what to do with his dice.” – Neils Bohr
8. 8
Quantum coin
• Disclaimer: Quantum computers are not hyper-Turing machines
– possible to completely simulate with classical UTM (albeit, with exponential time or space complexity)
– a classical TM can try all 2n paths corresponding to the possible random bit sequences of a probabilistic TM with n random bits
– Many Worlds interpretation: for every n entangled bits we can carry out a computation in all of 2n entangled parallel worlds, and
then get a little bit of this information back from each world. The clever bit is writing algorithms that guarantee that this little bit is
exactly what we need.
• Flipping a Quantum Coin
– 1 Non-unitary – Projection to ground state in computational basis
– 1 Unitary – Hadamard Gate
– 1 Non-unitary – Measurement in computational basis
• QX Code
• Uses
– Monte Carlo methods
– Cryptography
– Evolutionary algorithms
9. 9
Teleportation
• Transmit 1 qubit
– 1 previously shared Bell pair
– 2 cbits (nope!! not faster than light)
𝐻
y =a0 0 +a1 1
𝐻
𝑋 𝑍
y =a0 0 +a1 1
Share Bell pair
Bell pair measurement
Send
Decode
Received
C. H. Bennett, G. Brassard, C. Crépeau, R. Jozsa, A. Peres, and W. K. Wootters in 1993
10. 10
Bell test for spooky action
https://www.youtube.com/watch?v=AE8MaQJkRcg
11. 11
QX Demo Session 1
• Teleportation
– 𝛼0 = 0
– 𝛼1 = 1
– What happens when you replace x q0 with h q0?
qubits 3
.data
x q0 # create |psi>
.bell_pair
h q1
cnot q1,q2
.encode
cnot q0,q1
h q0
measure q0
measure q1
.decode
cx b1,q2
cz b0,q2
display
12. 12
Superdense coding
• Transmit 2 classical bits (opposite of Teleportation)
– 1 previously shared Bell pair
– 1 qubit
• If no shared entanglement, it is impossible to send two classical bits using 1 qubit, as this would violate Holevo's theorem
• Necessity of having both qubits to decode the information eliminates the risk of eavesdroppers intercepting messages
C. H. Bennett and S. J. Weisner in 1992
H
Prepare & Share
Bell pair
Encode Data
Receive & Decode
ZX
b2 b1
H
b2
b1
13. 13
RSA cryptosystem
• Take 2 prime numbers 𝑝 = 3, 𝑞 = 5
• 𝑁 = 𝑝. 𝑞 = 15
• Choose 𝑒 = 3 co-prime with (𝑝 − 1)(𝑞 − 1) = 8
– Check using Euclid’s algorithm – 𝑂(𝑛3)
• Public key is 𝑁, 𝑒
• Encrypted message is 𝐸𝑖 = 𝑀𝑖
𝑒
𝑚𝑜𝑑 𝑁
• Find 𝑑 = 3 such that, 𝒅. 𝒆 𝒎𝒐𝒅 (𝒑 − 𝟏)(𝒒 − 𝟏) = 𝟏
• Decrypted message is 𝐷𝑖 = 𝐸𝑖
𝑑 𝑚𝑜𝑑 𝑁
• Another example
• 𝑝 = 11, 𝑞 = 13, 𝑁 = 143, 𝑒 = 17
– gcd(𝑒, (𝑝 − 1)(𝑞 − 1)) = 1
• (𝑝 − 1)(𝑞 − 1) = 120
– 𝑑. 17 𝑚𝑖𝑑 120 = 1
– 𝑑 = 113
R. Rivest, A. Shamir and L. Adleman in 1977
NP
P
Bounded Quantum Polynomial
14. 14
Shor’s factorization
• Given N, factorize as a product of primes
– Check N is trivial to factorize using efficient classical methods (prime/even/integer power of prime) , ELSE
• Pick a random co-prime number 𝑎 < 𝑁, i.e. gcd 𝑎, 𝑁 = 1
• Pick a integer 𝑞 that is the power of 2 such that 𝑁2 ≤ 𝑞 < 2𝑁2
• Create 2 quantum registers ۧ|𝑟𝑒𝑔1, 𝑟𝑒𝑔2 each with enough qubits to represent integers as large as 𝑞 − 1
• Load 𝑟𝑒𝑔1 with equal superposition of 0 to q – 1 and load 𝑟𝑒𝑔2 with all zeros
• Apply transformation 𝑎 𝑥 𝑚𝑜𝑑 𝑁 to 𝑟𝑒𝑔1 and store the result in 𝑟𝑒𝑔2 (quantum parallelism)
• Compute the discrete Fourier transform on 𝑟𝑒𝑔1 (quantum parallelism)
• Measure 𝑟𝑒𝑔1 to find 𝑚, which is a multiple of 𝑞/𝑟
• Classical post-processing calculates 𝑟 based on 𝑚 and 𝑞
– Quantum period-finding subroutine to find 𝑟, the period of the function 𝑓 𝑥 = 𝑎 𝑥
𝑚𝑜𝑑 𝑁
• gcd(𝑎 𝑟/2 + 1, 𝑁) and gcd(𝑎 𝑟/2 − 1, 𝑁) are the nontrivial factors of 𝑁
• QFT required 𝑛(𝑛 + 1)/2 gates - polynomial time
– complexity class BQP
– exponentially faster than best classical algorithm
» the general number field sieve
16. 16
BB84 QKD
• BB84 quantum key distribution scheme and first provably secure quantum cryptography protocol
– A: Encode 4 ∗ |𝑘𝑒𝑦| random bits in selected basis (𝑍/𝑋/𝑌 at random)
– Each qubit in one of these 6 states: ۧ|0 Z, ۧ|1 Z, ۧ|0 X, ۧ|1 X, ۧ|0 Y, ۧ|1 Y
– B: Measure 4 ∗ |𝑘𝑒𝑦| received bits in selected basis (𝑍/𝑋/𝑌 at random)
– Share the basis information (2 ∗ |𝑘𝑒𝑦| bits will have same basis)
– Test |𝑘𝑒𝑦| bits to see if the channel is compromised, else use the other 𝑘𝑒𝑦 bits
– Information reconciliation with error-correction
– Privacy amplification for compromised bits (leftover hash lemma)
• also, E91
C. H. Bennett and G. Brassard in 1984
Key 0 1 1 0 1 0 0 0 1 1
Alice base Z X X X Z Z X Z X Z
Send state 0 - - + 1 0 + 0 - 1
Eve base X Z X X Z X Z X Z X
State +/- 0/1 - + 1 +/- 0/1 +/- 0/1 +/-
Eve Key 0 1 1 0 1 1 0 1 0 0
Bob base X X X Z X X X Z X X
State + +/- - 0/1 +/- - +/- 0/1 +/- 0
Bob Key 0 1 1 0 0 1 1 1 1 0
19. 19
QX Demo Session 2
• Grover search
– Full superposition of 3 qubits
– Mark state 101
– Invert about mean (Hn,CZn,Hn)
• Can we find more than 1 element?
• Can we start with an unequal superposition?
• Do we need to know the Oracle circuit before we code/compile?
qubits 3
prepz q0
prepz q1
prepz q2
.init
h q0
h q1
h q2
.grover(2)
#oracle
#inv_abt_mean
display
#amp_amplify
h q0
h q1
h q2
x q0
x q1
x q2
h q2
toffoli q0, q1, q2
h q2
x q2
x q1
x q0
h q2
h q1
h q0
#mark 101
x q1
h q2
toffoli q0, q1, q2
h q2
x q1
26. 26
Near-term algorithms
• Peter Shor’s estimates
– Without QEC, Shor’s algorithm needs ~5k qubits to factor cryptographically significant numbers
– With error correction, ~1 million
– ~100 millions gate operations
• Near-Term Quantum Algorithms
– runs on few qubits (low depth circuits) without extensive QEC (small-codes)
– enough qubits to just store the problem (hard to do better)
– still solve useful problems with local constraints
– Adaptable optimization algorithms (easy to map to problem) e.g. GA, SA, DL
• Quantum/classical hybrid algorithm
– Parameterised quantum subroutine is run within a classical optimization loop
– Variational theorem
– Heuristic, no general recipe that works universally for all problem
https://www.bcg.com/en-ca/publications/2018/next-decade-quantum-computing-how-play.aspx
27. 27
Quantum Approximate Optimization Algorithm
• Approximate algorithm for NP-Hard problems
– Polynomial-time solution for every instance with guaranteed quality
– QAOA is interesting because of its potential to exhibit quantum supremacy
– Structure
• Driver/Mixing function (solution space hard constraints)
• Cost function (problem soft constraints)
• Classical parameter optimizer
• Max-Cut: 𝑆 ⊆ 𝑉 (vertex set) such that the number of edges between 𝑆 and ҧ𝑆 is as large as possible
0
011110
100001
543210
1
2
34
5
111110
000001
101110
010001
30. 30
Quantum algorithms
on the QX Simulator
HiPEAC 2019, Valencia
Ir. Aritra Sarkar
Dr. Carmen G. Almudever
Prof. Dr. Koen Bertels
{A.Sarkar-3/C.GraciaAlmudever-1/K.L.M.Bertels}@tudelft.nl
Quantum Computer Architecture Lab
Delft University of Technology