A real quantum chip only connects each qubit to a handful of physical neighbours — the coupling graph. A logical circuit written by a programmer, however, calls two-qubit gates (e.g. CNOT) between arbitrary logical qubits, many of which never sit next to each other on the chip. A compiler's qubit-routing pass fixes this by inserting SWAP gates that physically shuttle logical states across the graph until the two operands become adjacent, then applies the real gate:
graph G = (physical qubits, coupling edges)
π : logical qubit → physical qubit (current mapping)
for each gate CNOT(a, b) in circuit:
u = π(a), v = π(b)
path = shortest_path(G, u, v) // breadth-first search
for each edge (path[i], path[i+1]) except the last:
SWAP π^-1(path[i]) ↔ π^-1(path[i+1]) // update π
apply CNOT on the now-adjacent pair
Each SWAP is itself compiled from 3 CNOTs (or ~3 native two-qubit gates), so every inserted SWAP adds real depth and real decoherence exposure. The routing overhead — SWAPs per original two-qubit gate — is exactly the metric quantum-development platforms such as Qiskit's transpiler or Cirq's routing passes try to minimise when they choose an initial mapping and a routing strategy for a given hardware coupling map.
- Grid size — the physical coupling graph; a square lattice, the simplified shape used by several real superconducting-qubit layouts.
- Circuit length — how many random two-qubit interactions the logical program requires.
- Step / Play — route one gate at a time, or auto-play the whole compiled circuit; node colours are logical qubits, so watch them drift across the physical grid as SWAPs accumulate.
- Reset Mapping — restore the identity mapping (physical i ↔ logical i) and replay the same circuit from gate 1.