Quantum circuit transpilation converts a hardware-independent circuit into a form a specific quantum processor or simulator can execute. This guide explains how to track layout, routing, gate decomposition, optimisation, and backend constraints so you can compare compiled circuits responsibly and diagnose why an apparently simple circuit became deeper.
Overview
A logical quantum circuit describes the algorithm you want to run. It may use abstract qubit connections and gates that are convenient for development, but a target backend usually imposes restrictions on which physical qubits can interact and which gates it can execute directly. Transpilation is the compiler workflow that reconciles those two views.
A useful transpilation workflow has five stages:
- Choose the target: identify the backend, simulator configuration, or hardware profile, including its available qubits, connectivity, supported operations, and execution constraints.
- Analyse the logical circuit: record qubit count, circuit depth, gate counts, two-qubit operations, measurements, and any barriers or control-flow features.
- Select a physical layout: map each logical qubit to a physical qubit. A good mapping places frequently interacting logical qubits close together on the backend coupling graph.
- Route and decompose: insert swaps or other routing operations where required, then rewrite abstract gates into the backend's native gate set.
- Optimise and validate: simplify the resulting circuit, compare its resource metrics with the original, and confirm that its behaviour remains equivalent within the intended compilation assumptions.
Transpilation is not simply a search for the shortest-looking circuit. A circuit with lower depth may use more two-qubit gates, while a circuit with fewer gates may map onto less reliable physical qubits. The right result depends on the objective: reducing execution time, limiting error exposure, preserving a variational structure, or producing a circuit compatible with a particular device.
For background on depth, width, gates, and shots, see the quantum circuit resource estimation guide.
What to track
Optimisation levels
SDKs commonly expose several optimisation levels, although names, defaults, and behaviour can change between releases. Treat the following table as a conceptual comparison rather than a promise about a particular version.
| Level | Typical purpose | Advantages | Trade-offs |
|---|---|---|---|
| Low or basic | Apply straightforward gate cancellations and basic decomposition. | Fast compilation; useful during development and debugging. | May leave avoidable depth, routing overhead, or redundant operations. |
| Medium | Combine local rewrites with layout and routing heuristics. | Good starting point for repeatable experiments. | Can produce different results as heuristics or SDK versions change. |
| High | Search more broadly for circuit simplification and hardware-aware improvements. | May reduce depth or two-qubit gate count for a fixed target. | Compilation can take longer and results may be more sensitive to settings. |
| Custom pipeline | Control individual passes, objectives, layouts, and routing methods. | Best for benchmarking, research, and production constraints. | Requires stronger testing and maintenance across framework releases. |
When comparing levels, record the SDK version, backend configuration, random seed where supported, optimisation settings, and whether the input was already partially compiled. Without this information, two results may not be reproducible.
Layout strategies
Layout is the initial assignment of logical to physical qubits. Common strategies include:
- Trivial layout: assign logical qubit zero to physical qubit zero, and so on. It is easy to understand but rarely optimal for constrained hardware.
- Dense or connectivity-aware layout: place the logical interaction graph onto a well-connected part of the device. This can reduce the number of inserted swaps.
- Noise-aware layout: consider calibration data or backend quality information when selecting physical qubits. This may trade a slightly shorter route for a more suitable region of the device.
- Fixed layout: provide an explicit mapping when reproducibility, calibration experiments, or an application-specific placement is more important than automatic search.
Inspect the backend coupling map rather than assuming that qubits are fully connected. The map may be directed for certain operations, and its available links can differ between targets or backend configurations.
Routing and native gates
Routing resolves interactions that are not supported by the current physical placement. A compiler may insert swaps, use a shortest-path heuristic, or choose another routing strategy exposed by the SDK. Every inserted swap can expand into several native operations, so routing is often the largest source of unexpected depth.
After routing, gate decomposition rewrites operations into the backend's native gate set. An abstract controlled operation, for example, may become a sequence of one- and two-qubit gates. Native gates are not automatically superior in every metric, but using supported operations avoids an additional translation stage and makes the compiled circuit's cost easier to assess.
Track at least these values before and after transpilation:
- total qubits and active qubits;
- overall depth and, where available, depth by gate type;
- total gate count;
- two-qubit gate count, including inserted routing operations;
- number of swaps and decomposed controlled operations;
- the selected physical qubits and coupling edges;
- the final gate set and any operations that remain unsupported;
- compilation time and execution-relevant constraints such as measurement placement.
A practical before-and-after record can use this format:
target: [backend or simulator profile]
framework_version: [version]
settings: [optimisation, layout, routing, seed]
logical_depth: [value]
compiled_depth: [value]
logical_two_qubit_gates: [value]
compiled_two_qubit_gates: [value]
inserted_swaps: [value]
final_gate_set: [list]
physical_layout: [mapping]
notes: [calibration or constraint assumptions]Framework-specific commands for inspecting depth, operation counts, layouts, coupling maps, and transpilation passes should be checked against the installed SDK documentation. Names and APIs can change, so avoid treating an old code snippet as a stable interface.
Cadence and checkpoints
Review transpilation whenever you change the target backend, upgrade the quantum SDK, alter the logical circuit, or change the objective of the experiment. For an active project, a monthly review is useful while circuits and provider configurations are moving quickly. A quarterly review is a sensible minimum for a stable codebase.
At each checkpoint, run a small, version-controlled benchmark suite containing representative circuits rather than relying on one toy example. Include circuits with different interaction patterns: a local chain, a dense interaction graph, a highly controlled circuit, and the application's typical workload. Compile each using the settings you expect to use in production or experiments.
Record results in a comparison table:
| Checkpoint | Target and SDK | Depth change | Two-qubit change | Layout or routing note |
|---|---|---|---|---|
| Date and commit | Backend profile and framework version | Before versus after | Before versus after | Swaps, rejected mappings, or native-gate changes |
Also rerun functional tests. A circuit that compiles successfully can still be unsuitable if measurements, parameter binding, control flow, or observable construction behave differently from the intended workflow. For experiment hygiene, use the quantum computing experiment reproducibility checklist.
How to interpret changes
An increase in depth is not automatically a compiler failure. It may indicate that the logical circuit used non-native gates, the chosen layout separated interacting qubits, or the backend has limited connectivity. First identify where the increase occurred: decomposition, routing, scheduling, or a deliberate optimisation constraint.
If two-qubit gate count rises sharply, inspect the layout and interaction graph before changing the optimisation level. A better initial placement may remove many swaps. If depth falls but two-qubit operations rise, decide which metric matters for the target hardware and experiment. On noisy devices, reducing two-qubit operations is often a useful objective, but it should be evaluated alongside calibration information and the application's required accuracy rather than used as an absolute rule.
If results differ between runs, check for stochastic pass behaviour, unspecified seeds, changing backend properties, and hidden defaults. Fix a seed for controlled comparisons when the framework supports it, but do not confuse reproducibility with quality: a stable heuristic can still produce a poor mapping.
When a high optimisation level produces little improvement, the circuit may already be close to the selected native form, or the dominant cost may be unavoidable routing. When compilation takes much longer without a meaningful resource improvement, a lower level or a custom pass sequence may be more appropriate for development. Compare compiler time as well as circuit metrics.
For a broader view of execution cost, connect transpilation results with quantum resource estimation and, where relevant, the backend benchmarking workflow.
When to revisit
Make transpilation review a normal part of your development cycle, not a one-time preparation step. Revisit this guide and your benchmark records when:
- you select a different backend, simulator, device generation, or coupling map;
- the provider changes its native gate set, calibration data, qubit availability, or backend interface;
- you upgrade Qiskit, Cirq, PennyLane, or another compilation framework;
- the circuit gains new controlled gates, entangling layers, measurements, or parameters;
- compiled depth or two-qubit gate count increases unexpectedly;
- execution quality changes without an obvious algorithmic change;
- you move from simulation to hardware or from exploratory work to a repeatable production workflow.
As a practical next step, choose one representative circuit, compile it with two or three documented configurations, and save the before-and-after metrics. Review the layout, count inserted swaps, inspect the final native gates, and run a functional equivalence test. Repeat that check monthly during active development and quarterly after the pipeline stabilises. This turns quantum circuit optimisation from guesswork into a measurable, maintainable part of your quantum programming workflow.