programming quantum computers (modules)

40
Programming Quantum Computers (Modules III: QFT) (Subtrack of Quantum Computing: An App-Oriented Approach) Moez A. AbdelGawad [email protected] Sat., Nov. 30 th , 2019

Upload: others

Post on 03-May-2022

10 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Programming Quantum Computers (Modules)

Programming Quantum Computers (Modules III: QFT)

(Subtrack of Quantum Computing: An App-Oriented Approach)

Moez A. AbdelGawad [email protected]

Sat., Nov. 30th, 2019

Page 2: Programming Quantum Computers (Modules)

Quantum Computers are Real

• What are they useful for?

– Let’s discover, by programming them!

• A hands-on approach to programming QCs/QPUs.

– By doing; i.e., by writing code & building programs.

– Using simulators, since real QCs are harder-to-access (so far).

• Goals: Read, understand, write, and debug quantum programs. – Ones like the following.

2019-11-30 2 Copyright @ Moez A. AbdelGawad 2019

Page 3: Programming Quantum Computers (Modules)

Structure of Quantum Apps

2019-11-30 3 Copyright @ Moez A. AbdelGawad 2019

Page 4: Programming Quantum Computers (Modules)

Structure of Quantum Apps

• Tendency to such structure, very roughly.

• Compute in superposition.

– Implicit parallelism.

• Phase manipulation.

– Practicality. Relative phase info directly inaccessible (unREADable).

• Modules are combined (composed) to define full quantum application.

– Possibly in iterations.

• Quantum programming is an art (too).

Quantum Modules Covered

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 4

Module Type

Digital arithmetic and logic (AL) Compute in superposition

Amplitude amplification (AA) Phase manipulation

Quantum Fourier transform (QFT) Phase manipulation

Phase estimation (PE) Phase manipulation

Quantum data types (Sim) Superposition creation

Page 5: Programming Quantum Computers (Modules)

PHASE MANIPULATION MODULES

2019-11-30 5 Copyright @ Moez A. AbdelGawad 2019

Page 6: Programming Quantum Computers (Modules)

QUANTUM FOURIER TRANSFORM (QFT)

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 6

Page 7: Programming Quantum Computers (Modules)

Lecture Outline

• QFT: Revealing hidden patterns. – Performs phase manipulation. Can also help in computing in superposition.

• Hidden patterns.

• QFT, DFT, and FFT.

• Frequencies in a QPU register.

• The DFT (and QFT).

• Uses of QFT. – Signal processing, and preparing superpositions.

• Why and how QFT works.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 7

Page 8: Programming Quantum Computers (Modules)

QFT: Revealing Hidden Patterns

• Signal Frequencies.

QFT ⇓

Applying mirror of AA on these states, instead of QFT, does nothing (Hands-on).

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 8

© P

rogram

min

g Qu

antu

m C

om

pu

ters: O’R

eilly Med

ia

Page 9: Programming Quantum Computers (Modules)

The QFT, DFT, and FFT

• Sound system graphical equalizer. – Uses DFT (Discrete Fourier Transform) to inspect and fiddle with

frequencies of audio signals encoded as bit streams.

– FFT (Fast Fourier Transform): Fastest DFT implementation. • Useful in performance comparisons. • Like QFT, FFT is restricted to power-of-two signal lengths.

– QFT operates on signals encoded in quantum registers (not streams).

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 9

Page 10: Programming Quantum Computers (Modules)

Frequencies in a QPU Register

• A quantum register can encode frequencies in its phases. – E. g., a 4-qubit register with relative phases making two full rotations.

– What if rotations are clockwise? (Hands-on) • Negative frequencies? 1’s complement? 2’s complement?

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 10

© Programming Quantum Computers: O’Reilly Media

Page 11: Programming Quantum Computers (Modules)

Frequencies in a QPU Register

• Frequency info hidden in relative phases; can’t extract by READing. Reveal by QFT.

• Curiosity 1: What if signal is encoded in magnitudes? Can its frequency info be extracted? If so, how?

• Curiosity 2: QFT is not its own inverse (QFT2 ≠ 1). What is QFT2? QFT3? QFT4? – MCQ: (a) Negate phases? (b) no-op? (c) negative frequency? (d) … .

