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.
- Coupling graph shape — swap the physical connectivity between a square grid (several real superconducting layouts), a ring, and a bare line, at the same qubit count, and watch the average path length — and therefore SWAP overhead — change with it: a line has the worst average distance, a grid the best.
- Grid size — sets the qubit count (N×N physical qubits, laid out as a grid/ring/line depending on the shape above).
- 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 layout as SWAPs accumulate.
- Reset Mapping — restore the identity mapping (physical i ↔ logical i) and replay the same circuit from gate 1.
- Drag to pan, scroll to zoom the graph view.