The SWAP gate exchanges the complete quantum states of two qubits. Where CNOT
conditionally flips one qubit, SWAP unconditionally trades the contents of both — whatever
amplitude was on qubit a moves to qubit b, and vice versa.
What SWAP does
On basis states, SWAP simply permutes the two labels:
In the computational basis {∣00⟩,∣01⟩,∣10⟩,∣11⟩} (qubit 0 most
significant) this corresponds to the unitary matrix
SWAP=1000001001000001.
The off-diagonal 1s in the ∣01⟩/∣10⟩ block are what effect the exchange.
SWAP on superpositions
Because SWAP is linear, it works just as cleanly on superpositions. If qubit 0 carries
amplitude α∣0⟩+β∣1⟩ and qubit 1 carries γ∣0⟩+δ∣1⟩,
then after SWAP qubit 0 carries γ∣0⟩+δ∣1⟩ and qubit 1 carries
α∣0⟩+β∣1⟩ — a full exchange of the amplitude packets, including any
relative phases.
Try it
The circuit below puts qubit 0 into ∣1⟩, leaving the two-qubit register in ∣10⟩.
Your task is to apply SWAP so the register ends in ∣01⟩ — qubit 0 returns to ∣0⟩
and qubit 1 receives the ∣1⟩.
Run your code to see the quantum state.
After a correct solution the statevector should show amplitude 1 on the ∣01⟩ basis state
and zero everywhere else.
Sign in on the full site to ask questions and join the discussion.