Transcript
Programming Quantum Computers (Modules III: QFT)
(Subtrack of Quantum Computing: An App-Oriented Approach)
Moez A. AbdelGawad moez@alexu.edu.eg
Sat., Nov. 30th, 2019
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
Structure of Quantum Apps
2019-11-30 3 Copyright @ Moez A. AbdelGawad 2019
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
PHASE MANIPULATION MODULES
2019-11-30 5 Copyright @ Moez A. AbdelGawad 2019
QUANTUM FOURIER TRANSFORM (QFT)
2019-11-30 Copyright @ Moez A. AbdelGawad 2019 6
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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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
• 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
Inside The QPU: invQFT
2019-11-30 Copyright @ Moez A. AbdelGawad 2019 24
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
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
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
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
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!
• 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
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.
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
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
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
Discussion
Q & A
2019-11-30 35 Copyright @ Moez A. AbdelGawad 2019
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
Homework
• Implement QFT on QX, Q#, and Cirq.
2019-11-30 Copyright @ Moez A. AbdelGawad 2019 39
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
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
Thank You
2019-11-30 43 Copyright @ Moez A. AbdelGawad 2019
top related