Skip to content
Current section
The Quantum Computing Enthusiast’s Hub
Saved
All sections

All sections

Saved
Skip Learn navigation
Encyclopedia
Topic

SWAP gate and routing

A unitary exchange of two quantum subsystem states, often used to satisfy hardware connectivity constraints.

Also called quantum state swap

Edition released Coverage: Overview · Technical
On this page

Definition and significance

SWAP exchanges the states of two labeled subsystems. It does not copy them, inspect them or necessarily move physical particles. On |a,b> it gives |b,a>; by linearity it also exchanges parts of an entangled state. In circuit compilation, SWAP can move logical information among physical locations so that later interactions meet a device's connectivity constraints.

Mechanism and mathematical treatment

For two qubits, SWAP=CX12 CX21 CX12, where the rightmost factor acts first and the first written chronological gate is also CX12. To see the identity on bits, (a,b) becomes (a,a XOR b), then (b,a XOR b), then (b,a). Linearity extends this basis proof to every two-qubit state.

SWAP=(I tensor I+X tensor X+Y tensor Y+Z tensor Z)/2. A routing permutation changes which physical register represents a logical register. Final output interpretation must account for that permutation. Counting a SWAP as three CNOTs is appropriate for this decomposition, not a universal hardware cost.

Fully worked reference example

Consider three sites in a line A-B-C, initially holding logical states |a>,|b>,|c>. A desired CNOT from logical A to logical C is not directly adjacent. SWAP B and C gives physical contents a,c,b. A CNOT between physical A and B now implements the desired logical interaction. Swapping B and C back restores the original mapping. This construction adds six CNOTs if each SWAP uses three, plus the desired one.

If no later operation requires the original mapping, the final SWAP can be omitted and the output labels remapped. The result has the same logical meaning with a different final permutation. It is therefore misleading to compare routed circuits without saying whether output relabeling is permitted.

Limitations and common misconceptions

A SWAP network trades interactions and movement against depth; fewer gates need not imply a shorter schedule. Physical shuttling, teleportation-based movement and native exchange interactions have different costs. A compiler's graph model can omit crosstalk or simultaneous-operation limits, so a legal routing graph is not a complete noise model.

Scientific relationships

Three appropriately oriented controlled-X gates implement SWAP.

Routing is a compilation transformation subject to target connectivity.

Fermionic exchange includes a sign on the doubly occupied basis state.

An adjacent-swap network with a complete mapping table

Place four logical registers A,B,C,D at physical sites 0,1,2,3 on a line. Apply swaps in three chronological layers: first swap sites (0,1) and (2,3) simultaneously; then swap (1,2); then again swap (0,1) and (2,3) simultaneously. The mappings are initially [A,B,C,D], then [B,A,D,C], then [B,D,A,C], and finally [D,B,C,A]. This exchanges the endpoint logical states and restores the two interior logical states.

There are five adjacent SWAP gates, but only three SWAP layers. If each SWAP is decomposed into three CNOTs and operations on disjoint pairs can run together, this construction has fifteen CNOTs and nine CNOT layers under the straightforward decomposition. These counts assume that both CNOT directions are available with the same primitive cost. Reversing a direction through basis changes can increase the actual gate ledger.

The five-swap count is minimal for this exact endpoint transposition on a line when adjacent swaps are the permitted moves. A permutation's inversion count changes by exactly one under an adjacent swap. The target order [D,B,C,A], represented as [3,1,2,0], has five inversions: D precedes three smaller labels, B precedes A, and C precedes A. Therefore at least five swaps are necessary, and the displayed network reaches that lower bound. Minimal swap count does not establish minimal elapsed time on a calibrated device.

Routing an interaction and retaining the final permutation

Suppose the desired logical operation is a gate G on A and D, with no requirement to restore positions afterward. Start from [A,B,C,D]. Swapping sites (0,1) and (2,3) produces [B,A,D,C], placing A and D next to one another at sites 1 and 2. Apply G there. The final mapping remains [B,A,D,C]. This costs two SWAPs rather than the five needed for an endpoint transposition, because the computational task is different.

If later measurement results are stored by physical site, the logical result for A comes from site 1, B from site 0, C from site 3 and D from site 2. This relabeling is free only in the sense that it requires no additional quantum gates; its classical bookkeeping must still be correct. A later gate on logical A and B must use the current mapping, not the initial one. Treating the mapping as a maintained permutation makes that requirement explicit.

A compiler can represent a route as a sequence of updates to two inverse tables: logical_to_physical and physical_to_logical. For a swap at physical p and q, first read the logical labels u and v located there, then exchange both table entries consistently. Updating only one table creates stale information that may produce a superficially legal but logically incorrect circuit. A small reference trace listing both tables after every swap is often more informative than a final gate count.

Entangled inputs and the operational meaning of exchange

Let A be entangled with an external reference R in (|00>+|11>)/sqrt(2), while B starts in |0>. Applying SWAP to A and B moves the correlation: the final joint state is |0>_A tensor (|00>+|11>)_(B,R)/sqrt(2), with register ordering stated explicitly. The reference never participates in a gate. The example verifies that SWAP transports an unknown subsystem state, including its external entanglement, rather than merely exchanging known classical bit values.

The identity SWAP=(I+XX+YY+ZZ)/2 also reveals its spectral structure. The three symmetric two-qubit Bell states have eigenvalue +1, while the antisymmetric singlet has eigenvalue -1. Therefore exp(-i theta SWAP)=cos(theta)I-i sin(theta)SWAP. At theta=pi/2 the result is -i SWAP, whereas at theta=pi/4 it is a partial exchange. A native interaction proportional to exchange can consequently realize a SWAP up to phase, but the gate time and any additional Hamiltonian terms must be established for the device.

For |01>, the partial exchange at theta=pi/4 produces (|01>-i|10>)/sqrt(2), an entangled state. This is different from a classical randomized choice between doing nothing and swapping, which produces an incoherent mixture. The two procedures have the same computational populations in this case but different off-diagonal matrix entries. Interference measurements distinguish them.

Sources

  • A. Barenco et al. · · Research paper · Publication status unspecified · arXiv · DOI 10.1103/PhysRevA.52.3457
    Verification scope

    Selected source text checked ·

    Source anchors gate-decomposition conventions. New worked instances are independent mathematical constructions, not reported experiments.