Sign in
← Atlas
Exact & formalGatesTwo-qubit gate

SWAP gate

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

routingtwo qubitconnectivity

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

SWAP belongs in a practical catalog because moving a state is often a compilation concern, not an algorithmic one.

Circuit & simulation
|01⟩ → |10⟩100%
What this takes and returns
Takes2 qubitsWhat joins here

Takes a 2-qubit register and states no assumption about what is on it. That is the whole condition: anything returning 2 qubits can feed it.

16 entries meet this end. Named below.

Returns2 qubitsWhat joins here

Returns a 2-qubit register a next stage can take. This is the end that joins.

11 entries meet this end. Named below.

A unitary. The same register goes in and comes out, and this entry states no assumption about what is on it — which is what lets anything of the same width feed it. See all 29 →

How it works

SWAP exchanges the states of two qubits: SWAPa,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=CX12CX21CX12\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.

Implementation
Native
swap.qasm
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
swap q[0], q[1];
Quantum vs classical

Classical baseline

Use a classical state-vector or matrix simulation at the same width, precision, and measurement objective.

Quantum claim

The quantum record demonstrates a state or operator behavior; it does not make classical simulation or communication costs disappear.

How to compare

Compare fidelity, samples, gate depth, noise, memory, and the cost of preparing and reading the state.

Declared gaps

Nobody has reviewed this record for gaps yet.

Literature & references
Quantum Computation and Quantum Information: 10th Anniversary Edition2010 · Michael A. Nielsen and Isaac L. Chuang

Standard graduate textbook covering the single- and two-qubit gate definitions, matrix identities, and circuit primitives this record states.

doi.org/10.1017/cbo9780511976667