qdb: from quantum algorithms towards correct quantum … · qdb: from quantum algorithms towards...

1
Yipeng Huang, Margaret Martonosi QDB: From Quantum Algorithms Towards Correct Quantum Programs Superconducting qubits Trapped ion qubits IBM Google Intel Rigetti University of Maryland / IonQ Classical value Deterministic Hadamard gate A quantum operator Quantum qubit Superposition Measurement Collapses state |0 = 1 0 |1 = 0 1 &= 1 2 1 1 1 −1 )=& |0 )= 1 2 |0 + 1 2 |1 +=, 0, . = / 1 2 1, . = / 1 2 & |0 + ) ! | 0 % & % ' |0 Two qubits Tensor product Product state Can be factored Controlled-NOT Two-qubit operator Entangled state Cannot be factored Measurement Results correlated |0⊗ |0 = 1 0 0 0 = |00 1 2 1 1 1 0 = 1 2 |00 + 1 2 |10 CNOT = 1 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1= 1 2 |00 + 1 2 |11 % & ,% ' = 3 (0,0), 6 = 7 1 2 (1,1), 6 = 7 1 2 1 Quantum chemistry algorithms Calculating molecule properties from first principles Use quantum mechanical system to simulate quantum mechanics! Near term: needs few qubits, needs no error correction Shor’s integer factorization quantum algorithm Factors large integers in polynomial time! (known best classical algorithms take exponential time) Distant future: needs many qubits, needs error correction Semantic gap Need languages, abstractions… Tools gap Need optimizing compilers, simulators, debuggers… Infrastructure gap Need more abundant, more reliable qubits… Educational gap Need researchers, college curricula, K-12 pipeline… Quantum algorithms GAP! Quantum physical devices Detailed debugging effort across quantum algorithms Huge state space limits simulation to ‘toy’ problems Where possible, validate across quantum languages Superposition underlies power, but precludes ‘printf’ Teams now racing towards accurate and more qubits Bug type 1: classical input parameters Bug type 2: quantum initial values Bug type 3: coding up basic operations Bug type 4A: iterating operations Bug type 4B: recursing operations Bug type 4C: mirroring operations Bug type 5: qubit garbage collection Defense 1: algorithm progress assertions Defense 2: pre- condition assertions Defense 3: support for modules and unit tests Defense 4A: support for numeric data types Defense 4B: support for controlled operations Defense 4C: support for reversible compute Defense 5: post- condition assertions An NSF Expedition in Computing !, the algorithm iteration 0 1 2 3 "=7 % & mod 15 7 4 1 1 " ,- ; "×" ,- ≡ 1 mod 15 13 12 4 1 1 Image credit: Metodi, Faruque, and Chong, Quantum Computing for Computer Architects, 2nd Ed., p26 Precondition: uniform distribution Precondition: any integer Rz(q1, +angle/2); // C CNOT(q0, q1); Rz(q1, -angle/2); // B CNOT(q0, q1); Rz(q0, +angle/2); // D CNOT(q0, q1); Rz(q1, -angle/2); // B CNOT(q0, q1); Rz(q1, +angle/2); // A Rz(q0, +angle/2); // D Rz(q1, -angle/2); CNOT(q0, q1); Rz(q1, +angle/2); CNOT(q0, q1); Rz(q0, +angle/2); // D Correct, operation A unneeded Correct, operation C unneeded Incorrect, angles flipped Unneeded? But angles wrong! U q 0 q 1 C q 0 q 1 B A D = module cADD ( const unsigned int c_width, // number of control qubits qbit ctrl0, qbit ctrl1, // control qubits const unsigned int width, const unsigned int a, qbit b[] ) { for (int b_indx=width-1; b_indx>=0; b_indx--) { for (int a_indx=b_indx; a_indx>=0; a_indx--) { if ((a >> a_indx) & 1) { // shift out bits in constant a double angle = M_PI/pow(2,b_indx-a_indx); // rotation angle switch ( c_width) { case 0: Rz ( b[b_indx], angle ); break; case 1: cRz ( ctrl0, b[b_indx], angle ); break; case 2: ccRz ( ctrl0, ctrl1, b[b_indx], angle ); break; }}}}} probability output 0 1 2 3 4 5 6 7 ancilla 0 1/8 0 1/8 0 1/8 0 1/8 0 4 1/64 1/64 1/64 1/64 1/64 1/64 1/64 1/64 7 1/64 1/64 1/64 1/64 1/64 1/64 1/64 1/64 8 1/64 1/64 1/64 1/64 1/64 1/64 1/64 1/64 13 1/64 1/64 1/64 1/64 1/64 1/64 1/64 1/64 Beauregard, 2003 Mirror image submodules Image credit: Metodi, Faruque, and Chong, Quantum Computing for Computer Architects, 2nd Ed., p26 Classify quantum programming bugs, pair with defenses, debugging and assertions

