QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
05 · Topology and SWAP cost0%

You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.

Learn/QC 203Hardware and Compilation·Lesson 5 of 6

Topology and SWAP cost

Coupling maps, the heavy-hex lattice, and how to lay out a circuit so the router adds nothing.

Intermediate10 min read4 sections · 2 questions+45
By the end you will be able to
  1. 01Read a coupling map and find the shortest path between two qubits.
  2. 02Predict how many SWAPs a non-adjacent CNOT costs.
  3. 03Explain why IBM uses heavy-hex instead of a square grid.

A superconducting chip can only apply two-qubit gates between physically coupled pairs. The coupling map is that graph. A CNOT between qubits three hops apart needs two SWAPs to bring them together (six two-qubit gates) plus the CNOT itself. IBM's heavy-hex lattice has degree 2 and 3 only: fewer neighbours than a square grid, chosen to reduce crosstalk and frequency collisions at the price of more routing.

fake_manilafake_manila: five qubits in a line. Any gate between qubit 0 and qubit 4 costs three SWAPs unless the layout stage moves the logical qubits closer.
Hands-on

Make the router work

Qubit 0 talks to all three others. fake_manila's qubits sit on a line, where no qubit has three neighbours, so the router must add a SWAP. Compile for fake_manila and count the two-qubit gates: 6 CNOTs instead of the circuit's 3 (one SWAP costs 3 CNOTs). Then compile for fake_kyiv: its heavy-hex lattice has qubits with three neighbours, so 3 two-qubit gates are enough.

OpenQASM 3
OPENQASM 3.0;
include "stdgates.inc";
qubit[4] q;
bit[4] c;
h q[0];
cx q[0], q[1];
cx q[0], q[2];
cx q[0], q[3];
c = measure q;
Sign in to run (nothing is saved)
Open in the IDE Open in the Playground
Knowledge check

2 questions · one try each counts

Question 1

On a line of qubits 0–1–2–3, a CNOT between 0 and 3 needs at least…

Sign in to answer and climb the ranks; you will come back to this lesson.

Question 2

Why might a chip deliberately give each qubit fewer neighbours?

Sign in to answer and climb the ranks; you will come back to this lesson.

Key takeaway

Two-qubit gates only run between coupled qubits; every missing edge costs SWAPs. Check the topology map, let the layout stage pick good qubits, and count SWAPs in Metrics.

Finished reading?

Knowledge check: 2 questions waiting above. Questions are optional. Mark it complete, or press Next: moving on marks it complete too.

Up next
Lesson 6 · 10 min
Running on IBM Quantum
Token, instance, queue, minutes: a checklist for a first real-hardware job and how to read the result.
Further reading
  • Docs: topology and heavy-hex
More in Hardware and Compilation
  • From an abstract qubit to a device
  • Classical Compiler vs. Quantum Transpiler
  • Transpilation and basis gates
Circuit Identities & Gate CancellationRunning on IBM Quantum
In this lesson0%
  1. Introduction
  2. Try it: Make the router work
  3. Knowledge check
  4. Key takeaway
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in