• Fundamentals
  • Also: quantum compilation
  • Also: circuit compilation

Transpilation

The process of rewriting an abstract quantum circuit into an equivalent circuit that uses only the native gates and qubit connectivity of a specific hardware backend.

Transpilation is the process of transforming a quantum circuit written in terms of arbitrary gates into an equivalent circuit that respects the constraints of a specific hardware backend. These constraints include the native gate set (which gates the hardware can physically execute), the qubit connectivity (which pairs of qubits can interact directly), and timing or calibration data. The term is a blend of “translation” and “compilation,” borrowed from classical compiler terminology.

What transpilation does

A typical transpilation pipeline has several stages:

1. Gate decomposition: Every gate in the input circuit is decomposed into the backend’s native gates. For example, a Toffoli gate might be decomposed into six CNOT gates and several single-qubit rotations. A Hadamard gate on an IBM backend using the {X,Rz,CX}\{\sqrt{X}, R_z, \text{CX}\} native set becomes Rz(π/2)XRz(π/2)R_z(\pi/2) \cdot \sqrt{X} \cdot R_z(\pi/2).

2. Layout selection: The algorithm’s logical qubits are mapped to the physical qubits on the device. Good layout selection minimizes the number of SWAP gates needed later. This is typically done using heuristics or noise-aware scoring functions that account for qubit quality (error rates, T1T_1, T2T_2).

3. Routing: When a two-qubit gate requires qubits that are not physically adjacent, SWAP gates are inserted to move qubit states to neighboring positions. Each SWAP gate decomposes into three CNOT gates, so minimizing SWAP count is critical for keeping circuit depth low. This is a computationally hard optimization problem (related to token swapping on graphs).

4. Optimization: After routing, the transpiler applies peephole optimizations: canceling adjacent inverse gates, commuting gates to enable further cancellations, consolidating sequences of single-qubit gates into single rotations, and resynthesizing subcircuits.

Transpilation in Qiskit

Qiskit provides transpilation through qiskit.transpile() with optimization levels 0 through 3:

from qiskit import QuantumCircuit, transpile
from qiskit_ibm_runtime import QiskitRuntimeService

service = QiskitRuntimeService()
backend = service.backend("ibm_sherbrooke")

qc = QuantumCircuit(3)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)

transpiled = transpile(qc, backend=backend, optimization_level=3)
print(f"Original depth: {qc.depth()}, Transpiled depth: {transpiled.depth()}")

Optimization level 0 performs only the minimum required transformations (decomposition and routing). Level 3 applies aggressive optimization including resynthesis of two-qubit blocks and noise-aware layout selection.

Impact on circuit quality

Transpilation can dramatically change circuit properties. A 3-qubit QFT circuit with depth 7 in the abstract might become a circuit with depth 30 or more after transpilation for a device with limited connectivity. The number of two-qubit gates, the dominant source of error on most hardware, often increases by 2x to 10x depending on the circuit structure and device topology.

This makes transpilation quality a significant factor in the practical performance of quantum algorithms. The same logical circuit can produce very different results depending on how well it is transpiled.

Why it matters for learners

Every quantum circuit you write will be transpiled before execution on real hardware. Understanding transpilation helps you write circuits that are more hardware-friendly from the start, interpret the actual operations being performed on the device, and debug unexpected results. It also explains why qubit layout and native gate sets matter for algorithm design.

See also