Upload: others

Post on 27-Mar-2020

15 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: QDB: From Quantum Algorithms Towards Correct Quantum … · QDB: From Quantum Algorithms Towards Correct Quantum Programs Yipeng Huang, Margaret Martonosi | Princeton University 7

Yipeng Huang, Margaret Martonosi

QDB: From Quantum Algorithms Towards Correct Quantum Programs

Motivation: race to quantum supremacy

Superconducting qubits Trapped ion qubits

IBM Google Intel RigettiUniversity of Maryland /

IonQ

Many research teams now competing towards more reliable and more numerous qubits.

QDB: From Quantum Algorithms Towards Correct Quantum ProgramsYipeng Huang, Margaret Martonosi | Princeton University 2

Quantum computing primer to understand debugging

Classical valueDeterministic

Hadamard gateA quantum operator

Quantum qubitSuperposition

MeasurementCollapses state

⟩|0 = 10

⟩|1 = 01

& = 121 11 −1

) = & ⟩|0) = 1

2⟩|0 + 1

2⟩|1 + = ,

0, . = /1 21, . = /1 2

&⟩|0 +)

We cannot pause a quantum computer and “printf debug”, because measurement collapses state.

Quantum programming is the process of converting quantum circuit diagrams to quantum code.

Quantum computing primer to understand debugging!⟩|0 %&

%'⟩|0

Possibility of entanglement leads to huge state space underlying power of quantum computing.

Two qubitsTensor product

Product stateCan be factored

Controlled-NOTTwo-qubit operator

Entangled stateCannot be factored

MeasurementResults correlated

⟩|0 ⊗ ⟩|0 =1000= ⟩|00

1211 ⊗ 1

0

= 12

⟩|00 + 12

⟩|10CNOT =

1 00 1

0 00 0

0 00 0

0 11 0

1 = 12

⟩|00 + 12

⟩|11

%&,%'

= 3(0,0), 6 = 71 2(1,1), 6 = 71 2

1

Huge state space limits us to simulating only toy-sized quantum programs.

Motivation: Race to practical quantum computation

QDB: From Quantum Algorithms Towards Correct Quantum ProgramsYipeng Huang, Margaret Martonosi | Princeton University 5

Quantum chemistry algorithms• Calculating molecule properties from first principles• Use quantum mechanical system to simulate quantum mechanics!• Near term: needs few qubits, needs no error correction

Shor’s integer factorization quantum algorithm• Factors large integers in polynomial time!• (known best classical algorithms take exponential time)• Distant future: needs many qubits, needs error correction

Many more algorithms: https://math.nist.gov/quantum/zoo/

QDB: From Quantum Algorithms Towards Correct Quantum ProgramsYipeng Huang, Margaret Martonosi | Princeton University 7

Semantic gap• Need languages, abstractions…Tools gap• Need optimizing compilers, simulators, debuggers…Infrastructure gap• Need more abundant, more reliable qubits…Educational gap• Need researchers, college curricula, K-12 pipeline…

Quantum algorithms

GAP!Quantum physical devices

Detailed debugging effort across quantum algorithms

Huge state space limits simulation to ‘toy’ problems

Where possible, validate across quantum languages

Superposition underlies power, but precludes ‘printf’

Teams now racing towards accurate and more qubits

Bug type 1: classical

input parameters

Bug type 2: quantum

initial values

Bug type 3: coding

