Quantum transpilation converts a hardware-independent circuit into instructions a specific quantum device can execute. This guide explains what changes during that process, how to estimate circuit cost, and how to compare depth, two-qubit operations, connectivity overhead, and optimization settings before you run a job.
Overview
A quantum algorithm is usually written in logical terms: apply a Hadamard gate, perform a controlled operation, measure a register, and so on. A real processor cannot necessarily execute every logical gate directly. It has a limited native gate set, a fixed arrangement of connected qubits, and hardware-specific timing and calibration constraints.
Transpilation is the compiler stage that bridges those two representations. It may decompose a logical gate into native gates, map virtual qubits to physical qubits, insert routing operations when qubits are not adjacent, cancel or combine compatible gates, and schedule instructions for a target backend. The result is still a quantum circuit, but it is expressed in a form that the selected simulator or hardware can accept.
This transformation can improve or worsen practical performance depending on the target and the compiler settings. A circuit with fewer logical gates may require many additional operations after mapping. In particular, limited connectivity can make a two-qubit interaction expensive because the compiler must move quantum information or use an equivalent decomposition.
For that reason, the original circuit is not a reliable estimate of execution cost. Compare the circuit before and after transpilation, and record the target backend, compiler settings, and metrics used. A reproducible experiment template can help preserve those details; see our guide to reproducible quantum experiments.
| Metric | What it tells you | Why it matters |
|---|---|---|
| Logical gate count | Operations in the algorithm as written | Useful for understanding algorithm structure, but not hardware cost |
| Transpiled gate count | Operations after decomposition and optimization | Reveals compiler overhead |
| Depth | Longest sequence of dependent circuit layers | Relates to exposure to decoherence and execution time |
| Two-qubit operations | Entangling gates after mapping | Often a key contributor to noise and routing cost |
| Connectivity overhead | Extra work caused by the coupling map | Shows how much the hardware layout affects the circuit |
How to estimate
Use a repeatable comparison rather than relying on a single optimization number. The following workflow works for a Qiskit-based project and can be adapted to Cirq, Braket, or PennyLane.
- Build a baseline. Save the original circuit and measure its number of qubits, depth, total operations, and two-qubit operations. This is your logical reference.
- Select the actual target. Transpilation depends on the backend. A simulator with unrestricted connectivity and a hardware backend with a coupling map can produce very different circuits.
- Choose an optimization level. Treat the setting as an experiment variable, not a universal quality score. Lower settings may compile quickly and preserve structure; higher settings may spend more compiler effort to reduce redundant operations.
- Transpile and inspect. Record the output depth, total operation count, two-qubit count, and any routing gates. In Qiskit, a typical pattern is
transpile(circuit, backend, optimization_level=...); exact options can vary by SDK release and backend. - Repeat under controlled conditions. Compare the same circuit, target, qubit count, layout constraints, and optimization settings. If you change several variables at once, you cannot tell which change produced the result.
- Validate behavior. Optimization should preserve the circuit's intended unitary or measured result within the assumptions of your test. Compare an ideal simulator result before treating a lower gate count as an improvement.
A useful cost summary is:
cost profile = (depth, total gates, two-qubit gates, routing gates, measurements)
Do not reduce this profile to one metric. A circuit with slightly greater depth but substantially fewer entangling operations may be preferable on one backend, while a different device may favor a layout with lower depth.
Inputs and assumptions
Your estimate is only as meaningful as the inputs you preserve. At minimum, record the following:
- Logical circuit: Include qubit count, gate sequence, measurements, and any classical control.
- Target instruction set: Native gates differ by backend. A compiler may decompose a controlled operation into several one- and two-qubit instructions.
- Connectivity: Note whether every pair of qubits can interact or whether the device uses a restricted coupling map.
- Initial layout: The assignment of logical qubits to physical qubits can change routing overhead. A layout that matches the algorithm's interaction pattern may reduce added operations.
- Optimization level and pass configuration: Save these with the result. Compiler defaults and supported passes can change between SDK releases.
- Metric definitions: State whether “two-qubit gates” includes all entangling instructions and whether depth is measured before or after scheduling.
- Noise and calibration context: Gate counts do not directly predict success probability. Use backend calibration data and error-mitigation methods when assessing real hardware. The backend selection guide covers the additional measurements worth comparing.
Native gates are not interchangeable from an engineering perspective. A compiler may find two mathematically equivalent decompositions with different depths or entangling-gate counts. Similarly, routing operations are not merely cosmetic: they add execution time and more opportunities for error.
Worked examples
Example 1: A logical circuit with unrestricted connectivity
Suppose a four-qubit circuit contains 20 logical gates, including four two-qubit interactions. On an ideal simulator that supports the circuit's gate set and unrestricted connectivity, transpilation may mainly perform decomposition and local simplification. If the output has 18 gates and the same four interactions, the compiler removed redundancy without adding routing overhead.
The useful conclusion is not that “optimization level X is best.” It is that this circuit has low mapping overhead for that target. Preserve the target and settings alongside the result before comparing it with another backend.
Example 2: The same circuit on restricted hardware
Now assume two of the required interactions involve nonadjacent physical qubits. The compiler must insert routing operations or choose a different layout. The output could contain more total gates, greater depth, and additional two-qubit operations even though the logical circuit has not changed.
Compare the results in a small table:
| Version | Depth | Total gates | Two-qubit gates | Interpretation |
|---|---|---|---|---|
| Logical circuit | Baseline | 20 | 4 | Algorithm-level cost |
| Mapped target A | Higher or lower | Compiler output | Compiler output | Check decomposition and routing |
| Mapped target B | Higher or lower | Compiler output | Compiler output | Check whether layout matches interactions |
Use measured output rather than filling these fields with estimates. If target B has lower depth but more two-qubit operations, test both on an ideal simulator and then consider calibration data. For circuits dominated by entangling gates, gate fidelity may matter more than a small reduction in single-qubit depth. Randomized benchmarking can provide useful context for hardware comparisons; see this guide to randomized benchmarking.
Example 3: Comparing optimization settings
Run the same circuit at several supported optimization settings and capture a row for each run. Look for stable patterns: Does depth fall while two-qubit count rises? Does a higher setting produce the same circuit repeatedly? Does a custom initial layout remove routing? These observations are more actionable than selecting the highest setting by default.
When to recalculate
Recalculate transpilation metrics whenever the execution target or compilation environment changes. A new backend revision, altered coupling map, native gate set, calibration profile, SDK release, or compiler pass can change the output even when your source circuit is identical.
Revisit the estimate before a hardware run, after changing qubit layout, and whenever you replace a logical subroutine. This is especially important for circuits containing many controlled operations, a quantum Fourier transform, or repeated entangling layers. For additional context on decomposing Fourier-transform circuits, read the QFT tutorial.
Make the process operational: store the source circuit, target identifier, SDK version, optimization settings, layout, transpiled circuit, and metric summary in the same experiment record. Then compare candidates using at least depth, total gates, and two-qubit gates rather than a single score. Finally, pair the transpilation report with backend calibration and, where appropriate, error mitigation. That habit turns transpilation from an invisible compiler step into a measurable part of quantum programming.