Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019...

27
14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher Quantum Computing - Grover’s Algorithm Programming Quantum Computers: A Primer with IBM Q and D-Wave Exercises Patrick Dreher NC State University Chief Scientist - NCSU IBM Q Hub 1

Transcript of Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019...

Page 1: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Quantum Computing - Grover’s Algorithm Programming Quantum Computers:

A Primer with IBM Q and D-Wave Exercises

Patrick DreherNC State University

Chief Scientist - NCSU IBM Q Hub

1

Page 2: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Demo of the Grover Algorithm Using the Quirk Simulator

2

Page 3: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Grover Algorithm• Classically, searching an unsorted database requires a linear search

that is of O(N) in time. • Grover’s quantum search algorithm finds the unique input to a

black box function that produces a particular output value, with only O(N1/2) evaluations of the function with high probability

• It is the fastest possible quantum algorithm for searching an unsorted database and provides a quadratic speedup

• Reference:• Quantum Algorithm Implementation for Beginners https://arxiv.org/pdf/1804.03719

3

Page 4: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

• Find a unique item in an unstructured search among N items• Classically worst case requires check of N boxes• In quantum computer

• Prepare of superposition of initial states that are

• Oracle on |-> reverses the amplitude of that state

4

Grover Algorithm

𝑂𝑂|x ∗>|𝑓𝑓(𝑥𝑥 ∗) ⊕ |0 > −|𝑓𝑓(𝑥𝑥 ∗) ⊕ 1 > −|𝑓𝑓(𝑥𝑥 ∗) ⊕ 1 >

2= |𝑥𝑥 ∗>

|1 > −|0 >2

= −|𝑥𝑥 ∗>|0 > −|1 >

2

| +>=|0 > +|1 >

2| −>=

|0 > −|1 >2

Page 5: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Grover Algorithm

• Define Grover operator G and initial uniform superposition of states and O

• The amplitude of each state is flipped about the mean

• Applying makes |x*> have amplitude above the mean while all other states have an amplitude below the mean

5

