Skip to content
Current section
The Quantum Computing Enthusiast’s Hub
Saved
All sections

All sections

Saved
Skip Learn navigation
Encyclopedia
Topic

Quantum circuit compilation

The transformation of a logical circuit into an equivalent or controlled-approximation circuit compatible with a target operation set.

Also called transpilation, quantum compiler

Edition released Coverage: Overview · Technical
On this page

Definition and significance

Compilation reconciles an algorithm's operations with a target gate set, connectivity and execution constraints. Scientific descriptions should separate semantic equivalence from resource optimization. A compiler may preserve ideal behavior while changing physical error exposure, depth, routing or measurement timing.

This entry concerns the meaning of circuit transformation.

Mechanism and mathematical treatment

For a unitary-only circuit, exact equivalence can mean U_new=U_old or equality up to a global phase. If the circuit will later be controlled, a previously global phase may become relative, so the stronger context-aware condition is needed. Measurement circuits are more generally compared through channels or outcome distributions, including classical-output labels.

Approximate synthesis should specify a norm and tolerance. If unitary segments U_j are replaced by V_j with operator-norm errors epsilon_j, a telescoping bound gives ||product U_j-product V_j||<=sum_j epsilon_j. This simple allocation is conservative but makes the budget explicit.

Fully worked reference example

Two consecutive R_Z rotations satisfy R_Z(alpha)R_Z(beta)=R_Z(alpha+beta), so they can merge exactly. A consecutive HZH sequence equals X. But H and Z cannot be reordered without changing the operation: HZ and ZH act differently on |0>.

For a circuit containing 100 synthesized rotations each bounded by epsilon/100 in operator norm, the telescoping argument bounds the aggregate replacement error by epsilon before physical noise is added. Allocating epsilon independently to every gate would instead permit a bound of 100epsilon. The per-gate and circuit-level tolerances must not be confused.

Limitations and common misconceptions

Fewer gates can have worse error if they use a poorly calibrated interaction or increase idle time on vulnerable qubits. Compiler metrics depend on the device snapshot. A simulator-only equivalence check verifies ideal semantics, not the fidelity of hardware execution.

Scientific relationships

Routing is a compilation transformation subject to target connectivity.

These metrics describe different implementation costs.

Dropping a phase can invalidate a later controlled use of a subroutine.

An exact optimization across commuting operations

Consider the chronological circuit H on q1, CNOT q0->q1, H on q1, R_Z(alpha) on q0, R_Z(beta) on q0, and CZ on q0,q1. The first three gates compose to CZ. The two rotations commute with CZ because all are diagonal in the computational basis after that replacement. Move the first CZ across the rotations and cancel it with the final CZ. The complete circuit reduces exactly to R_Z(alpha+beta) on q0.

For alpha=pi/3 and beta=-pi/6, the result is R_Z(pi/6). The original high-level circuit has six gate symbols, including two entangling operations after recognizing the first three as one CZ. The optimized circuit has one single-qubit rotation. This is an exact semantic simplification, not an approximate cancellation justified by small angles.

The reasoning depends on commutation. Inserting an X rotation on q1 between the two CZ operations generally prevents their cancellation because CZ conjugates X on one qubit into a two-qubit Pauli. An optimizer must prove the relevant commutation or use a validated rewrite, rather than canceling visually matching gates separated by arbitrary operations.

Scheduling as a dependency problem

Use three physical qubits on a line. Let H on q0 and H on q2 each take one time unit. Let CNOT q0->q1 take three units, followed by CNOT q1->q2 taking three. Let a final R_Z on q0 take one unit. The two initial Hadamards can run simultaneously from time zero to one. The first CNOT runs from one to four. The second runs from four to seven, while the final q0 rotation can run from four to five because it is disjoint from that CNOT.

The resulting elapsed gate time is seven units. A strictly textual execution that delayed the q0 rotation until after the second CNOT would take eight. The ideal dependency depth is three layers if the final rotation shares the third layer. Neither layer count alone nor total gate count specifies elapsed time without the operation durations and concurrency assumptions.

Additional constraints can remove the overlap: shared control electronics, crosstalk exclusions or a device-wide barrier may forbid the simultaneous rotation. A scheduler should therefore distinguish qubit-disjoint legality from target-specific simultaneous-operation legality. The mathematical circuit supplies necessary dependencies, while the target model supplies additional constraints.

Equivalence depends on the surrounding context

A replacement equal only up to global phase is valid for an isolated unitary action on a state. If that subroutine is later coherently controlled, the phase becomes relative to the branch where it is not applied. For example, P(phi)=exp(i phi/2)R_Z(phi). Replacing P by R_Z without its scalar is harmless when the whole operation is unconditioned, but controlled-P and controlled-R_Z differ by a phase on the control.

A compiler's equivalence contract should therefore state whether it preserves an exact unitary, a unitary up to phase, a channel or a joint classical-quantum instrument. Measurement and reset circuits do not generally have a unitary matrix on their visible wires. Comparing only their final quantum density matrices can also miss differences in recorded classical outputs that later code uses.

For the exact cancellation example, one can multiply the small matrices and verify equality without a phase tolerance. For a larger reversible classical circuit, comparing Boolean output functions may establish its basis permutation but does not detect unintended quantum phases. A phase-sensitive representation or additional verification is required when superpositions are part of the input contract.

Approximation budgets and optimization objectives

Suppose a compiler approximates L rotations with individual norm tolerances eta_j. A conservative circuit-level synthesis bound is their sum. Choosing tolerances to minimize total synthesis cost under a fixed sum is an optimization problem; equal tolerances are convenient but not necessarily optimal when different rotations have different synthesis costs or reuse patterns.

Gate count, entangling depth, ancilla width, critical-path duration and estimated error can favor different compiled circuits. A circuit using one fewer entangling gate can still take longer if it forces a serial route. A wider circuit may reduce depth through parallel computation. Reporting a single unqualified optimized score hides those tradeoffs. The chosen objective should correspond to the scientific workload and target constraints.

For a small demonstration, direct matrix checks and the explicit schedule above are sufficient evidence of ideal correctness and the stated timing model. They do not establish physical fidelity. A hardware-quality comparison requires calibrated operations and a relevant noise or experimental evaluation, neither of which is asserted for this reference construction.

Sources

  • A. Barenco et al. · · Research paper · Publication status unspecified · arXiv · DOI 10.1103/PhysRevA.52.3457
    Verification scope

    Selected source text checked ·

    Source anchors gate-decomposition conventions. New worked instances are independent mathematical constructions, not reported experiments.

  • IBM Quantum · Documentation · quantum.cloud.ibm.com
    Verification scope

    Recorded source check ·

    Full ordering guide retrieved; statevector/integer/string conventions and explicit object-level result distinctions inspected.

    Conceptual reference semantics only. No code execution or universal backend support claim.