Level 6 · Practitioner’s Corner

The Quantum Fourier Transform in Qiskit

About 4,991 words · roughly 23 minute read · sources checked December 2, 2026

The Quantum Fourier Transform, QFT for short, is the engine inside Shor’s factoring algorithm and quantum phase estimation. It does to a quantum state what the ordinary Fourier transform does to a signal: it reveals repeating patterns. Given a state whose amplitudes repeat with some period, the QFT turns it into a state whose probability is concentrated on a few sharp values related to that period.

This lesson builds the QFT in Qiskit from ordinary gates, proves to yourself that the circuit really is the Fourier transform by comparing it with the standard matrix, counts how many gates it needs, and then shows the key behaviour with two small examples where a period of 4 and a period of 2 produce clean peaks.

As in the other Qiskit lessons here, I could not run Qiskit in my environment. The code is written from documented behaviour, and every number comes from my own NumPy simulation of the same gates with Qiskit’s bit ordering (qubit 0 on the right of a result string). Run the code and compare.

What you will learn

  • What the discrete Fourier transform is and why the quantum version is a circuit.
  • How to build the QFT from Hadamard, controlled-phase and swap gates.
  • How to check the circuit against the Fourier matrix.
  • How many gates the circuit needs for n qubits.
  • How a periodic state is turned into sharp peaks, with exact probabilities.
  • Why the QFT alone does not speed up Fourier analysis of ordinary data.

Helpful first: Your First Qiskit Circuit, Shor’s Algorithm.

The Fourier transform, in two minutes

The discrete Fourier transform takes a list of N numbers and re-expresses it as a sum of waves. The output entry k says how much of the wave with k cycles over the list is present. A list that repeats every 4 entries, with N = 8, has strong content at the waves that fit a whole number of times into each repeat, and almost none elsewhere.

The quantum version acts on the amplitudes of a state. With n qubits there are N = 2ⁿ amplitudes, and the QFT maps the basis state |j⟩ to a superposition of all basis states, each with a phase that depends on j and k.

QFT |j⟩  =  (1/√N) Σₖ  e^(2πi·jk/N) |k⟩        (sum over k = 0 … N−1, N = 2ⁿ)
matrix entry:  F[k, j] = e^(2πi·jk/N) / √N
The Quantum Fourier Transform. Every output state has the same size 1/√N; only the phases carry the information.

Worked example

The QFT of |5⟩ with three qubits

  1. N = 8 and j = 5. Every amplitude has magnitude 1/√8 = 0.3536.
  2. The phase of output k is e^(2πi·5k/8), which is a fraction 5k/8 of a full turn (taken modulo 1).
  3. k = 0: 0 turns. k = 1: 5/8 = 0.625, which is −0.375 turns. k = 2: 10/8 = 1.25, which is 0.25 turns. k = 3: 15/8 = 1.875, which is −0.125 turns.
  4. My simulation of the circuit below gave exactly these phases for k = 0 to 7: 0, −0.375, 0.25, −0.125, 0.5, 0.125, −0.25, 0.375 turns.

Notice that a single input basis state gives equal probability 1/8 to every output. The QFT of a basis state looks flat if you only measure it. The information is in the phases, and it becomes visible when several inputs interfere, which is what happens for periodic states below.

Building the circuit

The QFT circuit has a regular shape. For each qubit, from the top qubit down, apply a Hadamard, then apply controlled-phase gates from every lower qubit with smaller and smaller angles. At the end, swap qubits to reverse their order.

import math
from qiskit import QuantumCircuit