|𝛹𝛹 >

]𝐺𝐺 = [2|𝛹𝛹 >< 𝛹𝛹| − 𝐼𝐼

𝐺𝐺 = [2|𝛹𝛹 >< 𝛹𝛹| − 𝐼𝐼]�𝑖𝑖

𝑎𝑎𝑖𝑖 |𝑖𝑖 >= �𝑖𝑖

�2 < 𝑎𝑎 > −𝑎𝑎𝑖𝑖]|𝑖𝑖 >

]𝐺𝐺 = [2|𝛹𝛹 >< 𝛹𝛹| − 𝐼𝐼

Page 6: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Implementation of the Algorithm1. Use the Quirk simulator (https://algassert.com/quirk )2. Initialization

• Initialize the qubits in a superposition with N-1/2 normalization (.25 for N=4)

3. Oracle• Implement the Oracle function

4. Amplification • Phase flip the amplitude about the average amplitude• Inverting the target state amplitude while keeping all other amplitudes unchanged

causes the target amplitude to increase while all other states decrease

5. Measurement• Perform a readout of the final qubit states

6

Page 7: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Initialization of 4 Qubit System• Quantum computing platforms are normally initialized as

• The procedure is to apply Hadamard gates to each qubit

|q0> |q1>|q2>|q3>

7

|𝟎𝟎 >= 𝟏𝟏𝟎𝟎

HHHH

Page 8: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Possible Oracle Configurations with 4 Qubits• With 4 qubits there are 16 possible oracle configurations

• States are initialized on QC platforms in the state

• Recall that the Z gate has the matrix representation

• Recall that the T gate has the matrix representation

8

|𝟎𝟎 >= 𝟏𝟏𝟎𝟎

𝟏𝟏 𝟎𝟎𝟎𝟎 −𝟏𝟏

𝟏𝟏 𝟎𝟎𝟎𝟎 𝒆𝒆𝒊𝒊

𝝅𝝅𝟒𝟒

Page 9: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 9

X

X

X

Z

X

X

X

X

X

Z

X

X

X

X

Z

X

XX

Z

X

0000

0010

0001

0011

XX X X

XX X X

Page 10: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 10

X

X

XZ

X

X

X

X

XZ

X

XX

XZ

X

X

XZ

X

0100

0110

0101

0111

Page 11: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 11

X

X

X

Z

X

X

X

X

X

Z

X

X

X

X

Z

X

XX

Z

X

1000

1010

1001

1011

Page 12: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 12

X

X

Z

X

X

X

Z

X

X

Z

X

1100

1110

1101

1111Z

Page 13: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Reference The Toffoli Gate Construction

• The Toffoli gate is a 3-bit gate, which is universal for classical computation• If the first two bits are in the state |1>, it applies a Pauli-X (NOT) on the

third bit, otherwise the state is left unchanged

13

|c>

|b> |b>

|c ab>⊕

|a> |a>

Page 14: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Properties of Toffoli Gates• Toffoli Gate is a reversible gate (i.e. UT

-1UT=I) or • Toffoli gate is used to replace a classical circuit with the equivalent

reversible gate• Two bits are control bits (|a> and |b>) and target bit |c> is flipped as

per the truth table(a, b, c) (a, b, c ab) (a, b, c)

• Toffoli gate and be used to simulate a NAND Gate

14

|1>

|b> |b>

|1 ab> = |ab>⊕

|a> |a>

¬

¬

Page 15: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Toffoli Gate Truth Table and Matrix

INPUT OUTPUT

a b c a’ b’ c’

0 0 0 0 0 0

0 0 1 0 0 1

0 1 0 0 1 0

0 1 1 0 1 1

1 0 0 1 0 0

1 0 1 1 0 1

1 1 0 1 1 1

1 1 1 1 1 0

15

1 0 0 0 0 0 0 00 1 0 0 0 0 0 00 0 1 0 0 0 0 00 0 0 1 0 0 0 00 0 0 0 1 0 0 00 0 0 0 0 1 0 00 0 0 0 0 0 0 10 0 0 0 0 0 1 0

X GatePauli rotation matrix𝜎𝜎𝑥𝑥

Page 16: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

4 Qubit Control-Z Gate • Within the Oracle there is multi-connected gate that as similar

characteristics to the Toffoli Gate

16

Page 17: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

CCC-Not Gate Construction• It should be possible to construct a CCC-Not gate using an array of CC-Not

gates combined with a sequence of 1 bit gates• Any 4-bit gate that has 3 controlled and one unitary transformation can be

represented* as where V is tuned such that V4 = U

17

U

*A. Barenco, C. Bennett, R. Cleve, D. P. DeVincenzo, N. Margolus, P. W. Shor, “Elementary Gates for Quantum Computation”, Phys. Rev A, March 1995

Page 18: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Amplification• This stage performs an inversion of the amplitudes about the

average

• From the initialization step the amplitude is .25 (N-1/2 where N=4)

• Avgamp = [(15)(0.25)+(-0.25)]/16 = 0.21875

• Indamp = 0.21875-(-0.25) = 0.46875

• The inversion of the Indamp about the average is 0.21875+0.46875 = 0.6875

• The amplitudes of the other states are 0.21875 - 0.25 = -0.03125• The other states have a value 0.21875 - 0.03125 = 0.1875

18

Page 19: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 19

Amplification Gate Structure

Page 20: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 20

Quantum Computing Circuits for |0000> OracleCCC-Not Gate Structure Amplification

Page 21: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 21

Final Measurement

Page 22: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 22

Final Measurement

Page 23: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 23

Page 24: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 24

Page 25: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 25

Final Measurement

Page 26: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher 26

Final Measurement

Page 27: Quantum Computing - Grover’s Algorithmmueller/qc/qc-tut/ASPLOS19-Grover.pdf14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher. Grover Algorithm •

14-April-2019 Introduction to Quantum Computing - ASPLOS Tutorial Patrick Dreher

Last Slide

27