QuantumAtlas

Gates & Circuits

SWAP Gate

A two-qubit gate that exchanges the states of two qubits; the tool for moving information around a chip.

Definition

The SWAP gate swaps the states of two qubits: whatever was on the first qubit ends up on the second, and vice versa. It does not create anything new, but it is vital in practice because most quantum chips can only run two-qubit gates between neighboring qubits. When an algorithm wants two distant qubits to interact, the compiler inserts SWAP gates to bring them next to each other, and those extra gates add time and errors.

In depth

Connectivity limits explain why SWAP matters. On a superconducting chip, each qubit is wired to only two to four neighbors, so a circuit that needs a gate between qubits far apart must route them together. The compiler step called routing inserts SWAP gates, and each SWAP costs three CNOT gates, so a routing overhead can multiply the number of two-qubit gates, which are the main source of errors. Trapped-ion machines with all-to-all connectivity and neutral-atom machines that can move atoms avoid much of this overhead.

A related use of SWAP is the SWAP test, a circuit that estimates the overlap between two states by applying a controlled swap. This is a different gate, called the Fredkin gate, which swaps two qubits only if a control qubit is 1. The SWAP test is used in quantum machine learning for computing kernels and in fingerprinting protocols.

Hardware vendors sometimes implement a native swap-like gate. The iSWAP gate on superconducting hardware, and the exchange interaction in spin qubits, produce swapping dynamics directly, and some architectures treat SWAP as cheap. Layout design, such as heavy-hex lattices and square grids, is chosen in part to reduce the average SWAP overhead for common algorithms.

Technical Definition

The SWAP gate is the 4 by 4 permutation matrix that exchanges the basis states 01 and 10 and leaves 00 and 11 unchanged. It can be built from three CNOT gates, with alternating control and target. The related iSWAP gate adds a phase of i to the swapped states and is native on some superconducting hardware.

Visual Explanation: An Analogy

Think of two people in a queue swapping places. Nothing about either person changes, only where they stand. When the queue is a line of qubits on a chip and you need two people far apart to talk, you have to move them next to each other by a chain of swaps.

Key facts

ItemDetail
Matrix actionExchanges basis states 01 and 10
DecompositionThree CNOT gates
Main useRouting qubits on chips with limited connectivity
VariantiSWAP adds a phase i and is native on some superconducting chips; the Fredkin gate is a controlled swap
CostEach SWAP adds three two-qubit gates and extra error

Where the idea comes from

The SWAP operation is basic to any theory of computation with registers, and its decomposition into CNOT gates appeared in the early circuit-model literature of the mid-1990s. Routing and SWAP minimization became a central compiler problem as superconducting devices with fixed layouts appeared in the 2010s.

Real-World Use Cases

  • Qubit routing in compilers for devices with limited connectivity.
  • The SWAP test for state comparison and kernel estimation.
  • Reordering qubits at the end of the quantum Fourier transform.
  • Moving quantum information between memory and processing zones in modular designs.

How it differs from related ideas

  • SWAP exchanges the quantum states of two qubits, while a physical movement of atoms or ions transports the qubits themselves.
  • The Fredkin gate is a controlled swap, and the plain SWAP has no control.
  • Teleportation can move a state across a distance using entanglement, while SWAP requires adjacent qubits.

Common Misconceptions

  • SWAP does not copy a state. It exchanges two states, so the no-cloning theorem is not violated.
  • A SWAP is not free on most hardware. It costs about three entangling gates.
  • Better connectivity does not remove the need for SWAP entirely, but it reduces it.

Frequently asked questions

Why do compilers insert SWAP gates?

Because two-qubit gates can only be run between connected qubits, and SWAPs move states next to each other so that a gate can be applied.

How many CNOTs make a SWAP?

Three CNOT gates, with the control and target alternating.

What is the difference between SWAP and iSWAP?

iSWAP adds a phase of i to the exchanged states. It is a native interaction on some superconducting chips.

Related Terms

Keep exploring

← Back to the dictionary