Transpilation converts your abstract quantum circuit into a concrete circuit that runs on a specific backend. Each backend has constraints: a gate set (only certain gates are native), qubit connectivity (which pairs can interact directly), and calibration data. Transpilation rewrites your circuit to respect these constraints while preserving the computation.
Think of transpilation like compiling source code to machine code: the abstract algorithm is the same, but the target-specific details differ.
from qiskit import transpile, QuantumCircuit from qiskit_aer import AerSimulator qc = QuantumCircuit(3, 3) qc.h([0, 1, 2]) qc.cx(0, 1) qc.cx(1, 2) qc.measure([0, 1, 2], [0, 1, 2]) backend = AerSimulator() transpiled = transpile(qc, backend, optimization_level=2) print(transpiled.draw())
Higher levels produce shallower circuits at the cost of transpilation time. For variational algorithms, level 2 is usually a good balance.
When targeting real hardware, transpilation accounts for measured error rates and gate times. Transpilers try to minimize two-qubit gates (the primary error source) and circuit depth (time qubits spend in superposition, where they decohere).