|
| 1 | +\documentclass[11pt]{book} |
| 2 | +\usepackage[utf8]{inputenc} |
| 3 | +\usepackage{amsmath, amssymb} |
| 4 | +\usepackage{physics} |
| 5 | +\usepackage{graphicx} |
| 6 | +\usepackage{hyperref} |
| 7 | +\usepackage{xcolor} |
| 8 | +\usepackage{listings} |
| 9 | +\usepackage{caption} |
| 10 | +\usepackage{geometry} |
| 11 | +\geometry{margin=1in} |
| 12 | + |
| 13 | +\title{Quantum Fourier Transform: Theory and Implementation} |
| 14 | +\author{} |
| 15 | +\date{} |
| 16 | + |
| 17 | +\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 |
| 27 | +} |
| 28 | + |
| 29 | +\begin{document} |
| 30 | + |
| 31 | +\maketitle |
| 32 | + |
| 33 | +\chapter{Mathematical Foundations and Motivation} |
| 34 | + |
| 35 | +\section{Introduction} |
| 36 | +The Quantum Fourier Transform (QFT) is a key component in many quantum algorithms, notably Shor’s factoring algorithm and quantum phase estimation. It serves as the quantum analogue of the classical Discrete Fourier Transform (DFT), but operates exponentially faster due to the principles of quantum parallelism and entanglement. |
| 37 | + |
| 38 | +\section{Classical Discrete Fourier Transform} |
| 39 | +Given a vector of $N$ complex numbers $\{x_0, x_1, \dots, x_{N-1}\}$, the DFT is defined as: |
| 40 | +\[ |
| 41 | +X_k = \sum_{n=0}^{N-1} x_n e^{-2\pi i kn/N}, \quad k = 0, 1, \dots, N-1 |
| 42 | +\] |
| 43 | + |
| 44 | +The inverse transform is: |
| 45 | +\[ |
| 46 | +x_n = \frac{1}{N} \sum_{k=0}^{N-1} X_k e^{2\pi i kn/N} |
| 47 | +\] |
| 48 | + |
| 49 | +This can be expressed in matrix form: |
| 50 | +\[ |
| 51 | +\vec{X} = F_N \vec{x}, \quad \text{where} \quad (F_N)_{jk} = \frac{1}{\sqrt{N}} e^{2\pi i jk/N} |
| 52 | +\] |
| 53 | + |
| 54 | +\section{Quantum Fourier Transform} |
| 55 | +Let $N = 2^n$. The QFT acts on the state: |
| 56 | +\[ |
| 57 | +\ket{x} = \ket{x_1 x_2 \dots x_n} |
| 58 | +\] |
| 59 | +and transforms it into: |
| 60 | +\[ |
| 61 | +\text{QFT} \ket{x} = \frac{1}{\sqrt{N}} \sum_{k=0}^{N-1} e^{2\pi i xk/N} \ket{k} |
| 62 | +\] |
| 63 | + |
| 64 | +The QFT is unitary and can be decomposed into a series of Hadamard and controlled phase gates, allowing for an efficient $O(n^2)$ implementation. |
| 65 | + |
| 66 | +\section{Comparison with Classical DFT} |
| 67 | +While the classical FFT runs in $O(N \log N)$ time, the QFT runs in $O(n^2) = O(\log^2 N)$ gate operations—an exponential improvement, crucial in quantum speedups for specific problems. |
| 68 | + |
| 69 | +\section{Unitary Nature of QFT} |
| 70 | +The QFT matrix $F_N$ is unitary: |
| 71 | +\[ |
| 72 | +F_N^\dagger F_N = I |
| 73 | +\] |
| 74 | +This guarantees that QFT is a valid quantum operation (i.e., norm-preserving and reversible). |
| 75 | + |
| 76 | +\section{PennyLane Setup and Basic Example} |
| 77 | +To experiment with QFT, we can use the PennyLane Python library. |
| 78 | + |
| 79 | +\subsection*{Installation} |
| 80 | +\begin{lstlisting}[language=bash] |
| 81 | +pip install pennylane |
| 82 | +\end{lstlisting} |
| 83 | + |
| 84 | +\subsection*{Classical DFT vs Quantum Fourier Transform} |
| 85 | +```python |
| 86 | +import pennylane as qml |
| 87 | +from pennylane import numpy as np |
| 88 | +
|
| 89 | +n_qubits = 3 |
| 90 | +dev = qml.device("default.qubit", wires=n_qubits) |
| 91 | + |
| 92 | +def apply_qft(wires): |
| 93 | + qml.templates.QFT(wires=wires) |
| 94 | + |
| 95 | +@qml.qnode(dev) |
| 96 | +def qft_circuit(): |
| 97 | + qml.BasisState(np.array([1, 0, 1]), wires=range(n_qubits)) |
| 98 | + apply_qft(wires=range(n_qubits)) |
| 99 | + return qml.state() |
| 100 | + |
| 101 | +state = qft_circuit() |
| 102 | +print("QFT output state:", state) |
| 103 | + |
| 104 | + |
| 105 | +\chapter{Quantum Circuit Implementation} |
| 106 | + |
| 107 | +\section{High-Level Structure} |
| 108 | +The Quantum Fourier Transform can be efficiently implemented using a combination of Hadamard gates and controlled phase gates. Given an $n$-qubit state $\ket{x}$, the QFT circuit transforms it into the state: |
| 109 | +\[ |
| 110 | +\frac{1}{\sqrt{2^n}} \sum_{k=0}^{2^n - 1} e^{2\pi i xk / 2^n} \ket{k} |
| 111 | +\] |
| 112 | + |
| 113 | +This is achieved through a decomposition into a quantum circuit of $O(n^2)$ gates. |
| 114 | + |
| 115 | +\section{QFT on 3 Qubits} |
| 116 | +We illustrate the circuit for $n = 3$. The transformation proceeds as follows: |
| 117 | + |
| 118 | +\begin{enumerate} |
| 119 | + \item Apply a Hadamard gate to the first qubit. |
| 120 | + \item Apply controlled-$R_k$ gates (phase gates) for $k=2, 3, \dots$ to encode phase interference. |
| 121 | + \item Repeat recursively on the remaining qubits. |
| 122 | + \item Apply a qubit swap at the end to reverse the order of qubits. |
| 123 | +\end{enumerate} |
| 124 | + |
| 125 | +\section{Controlled Phase Rotation} |
| 126 | +The controlled phase rotation gate $R_k$ is defined as: |
| 127 | +\[ |
| 128 | +R_k = \begin{bmatrix} |
| 129 | +1 & 0 \\ |
| 130 | +0 & e^{2\pi i / 2^k} |
| 131 | +\end{bmatrix} |
| 132 | +\] |
| 133 | + |
| 134 | +This gate introduces the correct phase into the wavefunction based on the binary digits of the input number. |
| 135 | + |
| 136 | +\section{Circuit Diagram} |
| 137 | +The QFT circuit for 3 qubits is shown below (read top to bottom): |
| 138 | + |
| 139 | +\[ |
| 140 | +\Qcircuit @C=1em @R=1em { |
| 141 | +\lstick{\ket{x_0}} & \gate{H} & \ctrl{1} & \ctrl{2} & \qw & \qw & \swap{2} & \qw \\ |
| 142 | +\lstick{\ket{x_1}} & \qw & \gate{R_2} & \ctrl{1} & \gate{H} & \qw & \qw & \qw \\ |
| 143 | +\lstick{\ket{x_2}} & \qw & \qw & \gate{R_2} & \qw & \gate{H} & \swap{-2} & \qw |
| 144 | +} |
| 145 | +\] |
| 146 | + |
| 147 | +\section{Python Code with PennyLane} |
| 148 | +We now implement a full QFT circuit manually for 3 qubits using PennyLane. |
| 149 | + |
| 150 | +\begin{lstlisting}[language=Python] |
| 151 | +import pennylane as qml |
| 152 | +from pennylane import numpy as np |
| 153 | +import math |
| 154 | + |
| 155 | +dev = qml.device("default.qubit", wires=3) |
| 156 | + |
| 157 | +def qft_rotations(wires): |
| 158 | + if len(wires) == 0: |
| 159 | + return |
| 160 | + head, *tail = wires |
| 161 | + qml.Hadamard(wires=head) |
| 162 | + for i, qubit in enumerate(tail): |
| 163 | + qml.ctrl(qml.PhaseShift, control=qubit)(math.pi / 2**(i+1), wires=head) |
| 164 | + qft_rotations(tail) |
| 165 | + |
| 166 | +def swap_registers(wires): |
| 167 | + for i in range(len(wires) // 2): |
| 168 | + qml.SWAP(wires=[wires[i], wires[-i - 1]]) |
| 169 | + |
| 170 | +@qml.qnode(dev) |
| 171 | +def qft_custom(): |
| 172 | + qml.BasisState(np.array([1, 0, 1]), wires=range(3)) |
| 173 | + qft_rotations(wires=[0, 1, 2]) |
| 174 | + swap_registers(wires=[0, 1, 2]) |
| 175 | + return qml.state() |
| 176 | + |
| 177 | +print("Custom QFT state:", qft_custom()) |
| 178 | +\end{lstlisting} |
| 179 | + |
| 180 | +\section{Complexity} |
| 181 | +- The QFT requires $O(n^2)$ gates. |
| 182 | +- Approximate QFT implementations can reduce complexity by omitting small-angle phase gates. |
| 183 | + |
| 184 | +\section{Summary} |
| 185 | +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. |
0 commit comments