QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
  1. Docs
  2. Compile (transpile): levels, basis gates, topology
Learn
  • Quantum basics
  • OpenQASM 3 cheat sheet
  • All gates, with the math
  • Every gate, interactive
  • Entanglement: how CNOT connects qubits
Circuits
  • Dynamic circuits: if/else, loops and conditions
Lessons
  • Learning path: from one qubit to algorithms
  • Quantum machine learning by hand
Run
  • Compile (transpile): levels, basis gates, topology
  • Simulators, noise, T1/T2 and fake backends
  • Python in the Playground
  • GitHub and git in the Playground
  • Articles and sharing
Analyze
  • Metrics: comparing distributions
  • Q-sphere and Bloch spheres
Hardware
  • Real IBM Quantum hardware
  • Device topology and calibration heat maps
  • Benchmark circuits: MQT Bench and QASMBench
Advanced
  • Circuit cutting, in depth
Story
  • The story of quantum computing
  • The Hamiltonian: where gates come from
  • What to expect next
Documentation/Run/Compile (transpile): levels, basis gates, topology

Compile (transpile): levels, basis gates, topology

A real device cannot run arbitrary gates on arbitrary qubit pairs. Transpiling rewrites your circuit into the device's native gates (basis) and its qubit connectivity (coupling map), then optimizes it.

Transpiler stages

The Qiskit preset pass manager runs these stages: init → layout → routing → translation → optimization → scheduling.

StageWhat it does
LayoutChooses which physical qubit holds each logical qubit. Good layouts put interacting qubits next to each other and prefer qubits with low error and long T1/T2.
RoutingInserts SWAP gates so every two-qubit gate acts on neighbouring physical qubits. Each SWAP costs three CNOTs.
TranslationRewrites gates into the basis set, e.g. H → RZ(π/2)·√X·RZ(π/2).
OptimizationCancels inverse pairs, merges single-qubit rotations, removes gates that commute to the end, re-synthesizes blocks.
H=eiπ/2RZ​(2π​)X​RZ​(2π​)
Example translation into the IBM basis {RZ, √X, X, CX/ECR}. RZ is free, so only the √X counts as a physical pulse.

Optimization levels 0–3

LevelMeaningWhen
0No optimization. Trivial layout (logical i → physical i), basic routing, plain translation.Debugging; seeing the raw cost of your circuit.
1Light: inverse-gate cancellation and 1-qubit gate merging. Qiskit's default.Fast everyday compiling.
2Medium: smarter layout (VF2 + SABRE), commutation analysis, more cancellation.Good trade-off for hardware runs.
3Heavy: everything in 2 plus unitary re-synthesis of 2-qubit blocks and many SABRE trials.Slowest, usually the smallest circuit. Use before spending IBM minutes.

Topology and SWAPs

Topology (coupling map). IBM Eagle (127 qubits) and Heron (133–156 qubits) processors use a heavy-hex lattice: every qubit has 2 or 3 neighbours. A 4-qubit GHZ chain fits on a line, but a 4-qubit all-to-all circuit needs SWAPs. The Levels tab shows layout, physical qubits and the SWAP count for each level.

Depth is the number of time steps when gates on different qubits run in parallel; it is the main driver of decoherence error (see T1/T2 below). Two-qubit gate count is the main driver of gate error. Smaller is better for both.

In QubitLab, Compile (in the bar above the circuit) transpiles once for your target and shows the mapped circuit, the exact statevector and an explanation. The Levels tab (Submit with 'Compare levels') runs all four levels as a job and charts them.

← Previous
Quantum machine learning by hand
Next →
Simulators, noise, T1/T2 and fake backends
On this page
  • Transpiler stages
  • Optimization levels 0–3
  • Topology and SWAPs
Try it in the IDE →
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in