Overview
Quantum programs pass through a toolchain before they reach a device: a language or library, an intermediate representation (IR), a series of compiler passes, and a back end that emits control instructions. Quantum software engineering asks how to make this toolchain interoperable, correct and testable. Three themes dominate.
- Representations. Open standards let languages and devices meet in the middle. OpenQASM 3 extends a circuit assembly language with real-time classical control, timing and pulse-level calibrations (Cross et al.); QIR embeds quantum programs in LLVM IR and defines profiles of supported features (QIR specification).
- Verification and testing. Compilers rewrite circuits aggressively, and a wrong rewrite produces plausible but wrong outputs. Equivalence checking compares circuits (Burgholzer and Wille); formally verified compilers prove their passes correct in a proof assistant (Hietala et al.). In general, deciding approximate equivalence is QMA-complete (Janzing, Wocjan and Beth).
- Simulation. Classical simulators are the reference against which programs are tested; their cost grows exponentially with qubit number in general and polynomially for restricted classes such as stabilizer circuits (Aaronson and Gottesman) or circuits of small treewidth (Markov and Shi).
Intuition
Classical software engineering relies on running a program and inspecting its state. Quantum programs resist both: inspecting the state destroys it, and a run returns one sample from a distribution. Tests therefore become statistical (do the observed frequencies match the expected distribution within error bars?) or move to a simulator, where the full state can be inspected but only for small instances.
Compilers make the problem sharper. A single compiled circuit may be the output of dozens of passes, each of which must preserve the unitary (often up to phase and qubit permutation). Because checking that two circuits agree is as hard as general quantum verification, the practical answer is layered: exact checks for structured pieces (Clifford parts, small blocks), heuristic checks for the rest, and proofs of correctness for the rewrite rules themselves.
Prerequisites
The circuit model, the Clifford group and stabilizer formalism, QMA for the complexity statements, and an outline of quantum compilation. The lesson circuits and simulation shows state-vector simulation at small scale.
Mathematical Definitions
An intermediate representation (IR) for quantum programs is a format, with defined syntax and semantics, that front ends (languages, circuit libraries) emit and back ends (compilers for specific devices, simulators) consume, so that languages and targets need translators rather than . Two open standards are widely used.
OpenQASM 3 (Cross et al.;
specification) is a textual language. Its gate semantics rest on
two built-in gates, the single-qubit and the global phase
; further gates are defined hierarchically or by modifiers such as
ctrl @, negctrl @ and inv @. Beyond circuits it adds classical types and arithmetic, branching
and loops on measurement results that must execute within the qubits' coherence time, subroutines and
extern calls, timing types (duration, stretch) with delay, box and barrier, and
defcal blocks that attach pulse-level implementations, in a selectable pulse grammar, to gates and
measurements on specific physical qubits. A gate definition fixes a unitary, not how the hardware
implements it.
QIR (specification) defines quantum programs as LLVM IR: qubits and results are opaque pointers, quantum operations are calls to functions of a quantum instruction set that the target chooses, and classical code is ordinary LLVM. Because targets differ widely, QIR defines profiles, coherent subsets that a back end declares it supports. The Base Profile requires only a sequence of quantum instructions followed by measurement of the qubits at the end; the Adaptive Profile adds mid-circuit measurement, conversion of results to booleans, and nested forward branching on them, with loops and further features as optional capabilities.
The two are complementary: OpenQASM 3 reads like an assembly language for circuits with real-time control, QIR reuses classical compiler infrastructure for analysis and optimisation.
- The descriptions of OpenQASM 3 and QIR follow their public specifications as accessed on 2026-12-01; both are living standards and later versions may differ.
Given circuits on qubits with unitaries :
- Exact equivalence: .
- Equivalence up to global phase: for some , equivalently is a multiple of the identity. This is the relevant notion for whole programs, but not for subcircuits that may later be controlled.
- Approximate equivalence: in operator norm, for a tolerance , as needed when rotations are synthesised approximately.
- Equivalence on a subspace or up to permutation: restrictions to an invariant subspace (for example with ancillas starting in ), or equality after a known relabelling of qubits (as left by routing).
Equivalence checking decides one of these relations from the circuit descriptions. Because is implemented by the circuit , every version reduces to an identity check. In its approximate form with a promise gap, deciding whether a circuit is far from every multiple of the identity (the yes case) or close to one is QMA-complete (Janzing, Wocjan and Beth); practical tools therefore use methods that work well on circuits produced by compilers, such as ZX-calculus rewriting, or decision diagrams combined with simulation of random inputs and with alternating gates of and so that intermediate representations stay close to the identity (Burgholzer and Wille).
Theorems
How hard is verification?
Given a circuit with unitary , decide whether is close to in operator norm for some (output "identity") or far from every such multiple (output "non-identity"), under the promise that one of the two holds. Janzing, Wocjan and Beth show that the "non-identity" side of this problem is QMA-complete, and that the more general equivalence check, whether two circuits almost coincide on a given common invariant subspace, is QMA-complete as well. Membership is intuitive: a witness is an input state that moves far from itself (up to phase), which a verifier can test. Hardness comes from encoding a QMA verification circuit into a unitary that is far from the identity exactly when some witness is accepted.
For practice the theorem means that no efficient algorithm is expected for general circuit equivalence; efficient methods exist only for restricted classes, such as Clifford circuits.
- The input is a classical description of a polynomial-size circuit from a fixed universal gate set; the problem is a promise problem with thresholds whose gap is at least an inverse polynomial in the input size, as specified in the cited paper.
Let be Clifford circuits with and gates and unitaries . Then for some if and only if
where both sides are signed Pauli strings. The conjugated generators, with their signs, form the stabilizer tableau of the circuit, which can be computed by updating bits per gate (Aaronson and Gottesman). Equivalence is therefore decided in time . The tableau formalism goes back to the Heisenberg-picture description of stabilizer circuits by Gottesman.
- Circuits on qubits built from H, S and CNOT gates (any Clifford gate set compiles to these with constant overhead per gate).
- Equivalence means equality up to a global phase.
Proof · Proof that Clifford circuit equivalence is efficient
Only if. If , the phases cancel in .
If. Put . The hypothesis gives , i.e. , for each generator , hence for every product of generators, which (up to phases) are all Pauli strings. The Pauli strings form a basis of the space of complex matrices, so commutes with every matrix. Taking the matrix units : applied to gives for all , so is diagonal with all diagonal entries equal, . Since is unitary, , so and .
Algorithm. Represent a signed Pauli string on qubits by bits and a sign bit. Starting from the identity tableau (row is , row is ), apply the gates of in order, conjugating every row: H, S and CNOT map each Pauli string to another one with a sign given by a simple Boolean formula, and only the columns of the one or two qubits the gate touches change, so each gate costs operations on the rows (Aaronson and Gottesman). Do the same for and compare the two tableaux, bits. The total time is .
How far can simulators go?
A pure state of qubits is a unit vector in , so storing it takes bytes. A -qubit gate acts on the vector as independent products of a matrix with a -vector, one for each setting of the other qubits, i.e. multiply–adds, and it must read and write every amplitude. With : gives bytes GiB; gives TiB; gives bytes TiB, consistent with the roughly half-petabyte memory used for the 45-qubit simulation of Häner and Steiger; gives PiB. Each additional qubit doubles memory and time. Density-matrix simulation of mixed states squares the dimension, bytes. Simulators that avoid the full vector (stabilizer, tensor-network, low-rank) trade this exponential for others tied to circuit structure.
- Pure-state simulation storing every amplitude; bytes per complex amplitude ( for two double-precision floats); a dense -qubit gate given as a matrix.
Let a circuit on qubits begin in and consist of operations, each a Clifford gate on at most two qubits, a measurement of on one qubit, or a Clifford gate applied conditionally on earlier outcomes. Then a classical algorithm samples the outcomes of all measurements with exactly the probabilities given by quantum mechanics, using elementary operations per gate and per measurement, so in total.
At every stage the state is a stabilizer state: the unique state fixed by an abelian group with independent generators and (a stabilizer code with ). The algorithm stores the generators as a binary matrix with sign bits, the stabilizer tableau, and every measurement outcome is either deterministic or uniformly random.
The theorem is due to Gottesman, who credits Knill (Gottesman); it is section 10.5.4 of Nielsen and Chuang. Aaronson and Gottesman add the destabilizer generators to the tableau, which removes the Gaussian elimination and brings the cost of a measurement down to at the price of doubling the storage. They also show that simulating stabilizer circuits is complete for the classical complexity class , so it is believed to be strictly weaker than general polynomial-time classical computation.
- The circuit acts on qubits initialised in .
- Its operations are Clifford gates (, , CNOT, or any gate given by its action on Pauli operators), measurements of single-qubit (equivalently, of any Pauli operator), and gates chosen as functions of earlier outcomes.
- Simulation means sampling the joint distribution of measurement outcomes exactly, given access to unbiased random bits.
Proof · Proof of the Gottesman–Knill theorem
Stabilizer states are determined by their generators. If is abelian, and has independent generators, the dimension theorem with says that fixes a one-dimensional subspace, so it determines a unique state up to phase. Moreover the normalizer equals : in the binary representation, the span of the generators is isotropic of dimension , and has dimension and contains , so . Hence a Pauli operator that commutes with all of is for some , and since only one of lies in .
Initial state. is stabilized by .
Gates. If then , so is the stabilizer state with generators . These are again Pauli operators, independent and commuting because conjugation is an automorphism. For a gate on at most two qubits, each differs from only on those qubits and in its sign, and the new entries and sign follow from a fixed table (for , , CNOT, the table in the Clifford group record). Updating all generators costs .
Measurement of , random case. Suppose some generator, say , anticommutes with . Multiplying every other generator that anticommutes with by gives a generating set of the same group in which only anticommutes with ; this costs per generator, in all. Then
so and each outcome , , has probability . The post-measurement state is proportional to . It is fixed by and, because commutes with , by every . These operators commute, are independent (the are independent, and the vector of is not in their span because anticommutes with whereas every element of commutes with ), and their group does not contain because they fix a nonzero vector. So the simulator draws a fair random bit and replaces by .
Measurement of , deterministic case. Suppose commutes with every generator. By the first paragraph for exactly one , so and the outcome is with certainty; the state does not change. To find , solve over for the binary vector of by Gaussian elimination, operations, then multiply the generators with in order, tracking the overall phase; each product of two Pauli operators and its phase costs , so this step costs . The resulting product is .
Classical control and sampling. A conditional gate is simulated by evaluating the condition on the outcomes already sampled and applying the gate update if required. Processing the operations in order, each measurement outcome is drawn from its exact conditional distribution given all previous outcomes, so the joint distribution of the sampled outcomes is the quantum one. The total cost is per gate and per measurement.
Measuring a general Pauli operator reduces to the same two cases with in place of : it is random exactly when anticommutes with a generator. The argument is that of Gottesman, presented as in section 10.5 of Nielsen and Chuang; Aaronson and Gottesman replace the Gaussian elimination by maintaining destabilizer generators, which gives per measurement.
Let be a quantum circuit with gates whose underlying graph has treewidth . Then can be simulated by a deterministic classical algorithm in time
which is polynomial in when (Markov and Shi). The algorithm views the circuit as a tensor network and contracts it in an order derived from a tree decomposition; the cost of the best contraction order is exponential in the treewidth of the line graph of , which is within constant factors of the treewidth of for bounded-degree graphs.
Two consequences stated by the authors: circuits of depth whose gates act only on nearby qubits have logarithmic treewidth and are classically simulable; and a one-way (measurement-based) computation on a graph state of treewidth can be simulated by a randomized algorithm in time .
- Circuits of gates, each acting on a bounded number of qubits; the underlying graph has a vertex per gate (and per input and output) and an edge per wire segment.
- The simulation computes output amplitudes or probabilities to within numerical precision; treewidth is of the circuit's graph, not of any qubit layout.
Worked Examples
Real-time feed-forward in OpenQASM 3
The following program prepares a Bell pair, measures the first qubit, and conditionally flips the second within the same shot:
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
h q[0];
cx q[0], q[1];
c[0] = measure q[0];
if (c[0]) { x q[1]; }
c[1] = measure q[1];
After the measurement the second qubit is in , and the conditional maps it to , so
c[1] is in every shot while c[0] is uniformly random. A test can therefore assert a
deterministic property, c[1] == 0, instead of comparing distributions. The branch must execute
while q[1] is coherent; in QIR terms the program needs the Adaptive Profile (mid-circuit measurement
and branching on its result), not the Base Profile (QIR specification).
Checking a CNOT reversal with tableaux
Is equal to ? Conjugate the generators through the three layers (H swaps and ; maps , and fixes ):
| input | after | after | after |
|---|---|---|---|
The last column is exactly the tableau of (control 2 copies onto qubit 1 and onto qubit 2), with all signs . By the Clifford equivalence theorem the two circuits are equal up to a global phase, checked with 16 table entries instead of two matrix products.
Memory budgets for simulators
By the state-vector cost, a laptop with 32 GiB holds at most qubits in double precision ( bytes GiB, with nothing left over), so 30 qubits is a practical limit. A stabilizer simulator stores a tableau of about bits: for qubits that is about bits MB, which is why stabilizer simulators such as Stim (Gidney) handle error-correction circuits with thousands of qubits, while a single non-Clifford gate takes the circuit outside their scope.
Algorithms and Implementations
- State-vector simulators store all amplitudes and apply gates as sparse updates; distributed versions split the vector across nodes and minimise communication.
- Stabilizer simulators update tableaux in time polynomial in (Aaronson and Gottesman); sampling-oriented implementations are optimised for error-correction workloads (Gidney).
- Tensor-network simulators contract the circuit as a network; cost is exponential in the treewidth of the circuit graph rather than in (Markov and Shi), and the tensor networks page treats contraction ordering.
- Equivalence checkers combine decision diagrams, rewriting and simulation with random inputs (Burgholzer and Wille); ZX-calculus rewriting provides another complete method.
- Verified compilation: VOQC expresses circuits in a small IR embedded in the Coq proof assistant and proves each optimisation correct with respect to a matrix semantics (Hietala et al.).
Computational Complexity
Approximate equivalence of general circuits, with an inverse-polynomial promise gap, is QMA-complete, so it is not expected to be efficiently decidable even with a quantum computer; Clifford equivalence is in polynomial time. Strong simulation of general circuits takes exponential time with known methods, with the exceptions above. These two facts are linked: if a circuit class is closed under inversion, composition and the addition of Bell-pair preparations, an efficient strong simulator for it gives an efficient equivalence check, because the amplitude on a maximally entangled state of qubits has modulus exactly when .
Limitations and Common Pitfalls
- Phase and permutation conventions. Many false alarms in equivalence checking come from global phases, qubit-ordering conventions (big- versus little-endian) and the output permutation left by routing. State them explicitly in tests.
- Shots are samples. A test that compares measured frequencies needs a statistical criterion and enough shots; a pass at 100 shots says little about a 1 percent bias.
- Simulators lie about noise. A program verified on an ideal simulator can fail on hardware for reasons the simulator does not model; noisy simulation needs an explicit noise model.
- Specifications evolve. OpenQASM 3 and QIR are living specifications; a program valid for one version or profile may not be accepted by a back end implementing another.
- Verified passes, unverified pipeline. A proof covers the passes inside the verified tool, not the parser, the hardware calibration or the code that calls it.
State of the Art
As of 2026-11, from the cited sources:
- 2017: a 45-qubit circuit was simulated in full state-vector form on a supercomputer using 8,192 nodes and about 0.5 petabytes of memory (Häner and Steiger).
- 2021: VOQC, a circuit optimizer whose optimisations are proved correct in Coq, was presented (Hietala et al.); Stim, a stabilizer simulator for error-correction circuits, was published (Gidney).
- 2022: the OpenQASM 3 language paper was published (Cross et al.); the language is maintained as a live specification (OpenQASM).
- QIR's current specification (accessed 2026-12-01) defines version 2.0 on LLVM opaque pointers, compatible with LLVM 16 and later, and the Base and Adaptive profiles (QIR specification).
Related Research
Compiler passes whose correctness is at stake are on quantum compilation and Clifford+T synthesis; the complexity background is on quantum complexity theory; classical simulation by tensor contraction is on tensor networks.