• Fundamentals

SWAP Gate

A two-qubit gate that exchanges the quantum states of two qubits, essential for routing information on hardware with limited qubit connectivity.

The SWAP gate exchanges the complete quantum states of two qubits. If qubit A is in state ψ|\psi\rangle and qubit B is in state ϕ|\phi\rangle, after a SWAP they hold ϕ|\phi\rangle and ψ|\psi\rangle respectively. This operation is conceptually simple but practically critical: on hardware where qubits can only interact with their physical neighbors, SWAP gates are the mechanism that moves quantum information across the chip.

The details

The SWAP gate acts on the four computational basis states:

0000011010011111|00\rangle \to |00\rangle \quad |01\rangle \to |10\rangle \quad |10\rangle \to |01\rangle \quad |11\rangle \to |11\rangle

Its 4×44 \times 4 matrix representation is:

SWAP=(1000001001000001)\text{SWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

The circuit symbol uses crossed lines:

qubit A ──×──

qubit B ──×──

Decomposition into CNOTs. The SWAP gate decomposes into exactly three CNOT gates:

SWAP = CNOT(A,B) · CNOT(B,A) · CNOT(A,B)

In Qiskit:

from qiskit import QuantumCircuit

qc = QuantumCircuit(2)
qc.cx(0, 1)
qc.cx(1, 0)
qc.cx(0, 1)
# This is equivalent to qc.swap(0, 1)

Three CNOTs is the minimum; no decomposition can do it in fewer.

iSWAP variant. On Google’s superconducting hardware, the native entangling gate is the iSWAP rather than CNOT. The iSWAP performs a SWAP combined with a relative phase: 01i10|01\rangle \to i|10\rangle and 10i01|10\rangle \to i|01\rangle. Because iSWAP is natively available on the hardware, circuits compiled for Google chips often use iSWAP directly rather than decomposing into CNOTs.

sqrt(SWAP) gate. The square root of SWAP, written SWAP\sqrt{\text{SWAP}}, applies half of a SWAP operation. Applied twice, it produces a full SWAP. The SWAP\sqrt{\text{SWAP}} gate is universal for quantum computation when combined with single-qubit gates. It naturally arises in spin chain Hamiltonians, where qubit-qubit exchange interactions generate SWAP\sqrt{\text{SWAP}} at specific interaction times.

Routing and SWAP networks. Most quantum hardware has limited connectivity: qubits can only interact with a few physical neighbors. When an algorithm requires a two-qubit gate between distant qubits, the compiler inserts SWAP gates to route one qubit’s state adjacent to the other. This is called qubit routing, and the added SWAP gates increase circuit depth and error. SWAP networks, systematic patterns of SWAP gates, can rearrange an entire register of qubits in O(n)O(n) depth. Efficient routing is one of the most important jobs of a quantum transpiler.

Clifford classification. The SWAP gate is in the Clifford group: it maps Pauli operators to Pauli operators under conjugation (it simply exchanges the Pauli acting on qubit A with the one on qubit B). This means SWAP gates do not add non-Clifford overhead in fault-tolerant circuits.

Why it matters for learners

When you write a quantum circuit in Qiskit or Cirq, you can apply gates between any pair of qubits. But the transpiler must convert your logical circuit to the hardware’s physical connectivity, and SWAP insertion is where most of the additional depth comes from. Understanding SWAP gates helps you write hardware-aware circuits, interpret transpilation output, and appreciate why qubit connectivity is a key hardware specification.

Common misconceptions

Misconception 1: SWAP gates are free because they just relabel qubits. On real hardware, a SWAP requires three physical CNOT operations, each contributing gate errors. Heavy SWAP overhead can double or triple circuit depth.

Misconception 2: SWAP gates create entanglement. A SWAP acting on a product state produces a product state. It rearranges existing information but does not generate entanglement. However, the intermediate steps of its CNOT decomposition do create temporary entanglement.

See also