up basic operations

Bug type 4A: iterating

operations

Bug type 4B: recursing

operations

Bug type 4C: mirroring

operations

Bug type 5: qubit

garbage collection

Defense 1: algorithm progress

assertions

Defense 2: pre-

condition assertions

Defense 3: support for

modules and unit

tests

Defense 4A:

support for numeric

data types

Defense 4B:

support for controlled operations

Defense 4C:

support for reversible compute

Defense 5: post-

condition assertions

An NSF Expedition in Computing

Beauregard, 2003

Bug type 4: incorrect classical input parameters

Classical inputparameters

!, the algorithm iteration 0 1 2 3 …

" = 7%& mod 15 7 4 1 1 …

",-; "×",- ≡ 1 mod 15 13 12 4 1 1 …

QDB: From Quantum Algorithms Towards Correct Quantum ProgramsYipeng Huang, Margaret Martonosi | Princeton University 38

Bug type 1: mistake in quantum initial values

Image credit: Metodi, Faruque, and Chong, Quantum Computing for Computer Architects, 2nd Ed., p26

Precondition:uniform distribution

Precondition:any integerE.g., controlled-Rz:

Rz(q1, +angle/2); // CCNOT(q0, q1);Rz(q1, -angle/2); // BCNOT(q0, q1);Rz(q0, +angle/2); // D

CNOT(q0, q1);Rz(q1, -angle/2); // BCNOT(q0, q1);Rz(q1, +angle/2); // ARz(q0, +angle/2); // D

Rz(q1, -angle/2); CNOT(q0, q1);Rz(q1, +angle/2); CNOT(q0, q1);Rz(q0, +angle/2); // D

Correct,operation A unneeded

Correct,operation C unneeded

Incorrect,angles flipped

Bug type 2: mistake in coding basic operations

Unneeded?But angles wrong!

U

q0

q1 C

q0

q1 B A

D=

QDB: From Quantum Algorithms Towards Correct Quantum ProgramsYipeng Huang, Margaret Martonosi | Princeton University 44

Bug type 3-B: mistake in composing gates using recursionE.g., Scaffold controlled adder:

module cADD (const unsigned int c_width, // number of control qubitsqbit ctrl0, qbit ctrl1, // control qubitsconst unsigned int width, const unsigned int a, qbit b[]

) {for (int b_indx=width-1; b_indx>=0; b_indx--) {

for (int a_indx=b_indx; a_indx>=0; a_indx--) {if ((a >> a_indx) & 1) { // shift out bits in constant a

double angle = M_PI/pow(2,b_indx-a_indx); // rotation angleswitch (c_width) {

case 0: Rz ( b[b_indx], angle ); break;case 1: cRz ( ctrl0, b[b_indx], angle ); break;case 2: ccRz ( ctrl0, ctrl1, b[b_indx], angle ); break;

}}}}}

Many versions of subroutines depending on number of control qubits

QDB: From Quantum Algorithms Towards Correct Quantum ProgramsYipeng Huang, Margaret Martonosi | Princeton University 54

probabilityoutput

0 1 2 3 4 5 6 7

anci

lla

0 1/8 0 1/8 0 1/8 0 1/8 04 1/64 1/64 1/64 1/64 1/64 1/64 1/64 1/647 1/64 1/64 1/64 1/64 1/64 1/64 1/64 1/648 1/64 1/64 1/64 1/64 1/64 1/64 1/64 1/6413 1/64 1/64 1/64 1/64 1/64 1/64 1/64 1/64

Shor’s factoring ancilla and output with bad inputs

Beauregard, 2003

Bug type 3-C: mistake in composing gates using mirroring

Mirror imagesubmodules

Bug type 3-A: mistake in composing gates using iterations

Image credit: Metodi, Faruque, and Chong, Quantum Computing for Computer Architects, 2nd Ed., p26

Tricky iterations—two dimensional loop, indexing, bit shifting, endianness, control-target order…

QDB: From Quantum Algorithms Towards Correct Quantum ProgramsYipeng Huang, Margaret Martonosi | Princeton University 50

Classify quantum programming bugs, pair with defenses, debugging and assertions