F.2 CSWAP error

For this circuit, I am not sure why the cswap is leading to an error. Also, am I thinking about how to swap the middle matix rows correctly?

def decompose_two_qubit_QFT(basis_id):
“”"A circuit that computes the QFT on two qubits using elementary gates.

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=dev.num_wires)]
qml.BasisStatePreparation(bits, wires=[0, 1])

##################
# YOUR CODE HERE #
##################
qml.ctrl(qml.SWAP, control = 0)(wires = [0,1])
qml.Hadamard(wires = 0)
qml.Hadamard(wires = 0)
qml.S(wires = 1)
qml.Hadamard(wires = 1)
qml.adjoint(qml.S)(wires = 1)
qml.Hadamard(wires = 1)
qml.ctrl(qml.SWAP, control = 0)(wires = [0,1])

return qml.state()

Hey @simsaidan! The CSWAP operator, which I believe is being called under the hood when you call qml.ctrl(qml.SWAP), is a three-qubit operator. I assume your error message is something like this:

ValueError: CSWAP: wrong number of wires. 2 wires given, 3 expected.

In your case, you’re specifying that you want the control qubit to be wire 0. Then, you are specifying that the target qubits be wire 0 and wire 1, where wire 0 is already being used as the control qubit!