← Atlas

Gates · Two-qubit gate

SWAP gate

A routing primitive that exchanges two qubit states and makes hardware connectivity explicit.

Exact & formalUpdated

View frozen graph

A small worked example, computed in your browser. It is not a result from this record's papers.

SWAP exchanges two qubits

Two qubits, with qubit 0 set to |1⟩ and qubit 1 left at |0⟩, so there is something to exchange.

q0q1Step 1 of 2 · XXStep 2 of 2 · SWAPSWAP

Step 1 of 2 · X

Probability of each outcome after this step

  • 01100%
  1. Sets qubit 0 to |1⟩. Read the outcome right to left: character 0 of the bitstring is the highest-numbered qubit, so this reads 01.

    The whole state moves from 00 to 01 — one certain outcome before, one certain outcome after, no superposition either side.

  2. Exchanges the two qubits entirely. On hardware this is rarely a gate of its own — it is three CXs, and moving a qubit across a chip is the main cost a router is trying to avoid.

    The whole state moves from 01 to 10 — one certain outcome before, one certain outcome after, no superposition either side.

Readout The register reads 10: what qubit 0 held is now on qubit 1. Nothing is in superposition on either side of this gate, which is exactly why the whole state simply moves from one outcome to another.

Open in Studio
  • Steps1
  • Wires2
  • Qubits2
  • Depth1 native / 3 CX
  • Outcomesstates exchanged
  • Papers1

SWAP exchanges the states of two qubits: SWAP∣a,b⟩=∣b,a⟩\mathrm{SWAP}|a,b\rangle=|b,a\rangle for every computational basis input, exactly the check this record performs across all four inputs. As a matrix, SWAP=(1000001001000001)\mathrm{SWAP}=\begin{pmatrix}1&0&0&0\\0&0&1&0\\0&1&0&0\\0&0&0&1\end{pmatrix} in the {∣00⟩,∣01⟩,∣10⟩,∣11⟩}\{|00\rangle,|01\rangle,|10\rangle,|11\rangle\} basis, and SWAP2=I\mathrm{SWAP}^2=I. Algebraically SWAP decomposes into three CNOTs, SWAP=CX12 CX21 CX12\mathrm{SWAP}=\mathrm{CX}_{12}\,\mathrm{CX}_{21}\,\mathrm{CX}_{12}, which is what a compiler emits when SWAP is not a native two-qubit interaction. SWAP does not create or destroy entanglement between the qubits it moves; it relocates existing correlations to different wires. In practice SWAP is a routing/connectivity primitive: transpilers insert it to move a logical qubit's state across a hardware coupling graph so a two-qubit gate can be applied between qubits that are not physically adjacent, at the cost of extra circuit depth.

References

Exact & formal
  • Basis-state truth table
  • Textbook / standard citation
Method
Apply SWAP to all four computational-basis inputs and compare output labels.
Result
Pass · q[0] and q[1] exchange states without changing amplitudes.
OpenQASM 3 standard gate set ↗
Kind
curated reference
Reviewed by
Leona Quantum curation pass
License
CC BY 4.0-compatible reference metadata
routingtwo qubitconnectivity

Atlas stars stay in the public catalog. Saving this entry to your workspace starts an unstarred private copy.