def qft(n):
    qc = QuantumCircuit(n)
    for j in reversed(range(n)):
        qc.h(j)
        for k in reversed(range(j)):
            qc.cp(math.pi / 2 ** (j - k), k, j)    # controlled phase, angle pi / 2^(j-k)
    for i in range(n // 2):
        qc.swap(i, n - 1 - i)                       # reverse the qubit order
    return qc

print(qft(3).draw())
A QFT built from basic gates. Not run in Qiskit here.

The controlled-phase gate cp(angle, control, target) multiplies the state by e^(i·angle) only when both qubits are 1. The angles π/2, π/4, π/8 and so on are the source of the Fourier phases: each qubit’s Hadamard puts the state into a superposition, and the controlled phases rotate it by an amount that depends on the lower qubits.

Why the swaps

Without the swaps the circuit gives the right transform but with the output qubits in reverse order. The swaps put them back. If you plan to measure and are happy to reverse the string yourself, you can skip them, which saves gates.

Checking it against the textbook matrix

The strongest test is to compute the matrix of the circuit and compare it with the Fourier matrix. In Qiskit you can get a circuit’s matrix from the Operator class in qiskit.quantum_info.

import numpy as np
from qiskit.quantum_info import Operator

n = 3
N = 2 ** n
U = Operator(qft(n)).data
F = np.array([[np.exp(2j * np.pi * j * k / N) for k in range(N)] for j in range(N)]) / np.sqrt(N)
print(np.allclose(U, F))       # expected: True
Comparing the circuit with the discrete Fourier matrix. Not run in Qiskit here; my own simulation of the same gates gave True for n = 3.

In my simulation the circuit matrix and the Fourier matrix agreed to numerical precision for n = 3, using Qiskit’s convention that the basis state’s integer index is read with qubit 0 as the least significant bit. If you get False on your machine, the likeliest cause is a bit-order difference, so test with n = 2 first and compare the entries by hand.

How many gates does it need?

The circuit has n Hadamards, n(n − 1)/2 controlled-phase gates (each qubit j has j of them), and ⌊n/2⌋ swaps. Counting is easy and shows how the cost grows.

Qubits nHadamardsControlled-phaseSwapsTotal gatesSize of the matrix it applies (2ⁿ × 2ⁿ)
333178 × 8
44621216 × 16
551021732 × 32
8828440256 × 256
1010455601,024 × 1,024

Counted from the circuit definition above; the totals match my gate count from the simulation code. Rows for n = 4, 5, 8 and 10 use the same formula.

Sixty gates for a transform on a 1,024-dimensional space looks like a bargain. The classical fast Fourier transform on N = 1,024 numbers takes on the order of N log₂ N ≈ 10,240 operations. That comparison is exactly the point people make, and it is also where the claim becomes misleading, as the next section explains.

An important caveat

The 60 gates act on a quantum state of 1,024 amplitudes. You cannot read those amplitudes out directly, and loading an arbitrary list of 1,024 numbers into a state costs far more than 60 gates. So the QFT does not speed up taking the Fourier transform of an ordinary list of data. It is useful inside an algorithm where the input state is prepared cheaply and only a few measurement results are needed.

Also, the later controlled-phase gates use very small angles (π/2⁹ for n = 10), which real hardware cannot set precisely. Practical implementations sometimes drop the smallest rotations, giving an approximate QFT. I mention this from the general literature and did not check a source in this session.

What the QFT is for: seeing a period

Take three qubits and prepare a state that is an equal superposition of positions 0 and 4: (|000⟩ + |100⟩)/√2. That is a pattern that repeats with period 4 in a list of 8. In Qiskit you prepare it with one Hadamard, on qubit 2, because qubit 2 is the one that changes the integer by 4.

from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler

qc = QuantumCircuit(3)
qc.h(2)                    # state (|000> + |100>)/sqrt(2): positions 0 and 4
qc.compose(qft(3), inplace=True)
qc.measure_all()
counts = StatevectorSampler().run([(qc, None, 4096)]).result()[0].data.meas.get_counts()
print(counts)
A period-4 state through the QFT. Not run in Qiskit here.

My simulation gave exactly equal probability, 0.25, on the four outcomes 000, 010, 100 and 110 (the values 0, 2, 4 and 6), and zero on the other four. A run of 4,096 shots should therefore show about 1,024 in each of those four, with random spread of about 28 per outcome.

Input state (positions)Period rOutcomes with probability > 0Probability of eachPeaks sit at multiples of N/r
0, 440, 2, 4, 60.258/4 = 2
0, 2, 4, 620, 40.58/2 = 4
1, 5, 9, 13 (four qubits)40, 4, 8, 120.2516/4 = 4

From my simulation. The third row starts at position 1 rather than 0, yet the peaks are at the same places, showing that a shift in the pattern changes only phases, not these probabilities.

This is the whole use of the QFT in Shor’s algorithm. If a quantum state repeats with an unknown period r in a space of size N, applying the QFT and measuring gives an outcome near a multiple of N/r. A few repeats of the measurement, plus some number theory (continued fractions), recover r. And finding the period of a function related to the number being factored is what lets Shor’s algorithm find factors.

Worked example

Reading a period off the output

  1. Suppose you measure the period-4 example and get 6, 2, 4 and 0 on different runs, with N = 8.
  2. The outcomes are multiples of 2, so N/r = 2 and r = 8/2 = 4.
  3. A single measurement of 6 is ambiguous (it fits several r), but the pair of results gives the common spacing, and the spacing gives the period.

What the QFT does not do alone

It does not find the period for you. It converts a hidden period in the amplitudes into a visible pattern of likely measurement results. Preparing the periodic state in the first place is the hard part of Shor’s algorithm, and it needs a modular-exponentiation circuit that costs far more gates than the QFT itself.

The inverse QFT and phase estimation in miniature

Running the QFT backwards (the inverse QFT) does the opposite job: it turns a state whose amplitudes carry a hidden phase into a sharp peak at the number that encodes that phase. This is the last step of quantum phase estimation, and it is where a quantum computer learns the value of a phase.

Here is the smallest version. We build a register of n qubits in the state whose k-th amplitude is e^(2πiφk)/√N, for a chosen phase φ, then apply the inverse QFT and measure. In Qiskit the inverse of a circuit is available as the inverse method.

import math
from qiskit import QuantumCircuit

def phase_demo(phi, n):
    qc = QuantumCircuit(n)
    qc.h(range(n))
    for i in range(n):
        qc.p(2 * math.pi * phi * 2 ** i, i)    # qubit i carries weight 2^i
    qc.compose(qft(n).inverse(), inplace=True)
    qc.measure_all()
    return qc
Phase estimation in miniature. Not run in Qiskit here. The p method applies a phase gate. In real phase estimation the phases come from controlled operations on an eigenstate; here we write them in directly to see the readout.
Phase φResult (3 qubits)P(result)Reading
0.250101.0000010 is 2, and 2/8 = 0.25: exact
0.1250011.00001/8 = 0.125: exact
0.3750111.00003/8 = 0.375: exact
1/3 (0.3333)011 (most likely)0.68783/8 = 0.375, nearest of the eight values
0.3010 (most likely)0.57752/8 = 0.25 is nearest below; 3/8 comes next with 0.2593

From my simulation. When φ is a multiple of 1/8 the answer is exact. Otherwise the probability is spread, with the nearest values most likely.

When the phase is not a multiple of 1/N, the answer is blurred. For φ = 1/3 the three-qubit probabilities are about 0.016, 0.032, 0.175, 0.688, 0.047, 0.019, 0.013 and 0.012 for the results 0 to 7: a clear peak at 3 (so 3/8 = 0.375) but with a long tail. Adding qubits sharpens the estimate.

Qubits nMost likely result ÷ 2ⁿP(most likely result)
30.37500.6878
40.31250.6849
50.34380.6842
60.32810.6840

For φ = 1/3, true value 0.3333. The estimate gets closer as qubits are added, while the probability of landing on the single best value stays near 0.68.

Why this matters for Shor’s algorithm

In Shor’s algorithm the phase being estimated encodes the period of a function. More counting qubits give a finer estimate, and the number theory that follows turns the estimate into the period. The probability of about 0.68 for the best single value is not a flaw: the neighbouring values also point to the right fraction, and the classical post-processing can use them.

The approximate QFT: dropping the tiny rotations

The smallest controlled-phase gates are the hardest to apply accurately, and for large n they barely change the result. An approximate QFT keeps only controlled phases between qubits no more than d places apart and drops the rest. I tested this on eight qubits, comparing the approximate circuit with the full one on 20 random states, and report the average overlap (fidelity).

Largest gap kept (d)Controlled-phase gates kept (out of 28)Average fidelity with the full QFTWorst of the 20
170.20730.1561
2130.72410.6839
3180.94210.9305
4220.99020.9877
5250.99870.9983
7 (all)281.00001.0000

From my simulation with a fixed random seed. Fidelity is |⟨full|approx⟩|² for the same input. Random states are a rough test; an algorithm may be more or less sensitive than this average suggests.

The pattern is clear: dropping the smallest angles costs little. Keeping gaps up to 4 retains 22 of 28 phase gates and an average fidelity near 0.99. Keeping only nearest neighbours loses almost everything. This is the idea behind approximate QFTs used to save gates on real machines, and the trade-off is yours to choose by testing.

See the QFT find a period in your browser

The most useful thing the quantum Fourier transform does is turn a hidden period into a peak you can measure. Before we write more code, watch it happen. Each widget prepares a state with a repeating pattern, applies a three-qubit QFT built from Hadamard gates, controlled phase rotations and a final swap, and measures. The strings use Qiskit's convention: qubit 0 is the rightmost bit, so 100 means the value 4.

A pattern that repeats every 2

Run this circuit

QFT on a state with period 2

q0q1q2HHHP1.57P0.79HP1.57H

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: The input is an equal superposition of the values 0, 2, 4 and 6 out of 8, a pattern that repeats every 2. The QFT turns a period r into peaks spaced N/r = 4 apart. Which outputs do you expect?

Press Run to simulate. Results appear here with a short explanation.

A pattern that repeats every 4

Run this circuit

QFT on a state with period 4

q0q1q2HHP1.57P0.79HP1.57H

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: Now the input is an equal superposition of 0 and 4, which repeats every 4. Peaks should be spaced N/4 = 2 apart. Which outputs?

Press Run to simulate. Results appear here with a short explanation.

The two results fit a simple rule. If the input is spread evenly over values spaced r apart, the output has spikes spaced N/r apart, where N = 2ⁿ is the number of values. For N = 8 and r = 2 the spikes are at multiples of 4. For r = 4 they are at multiples of 2. Longer period in, finer spacing out. A measurement returns one of the spikes, and from its position you read off N/r and so r. That is the whole idea behind the use of the QFT in Shor's algorithm.

A caution about what you see

Each shot gives only one of the spikes, never the full pattern. In the period-2 case you see either 000 or 100 in any single run. Information about the period is in which values are possible, not in any one outcome, so the algorithms repeat the run and combine the results.

The two-qubit QFT as an explicit matrix

The best way to trust the circuit is to see the matrix it implements. For two qubits N = 4 and the QFT is the matrix whose entry in row k and column j is ω^(jk)/√N with ω = e^(2πi/4) = i. Writing out the powers of i gives:

F₄ = (1/2) ×
  [ 1   1   1   1 ]
  [ 1   i  −1  −i ]
  [ 1  −1   1  −1 ]
  [ 1  −i  −1   i ]
The 4 × 4 quantum Fourier transform. Row k, column j holds i^(jk) divided by 2. My own calculation, checked with NumPy.

Worked example

Apply F₄ to the basis state |01⟩ (the value 1)

  1. The state |1⟩ as a vector is [0, 1, 0, 0], so the result is the second column of the matrix.
  2. That column is (1/2)·[1, i, −1, −i].
  3. Every output value has probability |1/2|² = 1/4. A basis state gives a flat distribution, as expected, since a perfectly sharp value has no definite frequency.
  4. The information is not in the probabilities but in the phases: i, −1, −i step around a quarter-turn each, which is the signature of frequency 1.

Worked example

Apply F₄ to the equal superposition of 0 and 2

  1. The input is (|0⟩ + |2⟩)/√2 = [1, 0, 1, 0]/√2, which has period 2.
  2. Add columns 0 and 2: (1/2)[1, 1, 1, 1] + (1/2)[1, −1, 1, −1] = [1, 0, 1, 0].
  3. Divide by √2: [1/√2, 0, 1/√2, 0].
  4. Outputs 0 and 2 each have probability 1/2, and 1 and 3 never appear. Spacing N/r = 4/2 = 2, as the rule predicts.

In both examples the transform is just matrix arithmetic. The circuit's job is to implement this matrix with few gates, which for two qubits needs two Hadamard gates, one controlled phase gate with angle π/2 and one swap.

The phases are the content

In the first example every probability is 1/4, so a measurement would learn nothing. That is a reminder that a single QFT followed by a measurement is useful only on states that already have a periodic structure. Inside Shor's algorithm and phase estimation, the earlier steps prepare exactly that structure, and the QFT is the final step that converts it into something readable.

When the period does not divide the size

The clean spikes above appeared because the period divided N exactly. Real problems are rarely so kind. If N = 16 and the period is 3, the spacing N/r = 5.33 is not an integer, and the spikes are blurred across neighbouring values. I computed the QFT of an equal superposition of the values 1, 4, 7, 10 and 13 on four qubits, a pattern with period 3, using NumPy.

Output valueProbabilityOutput valueProbability
00.312580.0125
10.001590.0174
20.0021100.0729
30.0040110.2271
40.0125120.0125
50.2271130.0040
60.0729140.0021
70.0174150.0015

QFT of a period-3 pattern on 16 values (N = 16). My own NumPy calculation. The probabilities sum to 1.

There are three main peaks: one at 0, and two near 16/3 = 5.33 and 2 × 16/3 = 10.67, at the values 5 and 11, with a smaller shoulder at 6 and 10. Together the three peaks carry 0.3125 + 0.2271 + 0.2271 = 0.7667 of the probability, and the rest is spread thinly. A measurement at 5 or 11 gives a number from which the fraction 5/16 or 11/16 is close to 1/3 and 2/3, and a continued-fraction step recovers the denominator 3.

5 / 16 = 0.3125 ≈ 1/3
11 / 16 = 0.6875 ≈ 2/3
peak mass: 0.3125 + 0.2271 + 0.2271 = 0.7667
My own check: the measured value divided by N approximates a multiple of 1/r.

This is why Shor's algorithm uses more qubits than strictly needed for N: extra precision makes the peaks sharper and makes the continued-fraction step reliable. It is also why the algorithm is probabilistic and needs a few repetitions.

What the QFT costs, and why the number matters

On n qubits the standard QFT uses n Hadamard gates and n(n − 1)/2 controlled phase gates, so n(n + 1)/2 gates before the final swaps, which add another ⌊n/2⌋ swap gates. The classical fast Fourier transform on 2ⁿ numbers takes about n·2ⁿ operations. Compare the two.

n (qubits)Values N = 2ⁿQFT gates, n(n + 1)/2Classical FFT, about n·2ⁿ operations
38624
101,0245510,240
201,048,57621020,971,520
301.07 × 10⁹4653.2 × 10¹⁰
501.1 × 10¹⁵1,2755.6 × 10¹⁶

Gate counts for the QFT against operation counts for a classical FFT. My own arithmetic.

The gap looks dramatic, and it is, but it needs two caveats. First, the QFT acts on a quantum state, and you cannot read out all 2ⁿ amplitudes, so it does not replace the FFT when you want the full spectrum of a given list of numbers. Second, loading that list into a quantum state is itself costly, as we discuss in our lesson on whether quantum computers replace classical ones. The QFT shines when the state is created by an algorithm and the readout is a single useful number, as in period finding.

The tiny rotations

The controlled phase gates have angles π/2, π/4, π/8 and so on, halving each time as the distance between the qubits grows. For a 2048-qubit register, which is the size of one counting register in some Shor estimates, the last angles are π/2²⁰⁴⁷, a number far smaller than any hardware can set. Real implementations therefore drop the smallest rotations. The next section measures how much accuracy this costs.

An experiment: how much can you drop?

To quantify the approximate QFT I wrote a NumPy simulation of the eight-qubit transform. It builds the circuit with an optional cut-off: controlled phase gates between qubits further apart than m positions are omitted. For each cut-off it compares the output with the exact QFT on 200 random states and reports the average and the worst overlap. The overlap |⟨exact|approx⟩|² is 1 for a perfect match. This is my own code and my own numbers, not from a paper.

Cut-off m (maximum qubit distance kept)Gate count (n = 8)Average overlapWorst overlap in 200 trials
1150.21520.1383
2210.72780.6772
3260.94280.9249
4300.99020.9873
5330.99870.9983
7 (exact)361.00001.0000

Approximate QFT on 8 qubits against the exact transform, averaged over 200 random states. My own NumPy experiment.

Dropping the rotations at distance 5 or more removes only 3 of 36 gates and leaves an average overlap of 0.9987. Keeping only distance 1 has 15 gates and fails badly, with an average overlap of 0.22. The accuracy improves quickly as m grows, which is the reason approximate QFTs are used: you can cut a surprising fraction of the gates with a small loss.

Random states are a harsh test

I tested with random states because they exercise every part of the transform. For a structured input such as the periodic states used in Shor's algorithm the errors can be smaller. I did not test that, so the table is a conservative guide, not a guarantee.

The scaling is the useful lesson. A cut-off m of about log₂ n, or a small multiple, is often sufficient for a target accuracy, which brings the gate count from order n² down to order n·log n. For a 2048-qubit register that is the difference between two million controlled phase gates and a few tens of thousands. I did not open a source quantifying the cut-off needed in a specific Shor estimate, so treat the sentence about log n as the standard form of the argument and not a measured figure.

The QFT in context: inverse transforms and bit order

Two practical points trip people up when they move from this lesson to real algorithms.

The inverse QFT is what phase estimation uses

In quantum phase estimation, the counting register accumulates a phase pattern through controlled powers of an operator, and the inverse QFT converts it into the binary digits of the phase. The inverse transform is the same circuit run backwards, with each controlled phase angle negated. In the period-finding view above, you apply the forward transform to a state with a period and read a spike. In the phase-estimation view, you apply the inverse transform to a state with a phase ramp and read the binary value. Both are the same mathematics seen from the two sides, and which one an algorithm needs depends on whether it starts from a periodic pattern or from a phase ramp.

Bit order again

The textbook QFT circuit produces its output qubits in reverse order, which is why the swaps at the end are there. Qiskit's own library QFT includes the swaps by default, but you can switch them off, and some algorithms skip them and fix the bit order afterwards. If your output looks like the right answer with the bits reversed, a missing or doubled swap layer is the cause. The widgets above include the swaps and use the same bit order as Qiskit's printed strings.

Summary

  • The QFT maps a periodic input to spikes spaced N/r apart, which is how a period is read out.
  • The gate count is n(n + 1)/2 before swaps, far fewer than the classical FFT operations, but the output cannot be read out in full.
  • If the period does not divide N, the spikes blur, and extra qubits plus a continued-fraction step recover the period.
  • Dropping the smallest rotations costs little accuracy and cuts the gate count, as the experiment above shows for eight qubits.

Four tests for your own QFT circuit

If you write a QFT circuit yourself, whether in Qiskit, Cirq or by hand, you need a way to know it is right. These four tests catch almost every common bug. They use only statements derived above, and I checked the numerical ones with NumPy, including a comparison with NumPy's own inverse FFT.

TestWhat to doExpected result
1. Zero stateApply the QFT to |0…0⟩ and measureA flat distribution: every value has probability 1/N
2. PeriodPrepare an equal superposition of values 0, 2, 4, 6 on three qubits, apply the QFT, measureOnly 0 and 4 appear, each near 50%
3. MatrixCompare the circuit's unitary with the matrix whose entries are ω^(jk)/√N, with ω = e^(2πi/N)Equal up to numerical rounding, including the bit order
4. InverseApply the QFT and then its inverse to a random stateThe original state returns, with overlap 1

Four tests for a QFT circuit. Tests 2 and 3 are the ones that catch bit-order mistakes.

Test 3 has a useful shortcut. The QFT matrix defined with a positive exponent equals √N times NumPy's inverse FFT, because NumPy's inverse transform uses a positive exponent and divides by N. I confirmed this numerically for N = 8 on a random complex vector. If your circuit's unitary matches this matrix, it is correct. If it matches the matrix with its rows in bit-reversed order, you are missing the final swaps. If it matches the complex conjugate, you used the wrong sign for the phase angles, which is in effect the inverse transform.

Why test 2 is the most informative

A flat distribution in test 1 is easy to get by accident, since many wrong circuits also give a flat output. Test 2 has a definite answer that depends on the correct angles and the correct bit order, so it is the first to fail when something is wrong. The widget at the top of this lesson is exactly this test.

A note on global phase

When you compare unitaries, remember that two circuits can differ by a global phase and still implement the same operation. For the QFT built from the standard gates the match is exact, but if you build it from a library with different conventions, compare the unitaries up to a global phase: check that the absolute value of the normalised trace of one times the conjugate transpose of the other equals 1.

Common mistakes

  • Mixing up the bit order. In Qiskit qubit 0 is the least significant bit and the rightmost character of a result string. To prepare position 4 you set qubit 2, not qubit 0.
  • Dropping the swaps and then reading the output as if they were there. The probabilities come out in a reversed pattern.
  • Expecting a speed-up for ordinary data. Loading data and reading all outputs cost more than the circuit.
  • Using the wrong sign of the angle and building the inverse transform instead. The inverse QFT uses angles with the opposite sign, and it is what phase estimation actually applies.
  • Using a built-in QFT helper from an old tutorial. Names and classes for these helpers have changed between versions; build from gates if in doubt, or check your version’s documentation.
  • Expecting exact peaks on hardware. Small-angle gates and noise blur them.

Questions people ask

Is the QFT faster than the classical FFT?

The circuit uses about n²/2 gates for n qubits, which is far fewer than the roughly N log N operations of the classical transform on N = 2ⁿ numbers. But the two do different jobs: the QFT transforms a quantum state you cannot read out in full, so it does not give a general speed-up for Fourier analysis of data.

Where is the QFT used?

In Shor’s algorithm and in quantum phase estimation, among others. It is the step that converts a hidden period or phase into a measurable one.

Why are the angles so small for large n?

The angle π/2^m halves each time the gap between qubits grows. The tiny angles encode fine detail of the transform and are the hardest for real devices to apply accurately.

What is the inverse QFT?

It is the circuit run in reverse with the signs of the angles flipped. It undoes the QFT, and it is the version used at the end of phase estimation.

Do I need to build this myself, or use Qiskit’s version?

Qiskit provides its own QFT component, but I did not check its current name or deprecation status, so I built it from gates. Building it once is a good way to understand it.

Practice problems

Check yourself

How many gates (Hadamards, controlled-phase and swaps) does a 6-qubit QFT circuit have?

6 + 15 + 3 = 24.

What is the magnitude of each amplitude after the QFT of a basis state on 4 qubits?

1/√16 = 0.25, so each outcome has probability 1/16 = 0.0625.

Which qubit do you apply a Hadamard to in order to prepare positions 0 and 2 on three qubits?

Qubit 1, because position 2 is 010 in binary and qubit 1 is the middle bit.

After the QFT, a period-2 state on N = 8 gives outcomes 0 and 4. What is the period from N/r?

N/r = 4, so r = 2.

Why does shifting a periodic pattern (starting at position 1 instead of 0) not move the peaks?

A shift multiplies the output amplitudes by phases, which does not change their magnitudes, so probabilities stay put.

What is the smallest controlled-phase angle in a 10-qubit QFT?

π/2⁹ = π/512, about 0.00614 radians.

Why is the QFT alone not a way to speed up analysing an audio file?

Getting the audio into a quantum state and reading out all the amplitudes costs more than the circuit saves.

References and further reading

I opened IBM’s Sampler guide for the pattern of building a circuit, running a Sampler and reading a named classical register. I could not run Qiskit here, so none of the code was executed. Qiskit also ships a ready-made QFT, but I did not check its current name or whether your version marks it as deprecated, so this lesson builds the circuit from basic gates. Every printed number comes from my own NumPy simulation of the same gates using Qiskit’s bit ordering, including the check that the circuit’s matrix equals the discrete Fourier transform matrix. The QFT’s definition and gate structure are standard textbook material that I verified by that simulation.

  1. Get started with Sampler (IBM Quantum documentation) Opened. Pattern of building a circuit, running a Sampler and reading results from a named classical register. It does not cover QFT; the QFT circuit, its gate counts and all printed values come from my own simulation.
  2. IBM Quantum documentation (IBM) Opened. Overview of Qiskit guides, tutorials and API references.