Gates · Two-qubit gate
SWAP gate
A routing primitive that exchanges two qubit states and makes hardware connectivity explicit.
Exact & formalUpdated
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.
Step 1 of 2 · X
Probability of each outcome after this step
- 01100%
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.
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 belongs in a practical catalog because moving a state is often a compilation concern, not an algorithmic one.
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 →
SWAP exchanges the states of two qubits: for every computational basis input, exactly the check this record performs across all four inputs. As a matrix, in the basis, and . Algebraically SWAP decomposes into three CNOTs, , 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.
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 →
- Qubits
- 2
- Depth
- 1 native / 3 CX
- Outcomes
- states exchanged
- Native form
- SWAP
- Decomposition
- CX · CX · CX
- Role
- Routing
SWAPon 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.
Nobody has reviewed this record for gaps yet.
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
swap q[0], q[1];Related entries
- Controlled-X gate
Gates
- QFT resource screen
Algorithms
References
- Quantum Computation and Quantum Information: 10th Anniversary Edition
Michael A. Nielsen and Isaac L. Chuang · 2010
Standard graduate textbook covering the single- and two-qubit gate definitions, matrix identities, and circuit primitives this record states.