Logo UniNA Logo Quasar

Transpilation

1. Build your circuit
📚 Quantum states, qubits, and Dirac notation ▼

A quantum circuit is a sequence of operations, called gates, applied to qubits. To understand what you are building, it helps to first understand what a qubit is and what the notation in the editor means.

The qubit. Unlike a classical bit, which is either 0 or 1, a qubit can be in a superposition of both states at the same time. The state of a qubit is a vector in a two-dimensional complex space.

The |0⟩ and |1⟩ notation, called Dirac or bra-ket notation, identifies the two computational basis states of a qubit:

  • |0⟩ = ground state, analogous to the classical bit 0. Vector representation: (1, 0)ᵀ
  • |1⟩ = excited state, analogous to the classical bit 1. Vector representation: (0, 1)ᵀ

Generic state. A qubit can be in a superposition α|0⟩ + β|1⟩, where α and β are complex numbers satisfying |α|² + |β|² = 1. When you measure the qubit, the result is probabilistic:

  • you obtain 0 with probability |α|²
  • you obtain 1 with probability |β|²

Multiple qubits. With N qubits, the global state lives in a 2ᴺ-dimensional space. For example, with 3 qubits the basis states are |000⟩, |001⟩, |010⟩, …, |111⟩ (8 in total). States such as (|00⟩ + |11⟩)/√2 are entangled: the two qubits become correlated in a way that cannot be reproduced classically.

💡 Why do all qubits start from |0⟩? By convention, at the beginning of a quantum circuit each qubit is initialized in the ground state |0⟩. That is why the editor shows q_0: |0⟩, q_1: |0⟩, and so on. The gates you apply transform this initial state into something more interesting. For example, the H (Hadamard) gate transforms |0⟩ into (|0⟩ + |1⟩)/√2, a perfect superposition of 0 and 1.

What does transpilation have to do with this? Not all gates have the same cost on real hardware: 2-qubit gates (CX, SWAP) are the most expensive, and every SWAP is equivalent to 3 CX gates. Also, some 2-qubit gates may be impossible to execute directly because the physical qubits are not connected on the chip. Transpilation addresses exactly these issues: it adapts the ideal circuit to the constraints of the physical device.

Real quantum hardware constraints: Current quantum computers are constrained devices: not every physical qubit is directly connected to every other qubit, each device supports a specific set of native gates, and every operation is affected by noise. Errors arise from imperfect gates, interactions between qubits, and interactions with the surrounding environment, which cause decoherence.
Main transpilation goal: Transpilation adapts an ideal circuit to the selected hardware by respecting its connectivity and native gate set. It also tries to minimize the total number of gates and the circuit depth, especially the number of 2-qubit gates such as CX, because these operations are usually the slowest and most error-prone.
What do depth and CX depth mean? Circuit depth is the number of sequential operation layers: gates acting on independent qubits can run in parallel in the same layer, while gates sharing qubits must run in different layers. CX depth counts only the sequential layers of CX gates. Lower depth generally means a shorter execution time and less exposure to noise, while lower CX depth specifically reduces the impact of costly 2-qubit operations.
💡 Tip: To see the effect of routing, build a circuit with at least 2-3 CX gates between non-adjacent qubits (for example q[0]-q[2] with a "line" coupling map). You can also load an example from the 📋 Examples gallery.
🔧 Quantum gate guide ▼

Each gate transforms the state of one or more qubits. Below you will find a complete reference.

1-qubit gates: Pauli

Gate Description Matrix
I Identity. It does not change the state. Useful as a placeholder or to preserve timing alignment. [[1,0],[0,1]]
X Quantum NOT. Flips |0⟩ ↔ |1⟩. It is the quantum analogue of classical NOT. [[0,1],[1,0]]
Y Rotation by π around the Y axis of the Bloch sphere. It flips the state with a phase. [[0,-i],[i,0]]
Z Adds a π phase (minus sign) to |1⟩. Leaves |0⟩ unchanged. [[1,0],[0,-1]]

1-qubit gates: Hadamard and phase

