Site Tools


swap-gate

SWAP gate

SWAP gate is a two-qubit gate that exchanges the states of its two qubits. It is symmetric โ€” neither qubit plays the role of control or target โ€” and it is its own inverse: $\text{SWAP}^2 = I$.

$$\text{SWAP} = \begin{pmatrix}1&0&0&0\\ 0&0&1&0\\ 0&1&0&0\\ 0&0&0&1\end{pmatrix}$$

$$\text{SWAP}\lvert 00\rangle = \lvert 00\rangle \qquad \text{SWAP}\lvert 01\rangle = \lvert 10\rangle \qquad \text{SWAP}\lvert 10\rangle = \lvert 01\rangle \qquad \text{SWAP}\lvert 11\rangle = \lvert 11\rangle$$

Decomposition into CX gates

SWAP can be decomposed into three CX gates in alternating directions:

$$\text{SWAP} = \text{CX}_{1\to 2}\cdot\text{CX}_{2\to 1}\cdot\text{CX}_{1\to 2}$$

This is important in hardware where qubit connectivity is limited. When two qubits that need to interact are not physically adjacent, SWAP gates are inserted to route them together โ€” at a cost of three CXs each. Minimizing SWAP overhead is a key concern in quantum circuit compilation.

Square root of SWAP

The $\sqrt{\text{SWAP}}$ gate satisfies $(\sqrt{\text{SWAP}})^2 = \text{SWAP}$. Unlike SWAP itself, $\sqrt{\text{SWAP}}$ can create entanglement, and together with arbitrary single-qubit gates it forms a universal gate set. It is native to several spin-qubit hardware architectures.

List of code implementations

swap-gate.txt ยท Last modified: by 127.0.0.1