NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

QEMI: A Quantum Software Stacks Testing Framework via Equivalence Modulo Inputs

Junjie Luo, Shangzhou Xia, Fuyuan Zhang, Jianjun Zhao

TL;DR

QEMI (Quantum Equivalence Modulo Inputs) is the first framework to adapt the classical compiler testing technique "EMI" to the quantum realm. By statically injecting and removing guaranteed dead code blocks within complex quantum control-flow structures, QEMI bypasses the quantum oracle problem to find critical compiler bugs. The framework successfully uncovered 12 real-world bugs across major quantum software stacks, including Qiskit, Cirq, and Q#.

What Problem Does This Paper Address?

Testing Quantum Software Stacks (QSSes)—the tools responsible for compiling and executing quantum circuits—is notoriously difficult due to the oracle problem. Because quantum outputs are inherently probabilistic, it is highly challenging to establish a reliable ground truth to verify if a program compiled correctly.

While existing metamorphic testing tools attempt to solve this by applying structural transformations (like replacing gates with equivalent combinations), they largely focus on simple, flat circuits. They struggle with language-level semantic equivalence and complex quantum control flow—such as loops and conditional branches that depend on quantum states or measurement outcomes. This leaves a massive blind spot where optimization and API-specific bugs can easily hide.

Two types of quantum conditions: (a) a quantum control gate where a qubit directly controls an operation, and (b) a quantum dynamic circuit where a classical register holds a measurement outcome used as a conditional input.

Methods

The authors introduce QEMI, a framework that brings Equivalence Modulo Inputs (EMI) to quantum computing. In classical testing, EMI creates program variants by modifying "dead code" (code that never executes for a given input). However, because quantum states exist in superpositions, dynamic execution profiling cannot reliably identify dead code—a path that seems dead in one run might execute in the next.

To overcome this, QEMI uses a novel static, pattern-based approach:

  1. Random Program Generation with Dead Code: QEMI generates random quantum programs containing advanced control-flow structures (like if_test, while_loop, and switch). It forces specific blocks to become dead code using two strategies:
  2. Input-independent: Utilizing language semantics (e.g., placing code immediately after a break_loop() or continue_loop()).
  3. Input-dependent: Explicitly preparing a deterministic quantum state beforehand (e.g., initializing a register to $|1\rangle$ so that an if (condition == 0) block is guaranteed never to execute).
  4. EMI Variant Generation: A static analysis pass strips away this guaranteed dead code, producing a semantically identical variant program.
  5. Adaptive Execution and Behavior Checking: Both the original and variant programs are executed. To avoid the massive computational overhead of running thousands of shots to compare probabilistic distributions, QEMI introduces a Hellinger-distance-based early termination strategy. It iteratively checks distribution convergence and stops early if the variants match with high statistical confidence.

Datasets

Not discussed in the paper. The framework evaluates QSS implementations directly by generating synthetic random programs rather than using pre-existing code benchmarks.

Key Insights and Ideas

  • Taming Quantum Randomness Statically: Instead of trying to dynamically track code coverage in a probabilistic environment, QEMI elegantly forces determinism at the control-flow level by carefully preparing initial quantum states.
  • Control Flow is a Major Blind Spot: The paper reveals that modern QSS optimization passes frequently break when encountering operations nested inside quantum control-flow blocks. For example, compilers often fail to properly decompose gates or validate analysis passes when classical and quantum control logic mix.
  • Statistical Testing Doesn't Have to Be Expensive: By leveraging the prior knowledge that the two variants should be identical, the adaptive sampling strategy proves that you don't need a massive, fixed-shot budget to confidently validate distribution equivalence.

Key Results

  • Real-World Bug Discovery: QEMI uncovered 12 unique, real-world bugs across the latest versions of major quantum stacks: 8 in Qiskit, 3 in Cirq, and 1 in Q#. These included 11 crash bugs and 1 critical behavioral inconsistency (a gate queueing optimization bug in Q# that altered output distributions). As of the paper's publication, 7 bugs have been fixed and 4 confirmed by upstream developers.
  • Higher Code Coverage: In a 24-hour test on Qiskit, QEMI achieved 14.80% code coverage, outperforming established baselines like QDiff (6.24%) and MorphQ (9.58%), and slightly edging out QuteFuzz (14.18%).
  • Significant Speedups: The early termination strategy dramatically reduced measurement overhead, yielding a 53.83% speedup for 6-qubit circuits and a 72.21% speedup for 8-qubit circuits compared to standard theoretical fixed-shot baselines.

Limitations and Future Work

  • Simulator Constraints: Due to classical hardware limitations, the evaluation was restricted to simulators running circuits with up to 8 qubits. The authors note that testing on real quantum hardware will introduce physical device noise, which may complicate distribution comparisons.
  • Pattern-Based Reliance: QEMI currently relies on predefined, hardcoded dead-code templates.
  • Future Directions: The authors plan to develop automated data-flow and control-flow analysis tools to detect arbitrary dead code across quantum-classical boundaries. They also aim to move beyond simple dead-code removal toward richer, semantics-preserving mutations within dead regions to catch even subtler compiler defects.

Summary updated

BibTeX
@inproceedings{luo2026qemi,
  author = {Junjie Luo and Shangzhou Xia and Fuyuan Zhang and Jianjun Zhao},
  title = {{QEMI: A Quantum Software Stacks Testing Framework via Equivalence Modulo Inputs}},
  booktitle = {FASE},
  year = {2026},
  doi = {10.1007/978-3-032-22774-4\_8},
}
Figure