Gate Description Matrix
H Hadamard. One of the most important gates: it creates superposition. |0⟩ → (|0⟩+|1⟩)/√2, |1⟩ → (|0⟩-|1⟩)/√2. 1/√2 [[1,1],[1,-1]]
S Adds a π/2 phase to |1⟩. Equivalent to √Z. This is a Clifford gate. [[1,0],[0,i]]
S† Inverse of S. Adds a -π/2 phase to |1⟩. [[1,0],[0,-i]]
T Adds a π/4 phase to |1⟩. A fundamental non-Clifford gate for universal quantum computation. [[1,0],[0,eiπ/4]]
T† Inverse of T. Adds a -π/4 phase to |1⟩. [[1,0],[0,e-iπ/4]]
SX √X. A half X rotation. Native gate on IBM hardware: the basis translator often uses it. 1/2 [[1+i,1-i],[1-i,1+i]]
SX† Inverse of SX. 1/2 [[1-i,1+i],[1+i,1-i]]

2-qubit gates

Gate Description
CX Controlled-NOT (CNOT). If the control is |1⟩, applies X to the target. It creates entanglement. It is the most common 2-qubit gate and is often the only native 2-qubit gate on hardware.
CY Controlled-Y. If the control is |1⟩, applies Y to the target.
CZ Controlled-Z. If the control is |1⟩, applies Z to the target. Unlike CX, it is symmetric: CZ(a,b) = CZ(b,a). Native on some platforms, such as superconducting transmons.
SWAP Swaps the states of two qubits. It is not usually native: it is decomposed into 3 CX gates. Routing inserts it automatically to move non-adjacent qubits closer together.
⚠️ Clifford vs non-Clifford: The H, S, and CX gates (and their combinations) form the Clifford group. Adding the T gate gives a universal set, able to approximate any quantum operation. The distinction matters: Clifford circuits can be simulated efficiently classically (Gottesman-Knill), while circuits with T gates generally cannot.

🔗 Learn more:


  • Drag 1-qubit gates onto the grid.
  • For 2-qubit gates: click 2Q gates, choose the gate, then click the two qubits (control → target for CX/CY/CZ).
  • You can move gates by dragging them. Click a gate to remove it.
I
H
X
Y
Z
S
S†
T
T†
SX
SX†
2Q gates
2. Connectivity constraints
🔗 Why is the coupling map important? ▼

In a real quantum processor, not all qubits are physically connected to each other. The coupling map describes which pairs of qubits can interact directly with 2-qubit gates such as CX.

For example, with a 3-qubit line topology, only pairs 0–1 and 1–2 are adjacent. A CX gate between q[0] and q[2] cannot be executed directly and will require intermediate SWAP gates.

💡 Think: If you choose ring instead of line, how many fewer SWAP gates do you expect? Why?
Coupling map preview
3. Layout stage
📐 Logical qubits vs physical qubits ▼

The layout stage decides which physical qubit corresponds to each logical qubit in your circuit. This assignment has a major impact on routing: if frequently interacting qubits are mapped to adjacent physical positions, routing will need to insert fewer SWAP gates.

TrivialLayout: maps q[0]→0, q[1]→1, … (no optimization).
DenseLayout: searches for the densest connected region of the coupling map.
SabreLayout: uses a routing-aware simulation to find a better initial mapping.

💡 Think: If your circuit has a CX between q[0] and q[2], what is the ideal layout for a 3-qubit line?
Docs: —
4. Routing stage
🗺️ How routing solves connectivity constraints ▼

After layout, each logical qubit has a physical position. However, some 2-qubit gates may still involve physical qubits that are not adjacent in the coupling map. The router solves this by inserting SWAP gates, which exchange the states of two adjacent qubits and bring the required qubits closer together.

BasicSwap: inserts SWAPs greedily, without lookahead: simple but often suboptimal.
LookaheadSwap: considers upcoming gates before choosing the best SWAP.
SabreSwap: uses a bidirectional heuristic and is usually the strongest of the three.

⚠️ Cost of SWAPs: Each SWAP gate = 3 CX gates. A circuit with 2 inserted SWAPs has 6 extra CX gates. Depth increases by at least 3 for each SWAP in a layer.
Docs: —
5. Translation stage
🔤 Translate into the hardware language ▼

Every gate in your circuit (H, S, T, CX...) must be expressed as a combination of native gates supported by the target hardware. The BasisTranslator uses an equivalence graph to find the correct decomposition.

For example, in the rz, sx, x, cx basis: H = RZ(π) · SX · RZ(π/2), e T = RZ(π/4).

💡 Note: Translation can significantly increase the size (the total number of gates), but it often does not increase depth if decompositions can run in parallel. Try it and compare.
Uses BasisTranslator (Qiskit docs).