Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Building the n-Qubit QFT Circuit

Hello! Welcome to the next lesson in our exploration of foundational quantum algorithms.

In our previous lesson, we completed our study of Grover's algorithm by deriving its quadratic speedup. We saw how the algorithm could be understood geometrically as a rotation in a 2D vector space, and that this rotation is constructed from two reflections implemented by the oracle and the diffusion operator. This analysis gave us the optimal number of iterations and the famous query complexity.

Today, we shift our focus to another monumental tool in quantum computation: the Quantum Fourier Transform (QFT). The QFT is the quantum analogue of the classical Discrete Fourier Transform (DFT), a tool you are likely familiar with from your work in astrophysics for signal processing and solving differential equations. The QFT is the core component that unlocks the exponential speedup in many crucial quantum algorithms, most notably Shor's algorithm for factoring.

Our learning outcome for this lesson is to: Construct the quantum circuit for the n-qubit Quantum Fourier Transform using Hadamard and controlled-rotation gates. We will derive the circuit from first principles, understanding how the mathematical definition of the QFT can be translated into a sequence of elementary quantum gates.

1. The Quantum Fourier Transform: Definition

The QFT is a linear transformation that acts on the basis states of a quantum register. For an -qubit register, the Hilbert space has dimension . The QFT is defined by its action on any computational basis state , where is an integer from to :

This transformation takes a single basis state and maps it into a superposition of all basis states. The amplitude of each component is a complex phase, specifically a root of unity, determined by the input and the output index . When applied to an arbitrary quantum state , the QFT transforms the amplitudes into their discrete Fourier transform.

For a deeper look at the formal definition and its relation to the classical DFT, please review the first section of the following document.

Quantum Fourier Transform and Applications

These lecture notes from the University of Trieste provide a concise and formal introduction to the QFT. This section establishes the mathematical foundation we'll build upon.

Please read the section '5.1 The quantum Fourier transform' (pages 3-4). Focus on Equation (5.2), which is the core definition. Note the statement that the QFT is a unitary transformation, a crucial property for any quantum gate.

2. The Key to an Efficient Circuit: The Product Representation

The definition above, while precise, does not immediately suggest an efficient quantum circuit. A direct implementation would require an exponentially large unitary matrix. The breakthrough comes from rewriting the QFT in a different form—a product representation.

This representation expresses the output state as a tensor product of single-qubit states, where the phase of each qubit depends on the bits of the input number . Let's represent the input state using its binary representation , where .

The QFT can be rewritten as:

Here, the notation represents the binary fraction .

This product form is the crucial insight. It shows that the output is not an entangled mess but has a separable structure that we can build up qubit by qubit. The derivation of this form is an elegant piece of algebra.

Quantum Fourier Transform and Applications

The same lecture notes derive this essential product representation. Understanding this derivation is key to understanding the circuit's logic.

Please read the section 'Circuit for the Quantum Fourier Transform' (pages 4-7). Focus on the derivation from Equation (5.5) to (5.10) which establishes the product representation. Then, follow the logic from Equation (5.12) onwards, which shows how this representation translates into a sequence of gates.

3. Constructing the QFT Circuit

As you saw in the reading, the product representation allows us to construct the circuit. Let's break down the process.

The circuit produces the terms of the product representation in reverse order, starting with the term that depends only on and ending with the term that depends on all bits .

The circuit consists of two main components:

  1. Hadamard and Controlled-Rotations: For each qubit (from 1 to ), we apply a Hadamard gate, followed by a series of controlled-rotation gates controlled by the subsequent qubits.
  2. SWAP Gates: The initial sequence of gates produces the correct qubit states but in the wrong order (). A final layer of SWAP gates is needed to reverse the qubit order.

The Gates

  • Hadamard (H): Creates the initial superposition.
  • Controlled-Rotation (): This is a controlled-phase gate that applies a phase to the target qubit if the control qubit is . Its matrix is: A controlled- gate from qubit to qubit applies the transformation to only if is in state .

The General Circuit Structure

The following video provides a clear visual explanation of the general -qubit QFT circuit, including the final swap operations.

Inverse n-qubit Quantum Fourier Transform and Phase Estimation Quantum Circuit

This video from Elucyda presents the general n-qubit QFT circuit diagram and explains the role of each component.

Watch from 00:37 to 05:45. The first part (until 03:54) details the structure of the Hadamard and controlled-rotation gates. The second part (from 03:54) explains why the SWAP gates are necessary and how many are needed.

To summarize the structure shown in the video and the reading:

  1. On qubit 1: Apply H, then a controlled- from qubit 2, a controlled- from qubit 3, ..., up to a controlled- from qubit .
  2. On qubit 2: Apply H, then a controlled- from qubit 3, a controlled- from qubit 4, ..., up to a controlled- from qubit .
  3. ...
  4. On qubit : Apply H, then controlled- gates from qubits for .
  5. On qubit : Apply H.
  6. Final Swaps: Apply SWAP gates to reverse the qubit order: swap qubit 1 with , 2 with , and so on.

4. A Concrete Example: 3-Qubit QFT

Let's solidify this with a 3-qubit example. The input is .

The circuit proceeds as follows:

  1. Qubit 1: H gate. Then, a controlled- (also called an S gate) from qubit 2. Then, a controlled- (also called a T gate) from qubit 3.
  2. Qubit 2: H gate. Then, a controlled- from qubit 3.
  3. Qubit 3: H gate.
  4. Swaps: Swap qubit 1 and qubit 3.

The video below walks through this 3-qubit example, showing how an input state is transformed step-by-step.

Quantum Computing Course: 3.6 Quantum Fourier Transform

This video from Quantum Soar provides a step-by-step mathematical walkthrough of the 3-qubit QFT, connecting the abstract formula to the concrete action of the gates.

Watch from 02:18 to 05:35. This segment first introduces the circuit diagram and then applies it to a general 3-qubit state |j⟩, showing how the final state matches the product representation.

Conclusion

In this lesson, we have successfully constructed the circuit for the n-qubit Quantum Fourier Transform. We moved from the formal mathematical definition to an efficient circuit implementation by leveraging the powerful product representation of the QFT.

Key Takeaways:

  • The QFT maps a computational basis state into a uniform superposition where the phases encode the value of the input state.
  • The key to an efficient circuit is the product representation, which expresses the QFT output as a tensor product of single-qubit states.
  • The circuit is constructed using a repeating pattern of Hadamard gates and controlled-rotation gates ().
  • The initial gate sequence produces the output qubits in reverse order, necessitating a final layer of SWAP gates.
  • The complete circuit for an -qubit QFT consists of Hadamard gates, controlled-rotation gates, and SWAP gates.

We have now built the circuit. The next logical step is to analyze its efficiency. In our next lesson, we will analyze the gate complexity of the Quantum Fourier Transform circuit and contrast its computational cost with the classical Fast Fourier Transform. This will reveal the source of the exponential speedup that makes algorithms like Shor's possible.

Can't find a good explanation? Sign up and we'll make it for you

Sign up