• If extracting frequency info is all that QFT does, can it solve practical problems? – Wait until end of lecture (& Ch.12: Shor’s algorithm).

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 11

Page 12: Programming Quantum Computers (Modules)

Frequencies in a QPU Register

• Not all signals have nice simple QFTs. – Consider the following square-wave signals, with corresponding QFTs.

(What’s missing in top figure? … Check textbook’s errata.)

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 12

© Programming Quantum Computers: O’Reilly Media

Page 13: Programming Quantum Computers (Modules)

Frequencies in a QPU Register

• Operations of the QFT program/circuit (on four qubits):

– (Hands-on) What if QFT is applied to 5, 6 or 7 qubits? … General rule? (# gates ≅ circuit complexity) • Later we’ll see the QFT circuit for 8 qubits. Can we draw it before we see it? (Lab Assignment)

– (Hands-on) What if QFT is applied to 3, 2, or 1 qubit(s)? • What do we conclude (regarding the Hadamard gate H)? (Check the Wikipedia article on Hadamard Transform)

• QFT ≡ DFT applied to signals encoded in QPU registers. – Let’s as such recap DFT, the more conventional cousin of QFT.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 13

© Programming Quantum Computers: O’Reilly Media

Page 14: Programming Quantum Computers (Modules)

DFT

• Sampling a continuous signal (ADC).

– E.g., sound (i.e., audio) or image (i.e., visual) data.

– Imprecision; due to finite # bits (or qubits, for QFT).

• (Continuous) Fourier Transform gives precise result.

– Involves multiplication by an exponential then

integration 𝑠 𝑡 𝑒−2𝜋𝑖𝑓𝑡∞

−∞. 𝑑𝑡 .

– Reveals sinusoidal components of a function/signal.

– Handles, accurately, signals with complex amplitudes (i.e., with magnitude and phase) and signals with real amplitudes (i.e., magnitude-only, w/ zero-phase).

– Does not work directly on discrete/sampled data.

– Useful resource: http://thefouriertransform.com .

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 14

– Odd functions (Y-axis refl.): 𝑠 𝑡 = 𝑠(−𝑡). Even functions (Origin refl.): 𝑠 𝑡 = −𝑠(−𝑡).

• Discrete Fourier Transform (DFT).

– Pros: Works directly on discrete/sampled data. Cons: Is less precise, given the finite # bits.

– Handles signals with complex and real amplitudes. For real amplitudes, DFT exhibits slightly different behavior than complex ones, due to sampled data imprecision.

Page 15: Programming Quantum Computers (Modules)

DFT

• DFT/QFT on real (i.e., magnitude-only) data.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 15

© Programming Quantum Computers: O’Reilly Media

Page 16: Programming Quantum Computers (Modules)

DFT (and QFT)

• Frequency encoded in magnitudes of a QPU register.

– Our earlier question (‘Curiosity 1’ on slide 11).

QFT ⇓

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 16

Page 17: Programming Quantum Computers (Modules)

DFT

• Can be applied also to non-sinusoidal signals. – DSP.

– Square wave.

• Again, 0-phase means symmetric DFT (and QFT) output.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 17

© Programming Quantum Computers: O’Reilly Media

Page 18: Programming Quantum Computers (Modules)

DFT and QFT

• Qubyte-encoded square wave input signal.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 18

© P

rogram

min

g Qu

antu

m C

om

pu

ters: O’R

eilly Med

ia

Page 19: Programming Quantum Computers (Modules)

DFT and QFT

QFT probability distribution is the same as DFT frequency strength distribution (on slide 17).

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 19

© P

rogram

min

g Qu

antu

m C

om

pu

ters: O’R

eilly Med

ia

Page 20: Programming Quantum Computers (Modules)

QFT in Apps: The QFT Is Fast

• QFT is far, far faster than FFT.

O(𝑛2𝑛) for FFT vs. O(𝑛2) for QFT

(Pragmatically, below 22 bits use FFT, over 25 use QFT)

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 20

© Programming Quantum Computers: O’Reilly Media

Page 21: Programming Quantum Computers (Modules)

QFT in Apps: Signal Processing

• QFT provides an exponentially faster implementation of DFT as a signal-processing tool? – Two main challenges. – How to get signal data into input quantum register?

• For large data, cost of initializing input register may wipe QFT’s benefit. • QRAM (Ch.9) is one solution.

– How to access result of QFT? • READing result gives only a randomly-chosen one of the present frequencies. • Final state can be useful under certain circumstances. • E.g., if calling app is okay with randomly getting “the dominant frequency or a

multiple of it,” or if it can verify a desired answer.

– Signal-processing capabilities of QFT can offer a valuable phase manipulation primitive. • We’ll see QFT play such a role in Shor’s factoring algorithm (Ch.12).

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 21

Page 22: Programming Quantum Computers (Modules)

QFT in Apps: InvQFT

• Preparing superpositions. (Hands-on) – Using invQFT is often easier than preparing state directly.

(Varying in phase. qin = 3) (qin = 1, -1. Symm. vary magnitude)

( 0,1 → 0,15 → 2,13 → 3,13 → (1,15))

• And manipulating superpositions.

(w/ phase oscill. only. Why?)

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 22

© Programming Quantum Computers: O’Reilly Media

Page 23: Programming Quantum Computers (Modules)

• QFT on a qubyte (Hands-on).

(Note circuit structure, and minimum phase rotations = 360𝑜/256)

• Understand QFT by understanding invQFT (in an equivalent form)

Inside The QPU

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 23

© Programming Quantum Computers: O’Reilly Media

Page 24: Programming Quantum Computers (Modules)

Inside The QPU: invQFT

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 24

Page 25: Programming Quantum Computers (Modules)

invQFT: The Intuition

• Make 𝑛 phase rotations in an 𝑁-qubit register.

– E.g., make 2 phase rotations in a 4-qubit register.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 25

© Programming Quantum Computers: O’Reilly Media

Page 26: Programming Quantum Computers (Modules)

invQFT: Operation By Operation

• Doing a phase rotation multiplied by each qubit’s value.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 26

© Programming Quantum Computers: O’Reilly Media

Page 27: Programming Quantum Computers (Modules)

invQFT: Operation By Operation

• Subroutines of invQFT.

– One subroutine for each qubit.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 27

© Programming Quantum Computers: O’Reilly Media

Page 28: Programming Quantum Computers (Modules)

invQFT: Operation By Operation

• Conditional phase rotations.

– As specified by binary representation of input.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 28

© Programming Quantum Computers: O’Reilly Media

Page 29: Programming Quantum Computers (Modules)

invQFT: Operation By Operation

• Rotations on highest-weight qubit (0x8).

– Each CPHASE conditionally rotates qubit by an angle that is the same proportion of 360° as the condition qubit is of 2N.

• E.g., the CPHASE acting between the 0x4 and 0x8 qubits rotates 0x8 by 90° --- and 4/24 = 90°/360°.

– Building up the rotation n/2N × 360° on the 0x8 qubit through each component of n’s binary expansion.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 29

• What about rotating conditioned on the highest-weight qubit 0x8 itself?

– Needed: A phase rotation of 180° on the highest-weight qubit, dependent on the value of the highest-weight qubit itself.

– The H(adamard) gate does that! … and it also generates superposition in the qubit!

– Cleverly compact!

Page 30: Programming Quantum Computers (Modules)

• Subsequent Stages? Just roll-left.

• One problem: Everything is upside-down! – Explain in circle-notation. (Hands-on)

• Subcircuit 1 rotated the 0x8 qubit a single multiple of the phase, whereas it should be rotated eight times that value (Slide 25).

– Solution: Exchanges at the very end.

invQFT: Operation By Operation

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 30

© Programming Quantum Computers: O’Reilly Media

Page 31: Programming Quantum Computers (Modules)

invQFT (QFT-1): Alternate Circuit Code and Illustration

qc.reset(4);

r=qint.new(4,'r');

r.write(15);

r.had(8);

r.cphase(90,8,4);

r.cphase(45,8,2);

r.cphase(22.5,8,1);

r.had(4);

r.cphase(90,4,2);

r.cphase(45,4,1);

r.had(2);

r.cphase(90,2,1);

r.had(1);

qc.swap(0x1|0x8);

qc.swap(0x2|0x4);

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 31

• Useful for understanding the operation of invQFT (QFT-1) and QFT. • Similar code based on this one is used to understand and analyze phase estimation (in next class). • Check the Wikipedia article on Fourier Transform.

Page 32: Programming Quantum Computers (Modules)

QFT and invQFT

• Very clever!

– Multiple steps compressed into a small multipurpose set of operations.

– Work on superpositions too!

• Both are at the core of some of the most powerful algorithms that can be run on a QPU.

– Including Shor’s algorithm, which first kick-started mainstream interest in quantum computing.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 32

Page 33: Programming Quantum Computers (Modules)

Research Ideas

• xFT (=FT, DFT, FFT, QFT) is a family of procedures for finding or revealing constituents, main components, essential parts or building blocks. – E.g., prime factorization of whole numbers (the fundamental theorem of arithmetic).

– Explains why QFT is useful in Shor’s factoring algorithm.

• Group Theory: General expression of finding components problem. – HSP (Hidden Subgroup Problem):

• In a group (many examples, e.g., integers under addition), find the kernel (the hidden core) of a certain function defined over the group.

– HSP Instance: Graph Isomorphism.

• No quantum algorithm so far.

• Most cases efficiently solvable (not much practical value to a quantum speedup).

• (Complexity Theory) Graph isomorphism and factoring are two problems not known to be NP-complete (NPC) nor to be P.

• Category Theory (CT): – Groups are (monoids are) categories. What corresponds to HSP in CT? … “HSCP”?

– ‘Conceptual Mathematics’, Lawvere and Schanuel, 2009.

• Subobjects, and the parts functor, useful? ... Fixed points (e.g., eigenstates/phases) from a CT perspective.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 33

Page 34: Programming Quantum Computers (Modules)

Research Ideas

• Other research directions:

– Ackermann’s function: Superexponential time complexity O(𝑛𝑛⋰𝑛

). • Ackermann quantum speedup?

– Related to my other OOP/PL research: • Mutual coinduction useful in the mathematical modeling of superposition or entanglement.

• The relation between partial products (of sets/lattices/graphs … etc.) and entanglement.

• ‘Modeling Object-Oriented Generics’ (Poster), Moez AbdelGawad. ACT’19 (Applied Category Theory 2019), The Quantum Group, Dept. of Comp. Sci., Oxford University, UK, July 2019.

• QPLs: ‘Foundations of Quantum Programming’, Mingsheng Ying, 2016.

– Theoretical Quantum Physics & Theoretical Quantum Computing: • ‘Road to Reality’, Penrose, 2004.

• ‘Picturing Quantum Processes’, ‘The 2nd Quantum Revolution’, ‘Programming The Universe’, … etc.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 34

Page 35: Programming Quantum Computers (Modules)

Discussion

Q & A

2019-11-30 35 Copyright @ Moez A. AbdelGawad 2019

Page 36: Programming Quantum Computers (Modules)

Research Question

• Now that we know precisely how QFT works, can we suggest a better patterns-revealing module? – i.e., a module that reveals the same (or different) patterns with, e.g.,

lesser operations, or that somehow produces better results.

– If you think it is possible, suggest how.

– If you think it is not possible, explain why not.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 36

Page 37: Programming Quantum Computers (Modules)

Homework

• Implement QFT on QX, Q#, and Cirq.

2019-11-30 Copyright @ Moez A. AbdelGawad 2019 39

Page 38: Programming Quantum Computers (Modules)

Next Lecture Appetizer!

• In next lecture (isA):

– Phase Estimation.

• Quantum operations as matrices.

• Fixed states, impervious to an operation, and their global phases.

– Eigenvectors and eigenvalues of matrices.

– Eigenstates, eigenphases … and (eigen)phase estimation.

• Works on superpositions.

– Reading Ch.8 before next class is a MUST.

2019-11-30 41 Copyright @ Moez A. AbdelGawad 2019

Page 39: Programming Quantum Computers (Modules)

Course Webpage

http://eng.staff.alexu.edu.eg/~moez/teaching/pqc-f19

• Where you can:

– Download lecture slides (incl. exercises and homework).

– Check links to other useful material.

2019-11-30 42 Copyright @ Moez A. AbdelGawad 2019

Page 40: Programming Quantum Computers (Modules)

Thank You

2019-11-30 43 Copyright @ Moez A. AbdelGawad 2019