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.


num_wires = 3
dev = qml.device("default.qubit", wires=num_wires)

@qml.qnode(dev)
def three_qubit_QFT(basis_id):
"""A circuit that computes the QFT on three qubits.
Args:
basis_id (int): An integer value identifying the basis state to construct.
Returns:
array[complex]: The state of the qubits after the QFT operation.
"""
# Prepare the basis state |basis_id>
bits = [int(x) for x in np.binary_repr(basis_id, width=num_wires)]
qml.BasisState(bits, wires=[0, 1, 2])
##################
# YOUR CODE HERE #
##################

pass

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.