Skip to main content
KetQat

Appearance

Topic · intermediate

Quantum Compilation

Turning an abstract quantum circuit into one a given device can run. Decomposition into native gates (Cartan decomposition, three-CNOT synthesis, CNOT lower bounds), qubit mapping and routing on limited connectivity and its hardness, peephole and template optimization, and discrete-gate synthesis.

ExpositionMachine-checkedUpdated 2026-12-01 · last verified 2026-12-01

AI-assisted text, machine-checked, not yet reviewed by a person. Citations resolve and an automated pass compared the statements with the cited sources. That is not peer review; check the sources for anything you depend on.

Overview

Algorithms are written as circuits of convenient gates on qubits that can all interact. A device offers a small native gate set (for example arbitrary single-qubit rotations plus one fixed entangling gate), a connectivity graph saying which pairs can interact, and error rates that differ from gate to gate. A quantum compiler bridges the two. Its main passes are:

  1. Decomposition (synthesis). Rewrite multi-qubit gates into native ones. For two qubits the Cartan decomposition shows that three CNOTs and single-qubit gates suffice (Vidal and Dawson; Vatan and Williams); for nn qubits generic unitaries need exponentially many CNOTs (Shende, Markov and Bullock).
  2. Mapping and routing. Place logical qubits on physical ones and insert SWAPs so that every two-qubit gate acts on neighbours (Siraichi et al.; Li, Ding and Xie). Optimal versions of this step are NP-hard in natural formulations (Botea, Kishimoto and Marinescu).
  3. Optimization. Cancel and merge gates by local rewrite rules and templates (Maslov et al.; Nam et al.).
  4. Discrete synthesis. For fault-tolerant targets, approximate continuous rotations by words in a finite gate set such as Clifford+T; this is covered in Clifford+T synthesis.

Intuition

Compilation resembles classical compilation with an unusual cost model. Every extra gate adds error, so a compiler that saves a few CNOTs can matter more than one that saves time. Connectivity plays the role of register allocation: an instruction can only combine operands held in adjacent "registers", and moving data (a SWAP) costs three entangling gates.

Two facts frame what is possible. First, two-qubit gates are well understood: after removing single-qubit gates on each side, a two-qubit gate is described by just three angles, which is why any of them costs at most three CNOTs. Second, large unitaries are hopeless to synthesise exactly: a parameter count shows that almost all nn-qubit unitaries need about 4n−14^{n-1} CNOTs, so practical compilers never synthesise arbitrary unitaries beyond a few qubits; they preserve the structure of the algorithm and optimise locally.

Prerequisites

The circuit model, the Z–Y–Z decomposition, the universality of CNOT and single-qubit gates, and the notion of a connectivity graph. The lesson gates and unitaries covers the gate identities used here.

Mathematical Definitions

DefinitionQubit mapping and routing problemEstablished definition

Let G=(V,E)G = (V, E) be the device's connectivity graph and let CC be a circuit on logical qubits QQ, ∣Q∣≤∣V∣\abs Q \le \abs V, whose two-qubit gates g1,…,gmg_1, \dots, g_m act on pairs {q,q′}⊆Q\{q, q'\} \subseteq Q and are partially ordered by the circuit's dependency DAG. A layout is an injective map π:Q→V\pi: Q \to V. A SWAP on an edge {u,v}∈E\{u, v\} \in E changes the layout by exchanging the logical qubits held at uu and vv.

A mapping and routing solution is an initial layout π0\pi_0 together with a sequence of gates, consisting of the gates of CC in an order compatible with the DAG interleaved with SWAPs, such that each two-qubit gate gg on {q,q′}\{q, q'\} is scheduled at a time when the current layout π\pi satisfies {π(q),π(q′)}∈E\{\pi(q), \pi(q')\} \in E. The resulting circuit implements CC followed by the permutation of qubits given by the final layout, which is tracked classically rather than undone. The objective is to minimise the number of SWAPs (each typically three CNOTs, by the SWAP identity), the depth, or an estimated success probability built from per-edge error rates.

The problem was posed for cloud superconducting processors as qubit allocation by Siraichi et al.. Widely used heuristics include the bidirectional search SABRE of Li, Ding and Xie, the A*-based layer-by-layer method of Zulehner, Paler and Wille, and the architecture-agnostic routing of Cowtan et al..

Holds when
  • Two-qubit gates only between adjacent physical qubits; single-qubit gates anywhere; data moved only by SWAP gates (other movement primitives change the cost model).
DefinitionPeephole and template optimization of quantum circuitsEstablished definition

A rewrite rule is a pair of circuits (L,R)(L, R) on the same qubits with UL=URU_L = U_R (up to phase) and cost(R)<cost(L)\mathrm{cost}(R) < \mathrm{cost}(L). A peephole optimizer repeatedly finds an occurrence of some LL in the circuit, where an occurrence may be spread out in time provided the gates between its parts commute past them, and replaces it with RR. Typical rules: cancel GG−1G G^{-1} (for example two adjacent CNOTs or Hadamards on the same qubits); merge Rz(α)Rz(β)=Rz(α+β)R_z(\alpha) R_z(\beta) = R_z(\alpha+\beta), moving RzR_z through CNOT controls; and resynthesise a maximal two-qubit block with the three-CNOT construction when that is cheaper.

