The following figure shows the QFT circuit on qubits, with a focus on the action of rotations on the first qubit.

As you can see, there is a Hadamard gate, followed by a contribution of rotations on each qubit from every subsequent qubit, followed by SWAP gates. These sequences of rotations produce the QFT in which the order of the qubits is reversed. For example, on the first qubit we obtain the term which is the last term in

This explains why we have SWAP gates at the end of the circuit!

To warm up our fingers, let's first derive this circuit for three qubits and implement it. We need the controlled gates and .

Implement the QFT for three qubits.

Hint.

Calculate the controlled- gates as follows:

These are familiar gates! Remember too that you can use the qml.ctrl operation to make a controlled gate.


or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Describe the QFT as a generalization of the Hadamard transform.
  • Derive the n-qubit QFT circuit.
  • Give examples of applications of the Quantum Fourier transform.