|
1 | | -\documentclass[11pt]{book} |
2 | | -\usepackage[utf8]{inputenc} |
3 | | -\usepackage{amsmath, amssymb} |
4 | | -\usepackage{physics} |
| 1 | +\documentclass[12pt]{book} |
| 2 | +\usepackage[a4paper,margin=1in]{geometry} |
| 3 | +\usepackage{amsmath,amsfonts,amssymb} |
5 | 4 | \usepackage{graphicx} |
6 | 5 | \usepackage{hyperref} |
7 | | -\usepackage{xcolor} |
| 6 | +\usepackage{qcircuit} |
8 | 7 | \usepackage{listings} |
| 8 | +\usepackage{xcolor} |
9 | 9 | \usepackage{caption} |
10 | | -\usepackage{geometry} |
11 | | -\geometry{margin=1in} |
12 | | - |
13 | | -\title{Quantum Fourier Transform: Theory and Implementation} |
14 | | -\author{} |
15 | | -\date{} |
| 10 | +\usepackage{physics} |
16 | 11 |
|
| 12 | +\definecolor{codebg}{rgb}{0.95,0.95,0.95} |
17 | 13 | \lstset{ |
18 | | - language=Python, |
19 | | - basicstyle=\ttfamily\small, |
20 | | - keywordstyle=\color{blue}, |
21 | | - commentstyle=\color{gray}, |
22 | | - stringstyle=\color{red}, |
23 | | - showstringspaces=false, |
24 | | - breaklines=true, |
25 | | - frame=single, |
26 | | - captionpos=b |
| 14 | + backgroundcolor=\color{codebg}, |
| 15 | + basicstyle=\ttfamily\footnotesize, |
| 16 | + keywordstyle=\color{blue}, |
| 17 | + commentstyle=\color{gray}, |
| 18 | + stringstyle=\color{red}, |
| 19 | + breaklines=true, |
| 20 | + postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space}, |
| 21 | + frame=single, |
| 22 | + showstringspaces=false |
27 | 23 | } |
28 | 24 |
|
| 25 | +\title{Quantum Fourier Transform: Theory and Implementation} |
| 26 | +\author{Morten Hjorth-Jensen} |
| 27 | +\date{May 2021} |
| 28 | + |
29 | 29 | \begin{document} |
30 | 30 |
|
| 31 | +\maketitle |
| 32 | +\tableofcontents |
| 33 | + |
| 34 | +\chapter{Introduction and Background} |
| 35 | +The Quantum Fourier Transform (QFT) is a central building block in quantum algorithms such as Shor's factoring algorithm and quantum phase estimation. It is the quantum analogue of the discrete Fourier transform (DFT) and enables efficient extraction of periodicity from quantum states. |
| 36 | + |
| 37 | +\section{Classical Fourier Transform} |
| 38 | +The classical Discrete Fourier Transform (DFT) on a vector $x = (x_0, ..., x_{N-1})$ is given by: |
| 39 | +\[ |
| 40 | +\tilde{x}_k = \frac{1}{\sqrt{N}} \sum_{j=0}^{N-1} x_j e^{2\pi i jk / N} |
| 41 | +\] |
| 42 | +It is a unitary transformation and can be implemented in $O(N \log N)$ via the Fast Fourier Transform. |
| 43 | + |
| 44 | +\section{Quantum States and Qubits} |
| 45 | +A quantum register of $n$ qubits encodes a vector in $2^n$-dimensional Hilbert space: |
| 46 | +\[ |
| 47 | +\ket{\psi} = \sum_{j=0}^{2^n - 1} x_j \ket{j} |
| 48 | +\] |
| 49 | +where $x_j$ are complex amplitudes satisfying $\sum |x_j|^2 = 1$. |
| 50 | + |
| 51 | +\section{Quantum Fourier Transform} |
| 52 | +The QFT on an $n$-qubit state transforms: |
| 53 | +\[ |
| 54 | +\ket{j} \rightarrow \frac{1}{\sqrt{2^n}} \sum_{k=0}^{2^n - 1} e^{2\pi i jk / 2^n} \ket{k} |
| 55 | +\] |
| 56 | +This unitary matrix has exponential size, but can be implemented in $O(n^2)$ quantum gates. |
| 57 | + |
| 58 | +\section{Matrix Form} |
| 59 | +For $n = 2$ qubits, the QFT matrix is: |
| 60 | +\[ |
| 61 | +\frac{1}{2} |
| 62 | +\begin{bmatrix} |
| 63 | +1 & 1 & 1 & 1 \\ |
| 64 | +1 & i & -1 & -i \\ |
| 65 | +1 & -1 & 1 & -1 \\ |
| 66 | +1 & -i & -1 & i |
| 67 | +\end{bmatrix} |
| 68 | +\] |
| 69 | + |
| 70 | +\chapter{Circuit Implementation of QFT} |
| 71 | + |
| 72 | +\section{QFT Circuit Structure} |
| 73 | +The QFT is decomposed into Hadamard and controlled phase shift gates. For $n$ qubits, the standard structure is: |
| 74 | + |
| 75 | +\begin{enumerate} |
| 76 | + \item Apply Hadamard to the most significant qubit. |
| 77 | + \item Apply controlled-$R_k$ gates to encode phase shifts. |
| 78 | + \item Repeat for remaining qubits. |
| 79 | + \item Apply SWAP gates to reverse the order. |
| 80 | +\end{enumerate} |
| 81 | + |
| 82 | +\section{Quantum Gates Used} |
| 83 | +\begin{itemize} |
| 84 | + \item \textbf{Hadamard gate:} $H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}$ |
| 85 | + \item \textbf{Phase shift gate:} $R_k = \begin{bmatrix} 1 & 0 \\ 0 & e^{2\pi i / 2^k} \end{bmatrix}$ |
| 86 | +\end{itemize} |
| 87 | + |
| 88 | +\section{QFT on 3 Qubits} |
| 89 | +Example for $n = 3$ qubits: |
| 90 | +\begin{enumerate} |
| 91 | + \item Apply $H$ to qubit 0. |
| 92 | + \item Apply $R_2$ (ctrl:1, tgt:0), $R_3$ (ctrl:2, tgt:0). |
| 93 | + \item Repeat with Hadamard on qubit 1, $R_2$ from qubit 2. |
| 94 | + \item Hadamard on qubit 2. |
| 95 | + \item Apply SWAPs: swap(0,2). |
| 96 | +\end{enumerate} |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
31 | 103 | \maketitle |
32 | 104 |
|
33 | 105 | \chapter{Mathematical Foundations and Motivation} |
@@ -183,3 +255,262 @@ \section{Complexity} |
183 | 255 |
|
184 | 256 | \section{Summary} |
185 | 257 | The circuit implementation of QFT is surprisingly efficient, enabling its use in several key quantum algorithms. Understanding the gate-level construction deepens our understanding of quantum information flow during Fourier transformation. |
| 258 | + |
| 259 | +\chapter{Inverse QFT and Phase Estimation} |
| 260 | + |
| 261 | +\section{The Inverse QFT} |
| 262 | +The inverse Quantum Fourier Transform (IQFT) is simply the Hermitian adjoint of the QFT. Since the QFT is unitary, its inverse is: |
| 263 | +\[ |
| 264 | +\text{QFT}^\dagger = \text{QFT}^{-1} |
| 265 | +\] |
| 266 | + |
| 267 | +\subsection*{Circuit Construction} |
| 268 | +To reverse the QFT circuit: |
| 269 | +\begin{enumerate} |
| 270 | + \item Swap the order of gates. |
| 271 | + \item Replace Hadamard gates with Hadamard gates (self-inverse). |
| 272 | + \item Replace each $R_k$ gate with its conjugate transpose $R_k^\dagger$: |
| 273 | + \[ |
| 274 | + R_k^\dagger = \begin{bmatrix} |
| 275 | + 1 & 0 \\ |
| 276 | + 0 & e^{-2\pi i / 2^k} |
| 277 | + \end{bmatrix} |
| 278 | + \] |
| 279 | +\end{enumerate} |
| 280 | + |
| 281 | +\section{Quantum Phase Estimation (QPE)} |
| 282 | +Quantum Phase Estimation is a core quantum algorithm that uses the QFT to estimate the phase $\phi$ in: |
| 283 | +\[ |
| 284 | +U \ket{u} = e^{2\pi i \phi} \ket{u} |
| 285 | +\] |
| 286 | + |
| 287 | +\subsection*{Algorithm Overview} |
| 288 | +Given an eigenvector $\ket{u}$ of a unitary $U$, the QPE algorithm estimates the phase $\phi$ using: |
| 289 | + |
| 290 | +\begin{enumerate} |
| 291 | + \item Apply Hadamards to an $n$-qubit register. |
| 292 | + \item Use controlled-$U^{2^k}$ gates to encode phase. |
| 293 | + \item Apply inverse QFT to extract the binary digits of $\phi$. |
| 294 | +\end{enumerate} |
| 295 | + |
| 296 | +\section{Circuit Diagram (3-bit QPE)} |
| 297 | +The general circuit has: |
| 298 | + |
| 299 | +- Top register: $n$ qubits to encode phase. |
| 300 | +- Bottom register: one eigenstate $\ket{u}$. |
| 301 | + |
| 302 | +\[ |
| 303 | +\Qcircuit @C=1em @R=1em { |
| 304 | +\lstick{\ket{0}} & \gate{H} & \ctrl{1} & \qw & \multigate{2}{\text{IQFT}} & \meter \\ |
| 305 | +\lstick{\ket{0}} & \gate{H} & \ctrl{1} & \qw & \ghost{\text{IQFT}} & \meter \\ |
| 306 | +\lstick{\ket{0}} & \gate{H} & \ctrl{1} & \qw & \ghost{\text{IQFT}} & \meter \\ |
| 307 | +\lstick{\ket{u}} & {/} \qw & \gate{U^{2^k}} & \qw & \qw & \qw |
| 308 | +} |
| 309 | +\] |
| 310 | + |
| 311 | +\section{PennyLane Implementation of QPE} |
| 312 | +\begin{lstlisting}[language=Python] |
| 313 | +import pennylane as qml |
| 314 | +from pennylane import numpy as np |
| 315 | + |
| 316 | +n_estimation = 3 |
| 317 | +dev = qml.device("default.qubit", wires=n_estimation + 1) |
| 318 | + |
| 319 | +def apply_controlled_unitaries(U, wires): |
| 320 | + for i, ctrl in enumerate(wires[:-1]): |
| 321 | + power = 2**i |
| 322 | + for _ in range(power): |
| 323 | + qml.ctrl(U, control=ctrl)(wires[-1]) |
| 324 | + |
| 325 | +def inverse_qft(wires): |
| 326 | + swap_registers(wires) |
| 327 | + for i in reversed(range(len(wires))): |
| 328 | + for j in range(i): |
| 329 | + qml.ctrl(qml.PhaseShift, control=wires[j])(-np.pi / 2**(i - j), wires=wires[i]) |
| 330 | + qml.Hadamard(wires=wires[i]) |
| 331 | + |
| 332 | +@qml.qnode(dev) |
| 333 | +def qpe(): |
| 334 | + target_wire = n_estimation |
| 335 | + for i in range(n_estimation): |
| 336 | + qml.Hadamard(wires=i) |
| 337 | + |
| 338 | + qml.RZ(2 * np.pi * 0.375, wires=target_wire) # Assume phase = 0.375 |
| 339 | + |
| 340 | + apply_controlled_unitaries(qml.RZ, list(range(n_estimation)) + [target_wire]) |
| 341 | + inverse_qft(list(range(n_estimation))) |
| 342 | + return qml.probs(wires=range(n_estimation)) |
| 343 | + |
| 344 | +probs = qpe() |
| 345 | +print("Measured phase state:", probs) |
| 346 | +\end{lstlisting} |
| 347 | + |
| 348 | +\section{Accuracy and Readout} |
| 349 | +The accuracy of phase estimation improves with the number of qubits in the control register. For $n$ qubits, we obtain the $n$ most significant bits of $\phi$. |
| 350 | + |
| 351 | +\section{Summary} |
| 352 | +The inverse QFT is essential for extracting phase information from quantum states. Combined with controlled unitary evolution, it enables phase estimation—a foundational subroutine for factoring, quantum simulations, and eigenvalue problems. |
| 353 | + |
| 354 | +ics, eigenvalues of unitary evolutions encode properties like energy levels. QPE, powered by QFT, is used to extract these values. |
| 355 | + |
| 356 | +\subsection*{Hamiltonian Simulation} |
| 357 | +Let $H$ be a Hamiltonian. The evolution $U = e^{-iHt}$ has eigenvectors $\ket{u}$ and eigenvalues $e^{-iEt}$. QPE yields estimates of $E$. |
| 358 | + |
| 359 | +\subsection*{Applications} |
| 360 | +- Electronic structure problems |
| 361 | +- Dynamics of molecules |
| 362 | +- Energy spectrum estimation |
| 363 | + |
| 364 | +\section{Amplitude Estimation} |
| 365 | +Quantum Amplitude Estimation (QAE) uses QFT for estimating probabilities (amplitudes) more efficiently than classical sampling. |
| 366 | + |
| 367 | +\subsection*{Basic Setup} |
| 368 | +Prepare a state: |
| 369 | +\[ |
| 370 | +\ket{\psi} = \sqrt{a}\ket{1} + \sqrt{1 - a}\ket{0} |
| 371 | +\] |
| 372 | +QAE estimates $a$ using Grover-like iterations and QFT. |
| 373 | + |
| 374 | +\section{PennyLane Example: Energy Estimation} |
| 375 | +We simulate a simple diagonal Hamiltonian using QPE. |
| 376 | + |
| 377 | +\begin{lstlisting}[language=Python] |
| 378 | + import pennylane as qml |
| 379 | + from pennylane import numpy as np |
| 380 | + |
| 381 | + n_qubits = 2 |
| 382 | + dev = qml.device(``default.qubit'', wires=n_qubits + 1) |
| 383 | + |
| 384 | + def controlled_unitary(t): |
| 385 | + def unitary(): |
| 386 | + qml.PhaseShift(2 * np.pi * 0.3 * t, wires=n_qubits) |
| 387 | + return unitary |
| 388 | + |
| 389 | + @qml.qnode(dev) |
| 390 | + def energy_estimation(): |
| 391 | + # Apply Hadamards to estimation qubits |
| 392 | + for i in range(n_qubits): |
| 393 | + qml.Hadamard(wires=i) |
| 394 | + # Prepare eigenstate for target qubit |
| 395 | + qml.PauliX(wires=n_qubits) |
| 396 | + # Apply controlled-U^{2^j} |
| 397 | + for i in range(n_qubits): |
| 398 | + unitary = controlled_unitary(2**i) |
| 399 | + qml.ctrl(unitary, control=i)() |
| 400 | + # Inverse QFT |
| 401 | + inverse_qft(range(n_qubits)) |
| 402 | + return qml.probs(wires=range(n_qubits)) |
| 403 | + |
| 404 | + probs = energy_estimation() |
| 405 | + print(``Measured energy phase:'', probs) |
| 406 | +\end{lstlisting} |
| 407 | + |
| 408 | +\section{Summary} |
| 409 | +The QFT enables exponential speedups in various quantum algorithms by exposing hidden periodicity, encoding eigenvalues, and amplifying amplitudes. Its applications span number theory, chemistry, and quantum finance, highlighting its centrality to quantum computing. |
| 410 | + |
| 411 | + |
| 412 | +large $k$ are highly sensitive to noise. Removing them improves fidelity on NISQ devices. |
| 413 | + |
| 414 | +\subsection*{Noise-Aware Compilation} |
| 415 | +Use device-specific compilers (e.g., Qiskit, tket) that minimize gate errors and optimize qubit layout. |
| 416 | + |
| 417 | +\section{Example: Approximate QFT in PennyLane} |
| 418 | +We modify our QFT to drop $R_k$ gates with angle $< \epsilon$: |
| 419 | + |
| 420 | +\begin{lstlisting}[language=Python] |
| 421 | + def approximate_qft(wires, epsilon=1e-2): |
| 422 | + if len(wires) == 0: |
| 423 | + return |
| 424 | + head, *tail = wires |
| 425 | + qml.Hadamard(wires=head) |
| 426 | + for i, qubit in enumerate(tail): |
| 427 | + angle = np.pi / 2**(i+1) |
| 428 | + if angle >= epsilon: |
| 429 | + qml.ctrl(qml.PhaseShift, control=qubit)(angle, wires=head) |
| 430 | + approximate_qft(tail) |
| 431 | +\end{lstlisting} |
| 432 | + |
| 433 | +This dramatically reduces depth for large $n$, making QFT feasible for hardware implementation. |
| 434 | + |
| 435 | +\section{Resource Summary} |
| 436 | + |
| 437 | +\begin{itemize} |
| 438 | +\item \textbf{Exact QFT}: $O(n^2)$ gates, accurate, but deep circuit. |
| 439 | +\item \textbf{Approximate QFT}: $O(n \log(1/\epsilon))$ gates, fast and NISQ-friendly. |
| 440 | +\item \textbf{Inverse QFT}: Similar structure, used in readout stages. |
| 441 | +\end{itemize} |
| 442 | + |
| 443 | +\section{Summary} |
| 444 | +Optimizing QFT for real-world execution is essential for practical quantum computing. Approximate QFTs maintain algorithmic utility while reducing quantum hardware demands. These optimizations are vital for algorithms targeting NISQ systems or requiring high repetition rates. |
| 445 | + |
| 446 | +sed(range(len(wires))): |
| 447 | +for j in range(i): |
| 448 | +qml.ctrl(qml.PhaseShift, control=wires[j])(-np.pi / 2**(i - j), wires=wires[i]) |
| 449 | +qml.Hadamard(wires=wires[i]) |
| 450 | +\end{lstlisting} |
| 451 | + |
| 452 | +\section{Code 3: Quantum Phase Estimation (QPE)} |
| 453 | +\begin{lstlisting}[language=Python] |
| 454 | + n_estimation = 3 |
| 455 | + dev = qml.device(``default.qubit'', wires=n_estimation + 1) |
| 456 | + |
| 457 | + def apply_controlled_unitaries(U, wires): |
| 458 | + for i, ctrl in enumerate(wires[:-1]): |
| 459 | + power = 2**i |
| 460 | + for _ in range(power): |
| 461 | + qml.ctrl(U, control=ctrl)(wires[-1]) |
| 462 | + |
| 463 | + @qml.qnode(dev) |
| 464 | + def qpe(): |
| 465 | + target_wire = n_estimation |
| 466 | + for i in range(n_estimation): |
| 467 | + qml.Hadamard(wires=i) |
| 468 | + qml.RZ(2 * np.pi * 0.375, wires=target_wire) |
| 469 | + apply_controlled_unitaries(qml.RZ, list(range(n_estimation)) + [target_wire]) |
| 470 | + inverse_qft(list(range(n_estimation))) |
| 471 | + return qml.probs(wires=range(n_estimation)) |
| 472 | + |
| 473 | + print(``Measured phase state:'', qpe()) |
| 474 | +\end{lstlisting} |
| 475 | + |
| 476 | +\section{Code 4: Approximate QFT Implementation} |
| 477 | +\begin{lstlisting}[language=Python] |
| 478 | + def approximate_qft(wires, epsilon=1e-2): |
| 479 | + if len(wires) == 0: |
| 480 | + return |
| 481 | + head, *tail = wires |
| 482 | + qml.Hadamard(wires=head) |
| 483 | + for i, qubit in enumerate(tail): |
| 484 | + angle = np.pi / 2**(i+1) |
| 485 | + if angle >= epsilon: |
| 486 | + qml.ctrl(qml.PhaseShift, control=qubit)(angle, wires=head) |
| 487 | + approximate_qft(tail) |
| 488 | +\end{lstlisting} |
| 489 | + |
| 490 | +\section{Execution Tips} |
| 491 | + |
| 492 | +\begin{itemize} |
| 493 | +\item All examples can run on \texttt{default.qubit}, the standard PennyLane simulator. |
| 494 | +\item Use \texttt{qml.draw()} to visualize circuits. |
| 495 | +\item To run on real hardware (e.g., IBMQ, Xanadu X8), swap the device line with the appropriate plugin and set API keys. |
| 496 | +\item Use \texttt{qml.state()} or \texttt{qml.probs()} to inspect output. |
| 497 | +\item PennyLane supports backpropagation, enabling QFT-based circuits to be optimized or trained. |
| 498 | +\end{itemize} |
| 499 | + |
| 500 | +\section{Further Reading} |
| 501 | + |
| 502 | +\begin{itemize} |
| 503 | +\item PennyLane Documentation: \url{https://docs.pennylane.ai} |
| 504 | +\item Nielsen and Chuang, \emph{Quantum Computation and Quantum Information} |
| 505 | +\item Kitaev's Phase Estimation Algorithm (original source) |
| 506 | +\item Qiskit textbook: \url{https://qiskit.org/textbook} |
| 507 | +\end{itemize} |
| 508 | + |
| 509 | +\section{Summary} |
| 510 | +This appendix compiles all code needed to simulate and visualize QFT and its applications using PennyLane. With these examples, readers can replicate core quantum algorithms on simulators or real hardware with minimal changes. |
| 511 | + |
| 512 | + |
| 513 | + |
| 514 | + |
| 515 | + |
| 516 | +\end{document} |
0 commit comments