A template is a circuit T=T1T2T = T_1 T_2 implementing the identity. Any occurrence of T1T_1 (with more than half of TT's gates) can be replaced by T2−1T_2^{-1}, which is shorter (Maslov et al.). Finding all maximal matches of a pattern in a circuit modulo commutation is itself an algorithmic problem; Iten et al. give an exact algorithm that is polynomial in the circuit size for a fixed pattern size. Rule-based optimizers with continuous rotation angles, phase-polynomial resynthesis and floating rotations are described by Nam et al..

Local rewriting always terminates when each step strictly lowers an integer cost, but it finds only local optima: the final circuit depends on the order in which rules are applied.

Holds when
  • Circuits are sequences of gates from a fixed library; equivalence means equality of the implemented unitaries, possibly up to a global phase.

Theorems

Two-qubit gates

TheoremCartan (KAK) decomposition of two-qubit gatesEstablished result

For every U∈U(4)U \in U(4) there are A1,A2,B1,B2∈SU(2)A_1, A_2, B_1, B_2 \in SU(2), real numbers a,b,ca, b, c and a phase γ∈R\gamma \in \R such that

U=eiγ (A1⊗A2)  exp⁡ ⁣(i(a XX+b YY+c ZZ))  (B1⊗B2).U = e^{i\gamma}\, (A_1 \otimes A_2)\; \exp\!\big(i(a\, XX + b\, YY + c\, ZZ)\big)\; (B_1 \otimes B_2).

The triple (a,b,c)(a, b, c) is not unique. Permuting its entries (conjugation by H⊗HH\otimes H exchanges XXXX and ZZZZ, and by S⊗SS\otimes S exchanges XXXX and YYYY), changing the sign of two entries (conjugation by Z⊗IZ\otimes I flips XXXX and YYYY), or shifting one entry by π/2\pi/2 (eiπ2XX=i X⊗Xe^{i\frac{\pi}{2}XX} = i\,X\otimes X) is absorbed into the local factors and the phase. Restricting the triple to a fundamental region for such moves gives the Weyl chamber of two-qubit gates. Any property invariant under single-qubit gates, such as entangling power or the minimal CNOT count, depends only on the triple. For example CZ, and hence CNOT, has triple (π/4,0,0)(\pi/4, 0, 0) and SWAP has (π/4,π/4,π/4)(\pi/4, \pi/4, \pi/4) modulo these moves (see the proof).

The decomposition is the two-qubit case of the Cartan decomposition of SU(2n)SU(2^n) used in control theory by Khaneja and Glaser; it was obtained independently, with its use for entangling power, by Kraus and Cirac, and the magic-basis form used in the proof is that of Vatan and Williams.

Holds when
  • U∈U(4)U \in U(4) acting on two qubits; X,Y,ZX, Y, Z are the Pauli matrices and XXXX abbreviates X⊗XX \otimes X.
Proof · Proof of the two-qubit Cartan decomposition

Magic basis. Let MM be the unitary whose columns are ∣Φ+⟩, i∣Φ−⟩, i∣Ψ+⟩, ∣Ψ−⟩\ket{\Phi^+},\ i\ket{\Phi^-},\ i\ket{\Psi^+},\ \ket{\Psi^-}, with the usual Bell states. We use one fact, proved by Vatan and Williams (see also Kraus and Cirac): K↦M†KMK \mapsto M\dagg K M maps SU(2)⊗SU(2)SU(2)\otimes SU(2) onto SO(4)SO(4). The second fact is a direct check: each Bell state is a joint eigenvector of XXXX, YYYY, ZZZZ, with eigenvalue vectors (over Φ+,Φ−,Ψ+,Ψ−\Phi^+, \Phi^-, \Psi^+, \Psi^-)

XX:(1,−1,1,−1),YY:(−1,1,1,−1),ZZ:(1,1,−1,−1),XX: (1, -1, 1, -1),\quad YY: (-1, 1, 1, -1),\quad ZZ: (1, 1, -1, -1),

and the phases ii in MM do not change eigenvectors. Together with I:(1,1,1,1)I: (1,1,1,1) these are four mutually orthogonal vectors, so every diagonal matrix in the magic basis is a real linear combination of I,XX,YY,ZZI, XX, YY, ZZ when its entries are real, and every diagonal unitary is exp⁡ ⁣(i(a0I+aXX+bYY+cZZ))\exp\!\big(i(a_0 I + a XX + b YY + c ZZ)\big) for real a0,a,b,ca_0, a, b, c.

Step 1. Remove a phase: U=eiγ0U′U = e^{i\gamma_0} U' with U′∈SU(4)U' \in SU(4). Put V=M†U′M∈SU(4)V = M\dagg U' M \in SU(4) and W=VTVW = V^{T} V. Then WW is unitary and symmetric.

Step 2. Write W=A+iBW = A + iB with A,BA, B real. Symmetry of WW makes A,BA, B symmetric, and W†=W‾T=W‾W\dagg = \overline{W}^{T} = \overline{W}. Unitarity gives I=WW‾=(A+iB)(A−iB)=A2+B2+i(BA−AB)I = W\overline{W} = (A + iB)(A - iB) = A^2 + B^2 + i(BA - AB), so AB=BAAB = BA. Two commuting real symmetric matrices are diagonalised by one real orthogonal matrix OO; replacing a column of OO by its negative if necessary, O∈SO(4)O \in SO(4). So W=ODOTW = O D O^{T} with DD diagonal, and DD is unitary because WW is.

Step 3. Choose a diagonal FF with F2=DF^2 = D. Then (det⁡F)2=det⁡D=det⁡W=(det⁡V)2=1(\det F)^2 = \det D = \det W = (\det V)^2 = 1; if det⁡F=−1\det F = -1, negate one diagonal entry of FF, so det⁡F=1\det F = 1. Define Q=VOF−1Q = V O F^{-1}. It is unitary, and

QTQ=F−1OTVTVOF−1=F−1OTWOF−1=F−1DF−1=I.Q^{T} Q = F^{-1} O^{T} V^{T} V O F^{-1} = F^{-1} O^{T} W O F^{-1} = F^{-1} D F^{-1} = I .

Hence QT=Q−1=Q†Q^{T} = Q^{-1} = Q\dagg, so Q‾=Q\overline{Q} = Q: QQ is real orthogonal, with det⁡Q=det⁡Vdet⁡O/det⁡F=1\det Q = \det V \det O / \det F = 1, i.e. Q∈SO(4)Q \in SO(4).

Step 4. V=QFOTV = Q F O^{T}, so U′=(MQM†)(MFM†)(MOTM†)U' = (M Q M\dagg)(M F M\dagg)(M O^{T} M\dagg). By the first fact the outer factors are A1⊗A2A_1 \otimes A_2 and B1⊗B2B_1 \otimes B_2 with Ai,Bi∈SU(2)A_i, B_i \in SU(2). The middle factor is diagonal and unitary in the magic basis, so it equals exp⁡(i(a0I+aXX+bYY+cZZ))\exp(i(a_0 I + a XX + b YY + c ZZ)). Collecting eiγ0eia0e^{i\gamma_0} e^{i a_0} into eiγe^{i\gamma} gives the theorem.

Examples. In the magic basis SWAP is diag⁡(1,1,1,−1)\operatorname{diag}(1, 1, 1, -1), which is eiπ/4exp⁡ ⁣(−iπ4(XX+YY+ZZ))e^{i\pi/4}\exp\!\big(-i\tfrac{\pi}{4}(XX + YY + ZZ)\big) (check: the exponent gives e−iπ/4e^{-i\pi/4} on the three states with XX+YY+ZZ=1XX + YY + ZZ = 1 and e3iπ/4e^{3i\pi/4} on Ψ−\Psi^-). For CZ, CZ=eiπ/4 (S†⊗S†)exp⁡ ⁣(−iπ4ZZ)\mathrm{CZ} = e^{i\pi/4}\,(S\dagg\otimes S\dagg)\exp\!\big(-i\tfrac{\pi}{4} ZZ\big), as one checks on the four computational basis states; CNOT differs from CZ by Hadamards on the target.

TheoremThree CNOTs suffice for any two-qubit gatePeer-reviewed result

For every U∈U(4)U \in U(4) there is a circuit U=eiγ (A1⊗A2) CNOT (C1⊗C2) CNOT (D1⊗D2) CNOT (B1⊗B2)U = e^{i\gamma}\, (A_1\otimes A_2)\, \mathrm{CNOT}\, (C_1 \otimes C_2)\, \mathrm{CNOT}\, (D_1 \otimes D_2)\, \mathrm{CNOT}\, (B_1 \otimes B_2) with single-qubit gates Ai,Bi,Ci,DiA_i, B_i, C_i, D_i (CNOT directions fixed by the construction). By the Cartan decomposition it suffices to implement the core exp⁡(i(aXX+bYY+cZZ))\exp(i(a XX + b YY + c ZZ)) for arbitrary (a,b,c)(a, b, c), and one three-CNOT circuit with single-qubit rotations whose angles are explicit functions of a,b,ca, b, c does this.

The result was obtained independently by Vidal and Dawson, Vatan and Williams and Shende, Markov and Bullock, the last also for other gate libraries. Vatan and Williams show that two CNOTs suffice when UU is a real orthogonal matrix of determinant +1+1 (U∈SO(4)U \in SO(4)); a real UU of determinant −1-1, such as SWAP, may need three. That three are necessary for almost every UU follows from the parameter-counting bound with n=2n = 2.

Holds when
  • Gate library of CNOT and arbitrary single-qubit unitaries, no ancillas.
EquationSWAP from three CNOTsEstablished result
SWAP  =  CNOT1→2  CNOT2→1  CNOT1→2\mathrm{SWAP} \;=\; \mathrm{CNOT}_{1\to 2}\; \mathrm{CNOT}_{2\to 1}\; \mathrm{CNOT}_{1\to 2}

On a basis state ∣x,y⟩\ket{x, y} the three gates give ∣x,x⊕y⟩\ket{x, x\oplus y}, then ∣x⊕x⊕y, x⊕y⟩=∣y,x⊕y⟩\ket{x \oplus x \oplus y,\, x\oplus y} = \ket{y, x\oplus y}, then ∣y,y⊕x⊕y⟩=∣y,x⟩\ket{y, y \oplus x \oplus y} = \ket{y, x}. Both sides are linear and agree on a basis, so they are equal; identities of this kind are collected in chapter 4 of Nielsen and Chuang. The middle CNOT may be reversed with Hadamards, CNOT2→1=(H⊗H) CNOT1→2 (H⊗H)\mathrm{CNOT}_{2\to1} = (H\otimes H)\,\mathrm{CNOT}_{1\to2}\,(H\otimes H), when the hardware supports only one direction. By the parameter-counting bound three is also the generic minimum for two-qubit gates.

A related bridge identity implements a CNOT between the ends of a three-qubit line 0−1−20 - 1 - 2 without moving data: in time order CNOT0→1, CNOT1→2, CNOT0→1, CNOT1→2\mathrm{CNOT}_{0\to1},\ \mathrm{CNOT}_{1\to2},\ \mathrm{CNOT}_{0\to1},\ \mathrm{CNOT}_{1\to2} maps ∣a,b,c⟩\ket{a, b, c} to ∣a,b,c⊕a⟩\ket{a, b, c \oplus a}, which is CNOT0→2\mathrm{CNOT}_{0\to2}.

Holds when
  • CNOTi→j\mathrm{CNOT}_{i\to j} has control ii and target jj; exact equality, no phase.

Many qubits

TheoremCNOT lower bound for generic n-qubit unitariesEstablished result

Let κn=⌈(4n−3n−1)/4⌉\kappa_n = \big\lceil (4^n - 3n - 1)/4 \big\rceil. The set of U∈U(2n)U \in U(2^n) that can be implemented, up to a global phase, by a circuit with fewer than κn\kappa_n CNOT gates and any number of single-qubit gates has Haar measure zero.

Values: κ2=3\kappa_2 = 3, κ3=14\kappa_3 = 14, κ4=61\kappa_4 = 61. For two qubits the bound is tight: three CNOTs suffice for every two-qubit gate (see the topic page). For general nn the quantum Shannon decomposition of Shende, Bullock and Markov uses O(4n)O(4^n) CNOTs, a constant factor above κn\kappa_n. The bound and the counting argument are due to Shende, Markov and Bullock.

Holds when
  • Circuits consist of CNOT gates between any ordered pairs of the n≥1n \ge 1 qubits and arbitrary single-qubit unitaries; no ancillas and no measurements.
  • "Almost every" refers to the Haar measure on U(2n)U(2^n); equality is up to a global phase.
Proof · Proof of the CNOT lower bound for generic unitaries

Normal form. Fix a circuit with kk CNOTs. Merge adjacent single-qubit gates on the same qubit. A single-qubit gate on qubit qq commutes with every CNOT not acting on qq, so it can be moved backwards in time until it meets the most recent earlier CNOT acting on qq, or the start of the circuit. The circuit then has the form: one layer L0=V1⊗⋯⊗VnL_0 = V_1 \otimes \cdots \otimes V_n of single-qubit gates, followed, for j=1,…,kj = 1, \dots, k, by the CNOT cjc_j with control sjs_j and target tjt_j and then single-qubit gates PjP_j on sjs_j and QjQ_j on tjt_j.

Removing redundant parameters. Process j=k,k−1,…,1j = k, k-1, \dots, 1. By the Z–Y–Z decomposition (theorem), Pj=eiαRz(β)Ry(γ)Rz(δ)P_j = e^{i\alpha} R_z(\beta) R_y(\gamma) R_z(\delta), and since RzR_z on the control commutes with CNOT, the factor Rz(δ)R_z(\delta), applied first, can be moved before cjc_j and merged into the previous gate on qubit sjs_j (a PiP_i or QiQ_i with i<ji < j, or a factor of L0L_0), which remains an arbitrary single-qubit gate. Likewise Qj=eiα′Rx(β′)Ry(γ′)Rx(δ′)Q_j = e^{i\alpha'} R_x(\beta') R_y(\gamma') R_x(\delta') (the X–Y–X decomposition, obtained from Z–Y–Z by conjugating with a Hadamard, which maps Rz(θ)R_z(\theta) to Rx(θ)R_x(\theta) and Ry(θ)R_y(\theta) to Ry(−θ)R_y(-\theta)), and RxR_x on the target commutes with CNOT, so Rx(δ′)R_x(\delta') moves before cjc_j. Global phases are collected in front. After the pass, each PjP_j and QjQ_j depends on two real parameters, L0L_0 on 3n3n (each Vi∈SU(2)V_i \in SU(2)), and there is one global phase.

Counting. For a fixed sequence of CNOT positions (sj,tj)j≤k(s_j, t_j)_{j \le k} the implemented unitaries, modulo global phase, form the image of a smooth map f:SU(2)n×R4k→PU(2n)f: SU(2)^n \times \R^{4k} \to PU(2^n) from a manifold of dimension 3n+4k3n + 4k into one of dimension 4n−14^n - 1. If 3n+4k<4n−13n + 4k < 4^n - 1, every point of the domain is critical, so by Sard's theorem the image has measure zero. There are finitely many CNOT position sequences for each k′≤kk' \le k, and a finite union of null sets is null. The inequality 3n+4k<4n−13n + 4k < 4^n - 1 holds exactly when k<(4n−3n−1)/4k < (4^n - 3n - 1)/4, i.e. for all k<κnk < \kappa_n. Since the projection U(2n)→PU(2n)U(2^n) \to PU(2^n) maps Haar-null sets to null sets and back (the measures are locally products with the phase circle), the set of such UU has Haar measure zero.

Values. n=2n = 2: (16−6−1)/4=2.25(16 - 6 - 1)/4 = 2.25, so κ2=3\kappa_2 = 3. n=3n = 3: (64−10)/4=13.5(64 - 10)/4 = 13.5, so κ3=14\kappa_3 = 14. n=4n = 4: (256−13)/4=60.75(256 - 13)/4 = 60.75, so κ4=61\kappa_4 = 61.

The matching upper bound comes from the quantum Shannon decomposition, which recursively splits an nn-qubit unitary into multiplexed (n−1)(n-1)-qubit pieces and uses O(4n)O(4^n) CNOTs (Shende, Bullock and Markov).

Discrete gate sets

TheoremSolovay–Kitaev theoremEstablished result

Let G⊂SU(d)\mathcal{G} \subset SU(d) satisfy the assumptions. There is a constant cc such that for every U∈SU(d)U \in SU(d) and every ε∈(0,1/2)\varepsilon \in (0, 1/2) there is a sequence g1,…,gℓ∈Gg_1, \dots, g_\ell \in \mathcal{G} with

∥U−gℓ⋯g1∥≤ε,ℓ=O ⁣(log⁡c(1/ε)),\norm{U - g_\ell \cdots g_1} \le \varepsilon , \qquad \ell = O\!\left(\log^{c}(1/\varepsilon)\right),

where the implied constant depends on G\mathcal{G} but not on UU or ε\varepsilon. The sequence is produced by a classical algorithm whose running time is also polylogarithmic in 1/ε1/\varepsilon.

The recursive construction analysed by Dawson and Nielsen gives c=log⁡5/log⁡(3/2)≈3.97c = \log 5 / \log(3/2) \approx 3.97 and running time O(log⁡c′(1/ε))O(\log^{c'}(1/\varepsilon)) with c′=log⁡3/log⁡(3/2)≈2.71c' = \log 3 / \log(3/2) \approx 2.71; see the exponent equation. Refined versions reach c=3+δc = 3 + \delta for every δ>0\delta > 0, and a 2023 preprint of Kuperberg, which summarises that earlier state, lowers the exponent to 1.44042…+δ1.44042\ldots + \delta (as of 2026-11 this improvement is known from the preprint). A volume-counting argument shows that no finite gate set can do better than ℓ=Ω(log⁡(1/ε))\ell = \Omega(\log(1/\varepsilon)).

The theorem is due to R. Solovay (an unpublished 1995 manuscript) and, independently, to Kitaev; textbook proofs are in Kitaev, Shen and Vyalyi and in Appendix 3 of Nielsen and Chuang. Its practical meaning is that the choice of a universal gate set changes circuit sizes by at most a polylogarithmic factor: a circuit of mm gates from one set, each approximated to ε/m\varepsilon/m, becomes a circuit of O(mlog⁡c(m/ε))O(m \log^{c}(m/\varepsilon)) gates from another with total error at most ε\varepsilon.

Holds when
  • The gate set G⊂SU(d)\mathcal{G} \subset SU(d) is finite and closed under inverses (g∈G⇒g†∈Gg \in \mathcal{G} \Rightarrow g\dagg \in \mathcal{G}).
  • The group generated by G\mathcal{G} is dense in SU(d)SU(d); dd is fixed while ε→0\varepsilon \to 0.
  • Accuracy is measured in operator norm.
TheoremOptimal ancilla-free Clifford+T approximation of z-rotationsEstablished result

For every angle θ\theta and ε>0\varepsilon > 0, the probabilistic algorithm of Ross and Selinger

  • with access to a factoring oracle, returns an ancilla-free Clifford+T circuit WW with ∥W−Rz(θ)∥≤ε\norm{W - R_z(\theta)} \le \varepsilon of the smallest T-count among all such circuits;
  • without the oracle, under a mild number-theoretic hypothesis, runs in expected time polynomial in log⁡(1/ε)\log(1/\varepsilon) and returns a circuit of T-count m+O(log⁡log⁡(1/ε))m + O(\log\log(1/\varepsilon)), where mm is the T-count of the second-best solution;
  • in the typical case produces T-count
3log⁡2(1/ε)+O(log⁡log⁡(1/ε)).3 \log_2(1/\varepsilon) + O\big(\log\log(1/\varepsilon)\big).

The method reduces approximation to two problems over the ring Z[1/2,i]\mathbb{Z}[1/\sqrt{2}, i]: a two-dimensional grid problem, enumerating ring elements uu close to e−iθ/2e^{-i\theta/2} in a thin region of the unit disc (and whose Galois conjugate lies in the unit disc), and a norm equation ∣t∣2=1−∣u∣2\abs{t}^2 = 1 - \abs{u}^2 to complete uu to a unitary with entries in the ring; the result is then turned into a circuit by exact synthesis. An earlier algorithm of Selinger achieves T-count 4log⁡2(1/ε)+K4\log_2(1/\varepsilon) + K with K≈10K \approx 10 for zz-rotations and proves a worst-case lower bound of the same form, 4log⁡2(1/ε)−94\log_2(1/\varepsilon) - 9, for certain zz-rotations.

Holds when
  • Target Rz(θ)R_z(\theta), accuracy ε\varepsilon in operator norm, single-qubit Clifford+T circuits with no ancillas or measurements.
  • Optimality relies on a factoring oracle; the classical runtime bound relies on a stated number-theoretic hypothesis.

Solovay–Kitaev applies to any finite universal gate set and gives words of length polylogarithmic in 1/ϵ1/\epsilon (Dawson and Nielsen); number-theoretic methods for Clifford+T reach the optimal O(log⁡(1/ϵ))O(\log(1/\epsilon)) for single-qubit rotations (Ross and Selinger). The surrounding theory (exact synthesis, phase polynomials, T-count optimisation such as Amy, Maslov and Mosca) is on the Clifford+T synthesis page.

Worked Examples

The nonlocal core of CZ

In the magic basis, XXXX, YYYY, ZZZZ are diagonal, and the Cartan decomposition reads CZ as eiπ/4(S†⊗S†)exp⁡(−iπ4ZZ)e^{i\pi/4}(S\dagg \otimes S\dagg)\exp(-i\tfrac{\pi}{4} ZZ). Check on ∣11⟩\ket{11}: exp⁡(−iπ4ZZ)\exp(-i\tfrac\pi4 ZZ) gives e−iπ/4e^{-i\pi/4}, S†⊗S†S\dagg\otimes S\dagg gives (−i)2=−1(-i)^2 = -1, and the phase eiπ/4e^{i\pi/4} restores −1-1 overall, as CZ requires; on ∣01⟩\ket{01} the factors are eiπ/4e^{i\pi/4}, −i-i and eiπ/4e^{i\pi/4}, with product 11. So CZ has interaction triple (0,0,−π/4)(0, 0, -\pi/4), equivalent to (π/4,0,0)(\pi/4, 0, 0) under the moves listed in the theorem. It needs exactly one CNOT, while SWAP, with triple (π/4,π/4,π/4)(\pi/4, \pi/4, \pi/4), uses three.

Why initial layout matters

Hardware: a line p0−p1−p2p_0 - p_1 - p_2. Logical circuit: CNOTa→b\mathrm{CNOT}_{a\to b} then CNOTa→c\mathrm{CNOT}_{a\to c} (a fan-out from aa).

  • Layout a↦p0a \mapsto p_0, b↦p1b \mapsto p_1, c↦p2c \mapsto p_2: the first gate is on an edge, the second is not. One SWAP on {p1,p2}\{p_1, p_2\} fixes it: total 1+3+1=51 + 3 + 1 = 5 CNOTs. Alternatively the bridge identity implements CNOTp0→p2\mathrm{CNOT}_{p_0\to p_2} with four CNOTs and no change of layout: also 5.
  • Layout a↦p1a \mapsto p_1: both gates are on edges, total 2 CNOTs.

With two-qubit error 10−210^{-2} per CNOT and errors adding, the first layout has error about 5×10−25 \times 10^{-2} and the second about 2×10−22 \times 10^{-2}. Choosing the layout is the "mapping" half of the routing problem; a triangle of interactions {a,b},{a,c},{b,c}\{a,b\}, \{a,c\}, \{b,c\} on the same line needs at least one SWAP or bridge for every layout, because a triangle is not a subgraph of a path.

A peephole saving T gates

On a control qubit, T CNOT TT\, \mathrm{CNOT}\, T (with T=Rz(π/4)T = R_z(\pi/4) up to phase on the control) becomes CNOT T2=CNOT S\mathrm{CNOT}\, T^2 = \mathrm{CNOT}\, S, because RzR_z on the control commutes with CNOT. A peephole rule thus turns two T gates into one Clifford gate, lowering the T-count from 2 to 0. The same commutation is the engine behind the phase-polynomial view of CNOT+T circuits.

CNOT budgets

The parameter-counting bound gives ⌈(4n−3n−1)/4⌉\lceil (4^n - 3n - 1)/4\rceil = 3, 14, 61, 252 for n=2,3,4,5n = 2, 3, 4, 5. A generic five-qubit unitary therefore needs at least 252 CNOTs; at an error rate of 10−310^{-3} per CNOT that alone contributes about 0.250.25 to the error. This is why compilers do not resynthesise large blocks from their matrices.

Algorithms and Implementations

  • Routing heuristics. SABRE (Li, Ding and Xie) chooses SWAPs greedily against a look-ahead cost on the front layer of the dependency graph and refines the initial layout by routing the circuit forwards and backwards. Zulehner, Paler and Wille use A* search layer by layer, and Cowtan et al. describe a device-independent router.
  • Rule-based optimization. Gate cancellation, rotation merging and phase-polynomial resynthesis (Nam et al.); template matching with exact pattern matching (Iten et al.).
  • Block resynthesis. Collect maximal runs of gates on two qubits and resynthesise each with the three-CNOT construction when that is cheaper.
  • Graphical rewriting. The ZX-calculus gives a complete set of rewrite rules that underlies several optimizers.

Computational Complexity

Exact synthesis of an arbitrary nn-qubit unitary is exponential in nn in output size, by the lower bound above. For routing, Botea, Kishimoto and Marinescu prove NP-completeness of a makespan-optimization formulation of circuit compilation onto restricted hardware, and exact solvers (search, SAT and integer programming) scale exponentially in the worst case, so production compilers use heuristics such as those above. Peephole optimization with a fixed rule set runs in polynomial time per pass but carries no global optimality guarantee.

Limitations and Common Pitfalls

  • Wrong cost model. CNOT count is the right metric on noisy devices, T-count and T-depth on fault-tolerant ones (resource estimation); optimising one can worsen the other.
  • Final permutation. Routing leaves qubits permuted. Forgetting to relabel measurement results gives wrong answers that still look plausible.
  • Equivalence up to phase. Rewrites valid up to a global phase are not valid inside controlled operations, where the phase becomes relative.
  • Uniform error assumptions. Counting SWAPs treats all edges alike; real devices have per-edge error rates and crosstalk, which hardware-aware algorithms and noise-aware compilers take into account.
  • Verification. Optimizers are complex programs; checking that output and input circuits are equivalent is itself a task of quantum software engineering.

The architecture side, including how connectivity shapes error-correcting codes and lattice-surgery layouts, is on quantum architecture; compilation for fault-tolerant machines continues in Clifford+T synthesis and lattice surgery. Pulse-level compilation, which replaces fixed native gates by optimised control waveforms, connects to quantum control.

Builds on

Open in the knowledge graph

Contributions about this record

Nobody has published a contribution about it yet.

Publish a result, reproduction or commentPropose a correction to this page

References

  1. Navin Khaneja, Steffen J. Glaser (2001). Cartan decomposition of SU(2^n) and control of spin systems. Chemical Physics 267, 11-23. doi:10.1016/S0301-0104(01)00318-4
  2. B. Kraus, J. I. Cirac (2001). Optimal creation of entanglement using a two-qubit gate. Physical Review A 63, 062309. doi:10.1103/PhysRevA.63.062309arXiv:quant-ph/0011050
  3. Farrokh Vatan, Colin Williams (2004). Optimal quantum circuits for general two-qubit gates. Physical Review A 69, 032315. doi:10.1103/PhysRevA.69.032315arXiv:quant-ph/0308006
  4. G. Vidal, C. M. Dawson (2004). Universal quantum circuit for two-qubit transformations with three controlled-NOT gates. Physical Review A 69, 010301. doi:10.1103/PhysRevA.69.010301arXiv:quant-ph/0307177
  5. Vivek V. Shende, Igor L. Markov, Stephen S. Bullock (2004). Minimal universal two-qubit controlled-NOT-based circuits. Physical Review A 69, 062321. doi:10.1103/PhysRevA.69.062321arXiv:quant-ph/0308033
  6. Vivek V. Shende, Stephen S. Bullock, Igor L. Markov (2006). Synthesis of quantum-logic circuits. IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 25, 1000-1010. doi:10.1109/TCAD.2005.855930arXiv:quant-ph/0406176
  7. Marcos Yukio Siraichi, Vinícius Fernandes dos Santos, Caroline Collange, Fernando Magno Quintão Pereira (2018). Qubit allocation. Proceedings of the 2018 International Symposium on Code Generation and Optimization (CGO), 113-125. doi:10.1145/3168822
  8. Adi Botea, Akihiro Kishimoto, Radu Marinescu (2018). On the Complexity of Quantum Circuit Compilation. Proceedings of the International Symposium on Combinatorial Search (SoCS 2018) 9, 138-142. doi:10.1609/socs.v9i1.18463
  9. Gushu Li, Yufei Ding, Yuan Xie (2019). Tackling the Qubit Mapping Problem for NISQ-Era Quantum Devices. Proceedings of the Twenty-Fourth International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS), 1001-1014. doi:10.1145/3297858.3304023arXiv:1809.02573
  10. Alexander Cowtan, Silas Dilkes, Ross Duncan, … Seyon Sivarajah (2019). On the qubit routing problem. 14th Conference on the Theory of Quantum Computation, Communication and Cryptography (TQC 2019), LIPIcs 135, 5. arXiv:1902.08091doi.org
  11. Alwin Zulehner, Alexandru Paler, Robert Wille (2019). An Efficient Methodology for Mapping Quantum Circuits to the IBM QX Architectures. IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 38, 1226-1236. doi:10.1109/TCAD.2018.2846658arXiv:1712.04722
  12. D. Maslov, G. W. Dueck, D. M. Miller, C. Negrevergne (2008). Quantum Circuit Simplification and Level Compaction. IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 27, 436-444. doi:10.1109/TCAD.2007.911334
  13. Yunseong Nam, Neil J. Ross, Yuan Su, … Dmitri Maslov (2018). Automated optimization of large quantum circuits with continuous parameters. npj Quantum Information 4, 23. doi:10.1038/s41534-018-0072-4arXiv:1710.07345
  14. Raban Iten, Romain Moyard, Tony Metger, … Stefan Woerner (2022). Exact and Practical Pattern Matching for Quantum Circuit Optimization. ACM Transactions on Quantum Computing 3, 1-41. doi:10.1145/3498325arXiv:1909.05270
  15. Christopher M. Dawson, Michael A. Nielsen (2006). The Solovay-Kitaev algorithm. Quantum Information and Computation 6, 81-95. doi:10.26421/QIC6.1-6arXiv:quant-ph/0505030
  16. Neil J. Ross, Peter Selinger (2016). Optimal ancilla-free Clifford+T approximation of z-rotations. Quantum Information and Computation 16(11-12), 901-953. arXiv:1403.2975
  17. Matthew Amy, Dmitri Maslov, Michele Mosca (2014). Polynomial-time T-depth Optimization of Clifford+T circuits via Matroid Partitioning. IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 33, 1476-1489. doi:10.1109/TCAD.2014.2341953arXiv:1303.2042
  18. Michael A. Nielsen, Isaac L. Chuang (2010). Quantum Computation and Quantum Information (10th Anniversary Edition). Cambridge University Press. doi:10.1017/CBO9780511976667
  19. A. Yu. Kitaev (1997). Quantum computations: algorithms and error correction. Russian Mathematical Surveys 52, 1191-1249. doi:10.1070/RM1997v052n06ABEH002155
  20. A. Yu. Kitaev, A. H. Shen, M. N. Vyalyi (2002). Classical and Quantum Computation. Graduate Studies in Mathematics 47, American Mathematical Society. doi:10.1090/gsm/047
  21. Greg Kuperberg (2023). Breaking the cubic barrier in the Solovay-Kitaev algorithm. arXiv:2306.13158
  22. Peter Selinger (2015). Efficient Clifford+T approximation of single-qubit operators. Quantum Information and Computation 15, 159-180. doi:10.26421/QIC15.1-2-10arXiv:1212.6253

Contributors

  • KetQat maintainers · @ketqatConceptualization; Supervision (CRediT roles)
  • Claude (AI drafting assistant)Writing, original draft (CRediT roles)

Review history

  1. Automated source check · Pass · 2026-12-01 · Independent automated verification pass (AI, not the drafting session)

    Topic body checked; embedded records carry their own review states. Recomputed: CNOT lower bound values 3, 14, 61, 252 (n=2..5) and 252 x 1e-3 = 0.25; the CZ magic-basis example on |11> and |01> (verified numerically in the Cartan proof check); layout example CNOT counts 5 vs 2 and the bridge alternative; T CNOT T = CNOT S on the control. Sources: Shende-Markov-Bullock arXiv quant-ph/0308033 Prop. III.1 (about 4^n/4 CNOTs); QSD O(4^n) in Shende-Bullock-Markov arXiv quant-ph/0406176 eq. (19); Botea-Kishimoto-Marinescu SoCS 2018 abstract (NP-completeness of a makespan formulation); SABRE reverse-traversal layout (arXiv 1809.02573 abstract); A* in Zulehner et al. arXiv 1712.04722; Ross-Selinger arXiv 1403.2975 and Dawson-Nielsen arXiv quant-ph/0505030 abstracts; other citations as in the embedded records.

Revision history

  1. 2026-12-01Content release 2.1.0: 35 more topics, an independent source check of every record, intake hardening (#17)80537b7e

Current revision a875cd86e783b3e1. Source file knowledge/records/topic/quantum-compilation.md in the content repository (readable there once it is public).