SWAP Gate
The SWAP gate exchanges the quantum states of two qubits and decomposes into three sequential CNOT gates
Source: mortalapps.com- The SWAP gate exchanges the quantum states of two qubits.
- In circuit diagrams, SWAP is represented by two 'x' symbols connected by a vertical line.
- The 4x4 SWAP matrix swaps the second and third rows/columns of the Identity matrix.
- A SWAP gate can be decomposed into three alternating CNOT gates.
- Like CNOT, the SWAP gate is its own inverse (SWAP^2 = I).
- SWAP gates do not physically move qubits; they route the quantum information.
- Minimizing SWAP gates is a major focus of quantum compilers to reduce circuit depth and error rates.
Why This Matters
In physical quantum computers, qubits are often locked in fixed physical locations on a chip, and they can only interact with their immediate neighbors. This spatial constraint poses a major challenge: how do we perform a gate between two qubits that are far apart? The solution is the SWAP gate, which physically exchanges the quantum states of two qubits.
In this topic, we will study the SWAP gate. You will learn its mathematical representation as a $4\times4$ matrix, its action on the computational basis states, and its unique circuit symbol (two 'x' marks connected by a vertical line). We will also explore a beautiful and deep result: how to decompose a single SWAP gate into a sequence of three CNOT gates.
By the end of this topic, you will understand how to route quantum information through a circuit using SWAP gates and how to prove the equivalence of different multi-qubit circuit layouts mathematically.
Core Intuition
Imagine you and a friend are sitting in a theater, but you are in the wrong seats. To swap seats, you could both stand up and walk around each other. But in a crowded row, you might have to perform a coordinated dance: first, you slide into your friend's lap; then, your friend slides over you into your old seat; finally, you slide off into their old seat.
This coordinated dance is exactly how qubits swap states when they cannot physically move. Instead of physically moving the qubits, we perform a sequence of conditional operations (CNOTs) that transfer the information back and forth until the states are completely exchanged.
In a circuit diagram, the SWAP gate is represented by two 'x' symbols connected by a vertical line. It acts as a crossing point, allowing information on the top wire to jump to the bottom wire, and vice versa, without losing any quantum coherence or phase information.
Visualization
Technical Explanation
The SWAP gate exchanges the states of two qubits. Its action on the computational basis states is: $$|00\rangle \xrightarrow{\text{SWAP}} |00\rangle$$ $$|01\rangle \xrightarrow{\text{SWAP}} |10\rangle$$ $$|10\rangle \xrightarrow{\text{SWAP}} |01\rangle$$ $$|11\rangle \xrightarrow{\text{SWAP}} |11\rangle$$
Written as a $4\times4$ matrix in the computational basis ($|00\rangle, |01\rangle, |10\rangle, |11\rangle$), the SWAP matrix is:
$$\text{SWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}$$
Notice that the SWAP matrix swaps the second and third rows/columns of the identity matrix. A key property of the SWAP gate is that it can be decomposed into three alternating CNOT gates:
$$\text{SWAP}(q_0, q_1) = \text{CNOT}(q_0, q_1) \times \text{CNOT}(q_1, q_0) \times \text{CNOT}(q_0, q_1)$$
where $\text{CNOT}(a, b)$ denotes a CNOT with control $a$ and target $b$. Like CNOT, the SWAP gate is its own inverse: $\text{SWAP}^2 = I$.