Editorial
A quantum gate that swaps the states of qubits is called a swap gate.
In this problem, since only the qubits are swapped and the probability amplitudes remain unchanged, you might consider using an X gate or a CX gate.
In fact, it is known that the swap gate can be implemented using three controlled X gates, as shown below:
The state transitions can be expressed as follows:
a0∣00⟩+a1∣10⟩+a2∣01⟩+a3∣11⟩CX(0,1)a0∣00⟩+a3∣10⟩+a2∣01⟩+a1∣11⟩CX(1,0)a0∣00⟩+a3∣10⟩+a1∣01⟩+a2∣11⟩CX(0,1)a0∣00⟩+a2∣10⟩+a1∣01⟩+a3∣11⟩
The CX(0,1) gate swaps the probability amplitudes of ∣10⟩ and ∣11⟩, while the CX(1,0) gate swaps the probability amplitudes of ∣01⟩ and ∣11⟩.
The circuit depth is 3.
Sample Code
Below is a sample program:
from qiskit import QuantumCircuit
def solve() -> QuantumCircuit:
qc = QuantumCircuit(2)
qc.cx(0, 1)
qc.cx(1, 0)
qc.cx(0, 1)
return qc