Quantum circuit transpilation turns an abstract circuit into an instruction sequence that a specific simulator or quantum processor can execute. This guide provides a repeatable workflow for selecting a target gate set, mapping logical qubits to physical qubits, reducing depth and two-qubit operations, and comparing results across Qiskit, Cirq, and PennyLane without assuming that a higher optimization setting is always better.
Overview
A circuit written with familiar operations such as Hadamard, rotation, and controlled gates is usually not ready for a target backend. The backend may support only a limited gate set, impose connectivity constraints, require particular measurement instructions, or expose a device-specific timing model. Transpilation, compilation, and decomposition are the stages that reconcile the circuit with those constraints.
The practical objective is not simply to produce the shortest source code. It is to preserve the circuit's intended behavior while reducing the resources most likely to affect execution: total depth, two-qubit gate count, inserted routing operations, idle time, and, where relevant, circuit duration. A circuit that has fewer gates overall can still be a poor choice if it contains more entangling gates or requires a longer qubit-movement sequence.
Keep two distinctions clear:
- Logical qubits are the qubits named by the algorithm.
- Physical qubits are the hardware locations to which those logical qubits are assigned.
- Gate decomposition expresses an operation using the target's native or accepted gate set.
- Routing adds operations, often swaps or equivalent decompositions, when interacting qubits are not adjacent in the device topology.
For hybrid applications such as VQE and quantum kernel workflows, transpilation is part of the experiment rather than a one-time packaging step. A change in circuit depth or entangling-gate count can alter optimization behavior and measured results. When evaluating an optimized circuit, pair resource metrics with functional checks and noise-aware validation. The quantum circuit resource estimation guide and noise-modeling guide provide useful context for that process.
What to track
1. Target constraints
Record the backend or simulator used for every comparison. At minimum, capture the supported gate set, number of available qubits, connectivity, native measurement behavior, and whether the run is ideal or noisy. A circuit optimized for an all-to-all simulator may require substantial routing on a device with restricted connectivity.
Do not treat a backend name as a complete specification. Hardware properties and SDK abstractions can change, and a provider may expose several compilation targets. Store the target configuration alongside the circuit and SDK version so that a later result can be reproduced.
2. Resource metrics
Track metrics before and after transpilation. Useful fields include:
- Number of qubits, including any ancillas introduced by the workflow.
- Total operation count.
- Circuit depth, with the framework's documented definition.
- Two-qubit gate count and, when available, the count by gate type.
- Number of inserted swaps or routing operations.
- Measurement and reset operations.
- Estimated duration or idle periods when timing information is available.
- Transpiler settings, including optimization, layout, routing, and decomposition choices.
Two-qubit gates deserve their own field. They often dominate the cost of mapping and are frequently more sensitive to noise than single-qubit operations, but the exact error profile depends on the target system. Avoid using depth alone as a proxy for quality.
3. Functional equivalence
An optimization is useful only if it preserves the behavior required by the application. For small circuits, compare statevectors or unitary representations where practical. For measured circuits, compare probabilities, expectation values, or counts using the same shot count and seed policy when supported. For variational algorithms, compare the objective landscape at identical parameter values before and after transpilation rather than comparing only the final optimizer result.
Measurement conventions can make equivalent circuits appear different. Confirm bit ordering, qubit ordering, parameter binding, and observable definitions before diagnosing a transpilation regression. See this overview of counts, probabilities, quasi-distributions, and expectation values when interpreting output.
Cross-SDK comparison
| SDK | Primary control | Mapping and routing considerations | What to record |
|---|---|---|---|
| Qiskit | transpile() with target, optimization level, layout, and routing options | Pass a backend or target when possible; inspect the resulting layout and routing operations | Optimization level, layout method, routing method, seed, depth, and two-qubit count |
| Cirq | Device-aware circuit transforms and optimizer passes such as target-gate-set optimization | Use a device or topology-aware workflow; routing and decomposition depend on the selected device and transform sequence | Device, optimizer sequence, final gate set, moments, swaps or movement operations, and gate counts |
| PennyLane | Device execution plus compilation and decomposition transforms | Confirm the device's supported operations and wire layout; compilation behavior can depend on the device and transform configuration | Device, decomposition settings, resulting tape or program, depth, operation counts, and differentiation method |
These controls are conceptually comparable, not interchangeable. Framework APIs evolve, and a similarly named optimization option may apply different passes. Treat the table as a starting point, then verify the installed version's documentation and inspect the emitted circuit.
Minimal Qiskit inspection example
The following pattern illustrates the comparison process. Backend names and supported options vary, so use the target available in your environment.
from qiskit import QuantumCircuit, transpile
circuit = QuantumCircuit(3)
circuit.h(0)
circuit.cx(0, 2)
circuit.ry(0.3, 2)
circuit.measure_all()
compiled = transpile(
circuit,
backend=backend,
optimization_level=2,
seed_transpiler=11,
)
print("depth:", compiled.depth())
print("operations:", compiled.count_ops())
print("two-qubit gates:", sum(
count for name, count in compiled.count_ops().items()
if name in {"cx", "ecr", "cz", "iswap"}
))For a robust report, do not hard-code only one two-qubit gate name. Define the set from the target's gate vocabulary, or classify operations by arity using the framework's circuit data structures. Also compare multiple transpiler seeds when stochastic layout or routing choices are involved.
Cadence and checkpoints
Transpilation results should be checked whenever the target, circuit, framework, or execution environment changes. A quarterly review is a reasonable default for an active project, with additional checks before hardware runs or production pipeline changes.
At circuit changes
Run the baseline and optimized versions whenever you add an ansatz layer, change entanglement topology, introduce an ancilla, or alter measurement placement. Small source-level changes can create a different routing problem. Save the previous resource report so that the change is visible rather than inferred from runtime alone.
At backend changes
Repeat compilation when moving from a simulator to hardware, changing device topology, selecting a different region or provider target, or updating the backend's calibration data where the workflow exposes it. A layout that was effective on one topology may be poor on another.
At SDK and dependency changes
Pin versions for reproducible experiments and rerun a compilation regression suite after upgrades. Compare both resource metrics and representative outputs. An SDK upgrade may change default decomposition, pass ordering, routing heuristics, or terminology without changing your source circuit.
Suggested checkpoint record
date: 2026-11-05
sdk: framework and version
backend: target identifier and version, if available
circuit_id: stable application name
settings: optimization, layout, routing, seed
logical_qubits: N
compiled_qubits: N
depth: N
two_qubit_gates: N
routing_operations: N
validation: method, tolerance, and result
notes: topology or decomposition observationsKeep this record in source control or an experiment store. It makes optimization a measurable engineering activity and supports the automated checks described in the CI/CD guide for hybrid quantum-classical applications.
How to interpret changes
A lower depth is generally encouraging, but it is not sufficient evidence of improvement. Start by asking what changed in the compiled circuit.
- Depth fell and two-qubit gates fell: This is usually a strong candidate for further validation, provided functional results remain consistent.
- Depth fell but two-qubit gates rose: The compiler may have parallelized more operations while increasing entangling exposure. Compare noisy results and circuit duration before choosing it.
- Two-qubit gates fell but depth rose: Fewer entangling operations may help, but longer execution can increase decoherence or idle error. The better choice depends on the target and workload.
- Depth and gate count rose after targeting hardware: This often indicates routing or native-gate decomposition overhead. Test alternative layouts and routing strategies rather than immediately raising the optimization level.
- Metrics are unchanged but results differ: Investigate parameter binding, measurement order, random seeds, compiler transformations, and simulator settings before blaming optimization.
Optimization levels are useful search presets, not quality guarantees. Compare at least two settings on a representative circuit and inspect the emitted operations. A higher level may spend more compilation time or produce a better result for one topology while performing worse for another. Layout selection is similarly workload-dependent: preserving a heavily used interaction graph can matter more than assigning qubits by their original indices.
Use a before-and-after template for every meaningful comparison:
| Field | Before | After | Interpretation |
|---|---|---|---|
| Target and topology | Same target? | ||
| Depth | Parallelism change | ||
| Two-qubit gates | Entangling overhead | ||
| Routing operations | Mapping cost | ||
| Functional metric | Equivalent within tolerance? | ||
| Noisy metric | Execution-level effect |
When to revisit
Revisit the transpilation workflow on a monthly or quarterly cadence for active projects, and immediately after any of these triggers:
- A quantum SDK, plugin, compiler, or runtime is upgraded.
- The backend topology, native gate set, calibration information, or execution target changes.
- A circuit gains layers, changes its entanglement pattern, or adds controlled operations.
- Measured quality, convergence, runtime, or job cost changes unexpectedly.
- A new routing, layout, decomposition, or device-aware compilation option becomes available in your approved toolchain.
- A simulator result is being promoted to hardware execution.
Make the review actionable. Recompile a fixed benchmark set, run the same functional validation, compare depth and two-qubit counts, and retain the compiler settings that produced each result. If a regression appears, first isolate whether it comes from decomposition, layout, routing, or measurement handling. Then test one variable at a time.
A practical checklist is:
- Define the target gate set, topology, and execution assumptions.
- Capture an uncompiled baseline and its functional output.
- Compile with a small set of documented optimization and mapping configurations.
- Report depth, total operations, two-qubit gates, routing operations, and duration when available.
- Validate ideal behavior, then test with a representative noise model or target execution path.
- Record versions, seeds, settings, and the selected circuit in a reproducible artifact.
- Schedule the next review or trigger it when the target or toolchain changes.
This process turns quantum circuit optimization from a one-off compiler experiment into maintainable developer tooling. It also gives hybrid application teams a defensible way to explain why a compiled circuit was selected and whether a later SDK or backend change actually improved execution.