Quantum circuit transpilation converts an abstract circuit into a form that a simulator or quantum processor can execute. This guide explains the main compiler decisions—gate-set conversion, qubit mapping, routing, depth reduction, and measurement preservation—and provides a repeatable workflow for comparing transpilation settings as SDKs and backend constraints change.
Overview
A circuit written in a high-level quantum SDK is rarely ready to run unchanged on a target backend. The circuit may use gates that the device does not support directly, assume connections between qubits that the hardware does not provide, or contain operations that can be simplified before execution. A transpiler, also called a quantum compiler in some contexts, transforms the circuit while aiming to preserve its intended behavior.
Transpilation is therefore more than a format conversion. It is a constrained optimization problem. The compiler must balance hardware compatibility with circuit quality. A transformation that reduces the number of gates may increase circuit depth. A qubit layout that minimizes one set of routing operations may perform poorly for another workload. An aggressive optimization pass may also make debugging or comparing results more difficult.
The output should be evaluated against the target backend, not judged only by how short the source code looks. For a simulator, the important constraints may be the supported gate set, precision, memory, and execution model. For hardware, connectivity, native operations, calibration data, available qubits, timing, and noise all influence whether a transpiled circuit is useful.
What to track
When comparing quantum programming tools or compiler configurations, record the same variables for every run. A small circuit report makes changes easier to explain and helps prevent a backend migration from becoming an informal rewrite.
Gate-set conversion
First, identify which operations appear in the input circuit and which operations the target supports natively or through its execution interface. Unsupported gates must be decomposed into an accepted basis. Track the total operation count and, where the SDK exposes it, the count by gate type. A decomposition that adds many two-qubit operations may be more consequential than one that adds several single-qubit operations.
Qubit mapping and routing
Logical qubits represent the algorithm; physical qubits represent locations on the target device. Mapping assigns logical qubits to physical ones. If two logical qubits need an interaction but their assigned physical qubits are not connected, the transpiler inserts routing operations, often swaps or equivalent sequences.
Record the initial layout or mapping method, the number of routing operations, and whether the mapping was fixed or selected automatically. Mapping can change the result substantially even when the source circuit and optimization level remain the same.
Circuit depth and operation counts
Depth measures the number of sequential layers in a circuit under the compiler's scheduling or layering rules. It is not interchangeable with total gate count. Two circuits can contain the same number of operations but have different depths, and a lower-depth circuit is not automatically better if it uses more expensive operations.
Track at least:
- Overall circuit depth before and after transpilation.
- Total operations and counts for one- and two-qubit gates.
- Number of inserted routing operations.
- Number and placement of measurements.
- Any barriers, delays, resets, controls, or timing instructions added or removed.
Optimization passes and settings
Transpilers commonly apply passes for local gate cancellation, algebraic simplification, commutation-based reordering, layout selection, routing, and scheduling. SDKs may expose these as named passes, preset levels, compiler stages, or configuration options. Save the exact SDK version, compiler settings, target definition, and random seed when one is available.
Do not compare an unnamed default run with a carefully configured run and attribute every difference to the optimization algorithm. Defaults can change as SDKs evolve, and a backend description may also change without altering the source circuit.
Measurement preservation
Measurements are part of the experiment's interface, not merely another operation to optimize. Confirm that the transpiled circuit measures the intended logical qubits, writes results to the expected classical registers or result fields, and preserves any required ordering. Also check whether resets, mid-circuit measurements, conditional operations, or control flow have special backend requirements.
| Area | Question to ask | Useful comparison fields |
|---|---|---|
| Gate-set conversion | Can the target execute every operation? | Supported basis, decomposition, operation counts |
| Qubit mapping | Which logical qubit occupies each physical qubit? | Initial layout, final layout, mapping method |
| Routing | How are non-adjacent interactions implemented? | Inserted swaps, routing count, connectivity violations |
| Circuit depth | How much sequential work remains? | Input depth, output depth, two-qubit depth |
| Optimization passes | Which transformations were enabled? | Pass list, optimization level, seed, SDK version |
| Measurements | Does the output still represent the intended experiment? | Measured qubits, classical destinations, ordering |
Cadence and checkpoints
Transpilation results are worth checking whenever the execution context changes. A practical cadence is to perform a light review monthly or quarterly for active projects, then run a full comparison before an important experiment, release, or backend migration.
At project setup
Choose a small representative circuit set rather than testing only a trivial example. Include the shallow smoke test, the largest expected circuit, and at least one circuit with the interaction pattern that matters to the algorithm. Save the source circuits, target description, compiler configuration, and resulting metrics.
After an SDK or backend change
Rerun the same circuits when upgrading an SDK, changing compiler defaults, switching simulator modes, or selecting a different backend. Compare structural output first: gate counts, depth, routing, layout, and measurements. Then compare execution results using a fixed test setup where practical.
Before hardware execution
Review the backend's current constraints and calibration information rather than relying on an older compiled circuit. A device's useful qubit subset, connectivity assumptions, or operation characteristics may differ from the environment used during development. The guide to reading quantum backend calibration data can help organize this review.
After optimization changes
Change one major compiler variable at a time when diagnosing behavior. For example, compare two layout methods while holding the gate decomposition and optimization settings constant. Keep a record of the result in the project documentation so later improvements are not mistaken for unexplained variation. The quantum computing project documentation template provides a useful structure for this record.
How to interpret changes
A lower gate count is helpful only when the removed operations were relevant to the execution cost. Pay particular attention to two-qubit operations, routing overhead, and depth in the portions of the circuit most exposed to errors or timing limits. A modest increase in single-qubit operations may be acceptable if it eliminates several routing operations, but that conclusion should be tested rather than assumed.
If depth increases while gate count falls, inspect whether the compiler has serialized operations that were previously parallel. If gate count increases but measured results remain stable in simulation, determine whether the change is a harmless decomposition or a sign that the target constraints are forcing a less suitable representation. If results change unexpectedly, check qubit ordering, classical-bit ordering, measurement placement, reset behavior, and parameter binding before blaming optimization.
Use a fixed benchmark set for comparisons. The quantum circuit benchmarking guide can support repeatable runs, while the comparison of quantum circuit testing tools covers ways to place structural and behavioral checks in a development workflow.
Finally, separate compiler quality from backend quality. A well-mapped circuit can still produce poor hardware results because of noise or calibration conditions. Conversely, a circuit with more operations may be the correct output for a target whose native instruction set makes those operations efficient. Transpilation metrics explain the circuit; they do not replace execution testing.
When to revisit
Revisit this guide and your transpilation report whenever you switch quantum SDKs, compare alternatives, move between simulator and hardware, change the target backend, or alter optimization settings. A quarterly review is sensible for an active codebase even when no migration is planned, because compiler defaults, backend descriptions, and supported instructions can change over time.
For the next review, take one representative circuit and complete this short checklist:
- Record the source circuit, SDK version, target, compiler settings, and seed.
- Capture gate counts, two-qubit counts, depth, routing operations, layout, and measurements before and after transpilation.
- Compare at least two reasonable layouts or optimization configurations.
- Run structural tests to confirm qubit and classical-bit semantics.
- Benchmark the selected output with the same workload and document why it was chosen.
Keep the report beside the experiment rather than in an isolated notebook. That makes future backend comparisons faster and gives developers a clear baseline when a compiler upgrade changes the circuit. For broader tool discovery, consult the quantum computing tools directory, and pair transpilation measurements with appropriate error-mitigation and testing practices when running on noisy hardware.