Skip to main content

Building a Quantum Fourier Transform Circuit

The Quantum Fourier Transform (QFT) is a fundamental quantum algorithm that performs a Fourier transform on quantum amplitudes. This guide will walk you through creating a QFT circuit in LeafSheep QVU.

Circuit Overview

Circuit diagram showing 3-qubit QFT implementation with H gates and controlled-P gates

The QFT circuit shown above consists of:

Step-by-Step Construction

1. Create the Basic Circuit Structure

  1. Open LeafSheep QVU
  2. Add 3 qubits using the '+' button
  3. Enable measurements on all qubits
Screenshot showing initial setup with 3 qubits and measurement gates

2. Adding Gates

  1. Drag the required gates from the Gate Palette in this order:

For Qubit 0 (top line):

For Qubit 1 (middle line):

  • Add a Hadamard (H) gate, positioned after the second P gate of Qubit 0
  • Add one Phase (P) gate after the H gate

For Qubit 2 (bottom line):

  • Add a Hadamard (H) gate, positioned after the P gate of Qubit 1
Screenshot showing circuit with gates placed on each qubit
note

The order and positioning of gates is important for the QFT algorithm to work correctly. Make sure each gate is placed after the previous operations as described above.

3. Add Controlled Phase Gates

Now we'll convert the P Gates into Controlled-P Gates by adding control points:

For the P Gates on Qubit 0 (top line):

  • First P Gate: Add control to Qubit 1 (middle line)
  • Second P Gate: Add control to Qubit 2 (bottom line)

For the P Gate on Qubit 1 (middle line):

  • Add control to Qubit 2 (bottom line)

To add controls:

  • Hover on any P Gate to reveal control points
  • Click and drag from the control point to the target qubit line
  • A black dot and vertical line will appear, showing the control connection
Screenshot showing circuit with controlled-P gates added

4. Configure Phase Gates

Now we'll set the phase angles for each Controlled-P gate:

For the P Gates on Qubit 0 (top line):

  • First P gate (controlling Qubit 1): Set phase to 0.5 (equivalent to π/2)
  • Second P gate (controlling Qubit 2): Set phase to 0.25 (equivalent to π/4)

For the P Gate on Qubit 1 (middle line):

  • P gate (controlling Qubit 2): Set phase to 0.5 (equivalent to π/2)

To set the phase parameters:

  • Hover over a P gate to open its parameter panel
  • Enter the value as a decimal (the value will be multiplied by π)
  • Example: entering 0.5 means 0.5π or π/2
Screenshot showing parameter panel for the third P gate with phase angle set
caution

The phase values are crucial for the QFT algorithm. Make sure each gate has the correct phase value before running the circuit.

Running the Circuit

  1. Ensure all measurement buttons are enabled
  2. Open the Console tab by clicking on the console button (console tab icon) on the right of the screen
  3. Set the number of shots
  4. Click "RUN" to execute the simulation
Screenshot showing the run button and console tab

Expected Results

When you run this circuit, you should see:

  • Probability distribution across all possible states
  • You can see the Measurement counts by turning on the count switch on results panel
Screenshot showing measurement results and probability distribution

Common Issues and Tips

tip
  • Ensure precise phase angles for accurate results
  • Check that all control connections are properly set
  • Verify that all measurements are enabled
  • Use sufficient shots for reliable statistics

Theoretical Background

The Quantum Fourier Transform (QFT) is a quantum analogue of the classical discrete Fourier transform. It's a linear transformation on quantum bits that plays a crucial role in many quantum algorithms, including:

  • Shor's algorithm for factoring
  • Quantum phase estimation
  • Hidden subgroup problems
  • Fast quantum arithmetic operations

Mathematical Definition

For an n-qubit system (N = 2ⁿ), the QFT transforms a quantum state |x⟩ into:

Theorical circuit of QFT QFT:x1Nk=0N1ωNxkkQFT:|x⟩ \mapsto \frac{1}{\sqrt{N}}\sum_{k=0}^{N-1}\omega_N^{xk}|k⟩

where ωn=e2πi/Nωₙ = e^{2πi/N} is an NNth root of unity.

Why Phase Gates (P Gates)?

In our circuit implementation, we use P gates (controlled-phase gates) to create the required phase relationships. Here's why:

  1. The QFT can be decomposed into a product of simpler operations:

    • Hadamard gates (H) create superpositions
    • Phase gates (P) apply the necessary phase factors
  2. The phase angles in our implementation correspond to the powers of ωₙ in the mathematical formula:

    • First P gate: phase = π/2 (equivalent to ω₄)
    • Second P gate: phase = π/4 (equivalent to ω₈)
    • And so on...
  3. When controlled, these P gates create the entanglement necessary for the QFT's quantum parallelism.

tip

Understanding the mathematical foundation helps in:

  • Verifying circuit correctness
  • Choosing appropriate phase angles
  • Extending to larger numbers of qubits

Next Steps

Now that you've built your first QFT circuit, you can:

  1. Experiment with Different Sizes

    • Add more qubits to see how the circuit scales
    • Observe how the phase angles follow a pattern
  2. Modify Parameters

    • Try different phase angles to see their effect
    • Observe how measurement results change