arXiv:2611.08220quant-phNov 2026

Manuscript Offprint

arXiv:2611.08220

QDiff: Differential Testing of Quantum Software Stacks

Jiyuan Wang, Qian Zhang, Guoqing Harry Xu, Miryung Kim

Jiyuan Wang, Qian Zhang, Guoqing Harry Xu, Miryung Kim

University of California, Los Angeles

CA, United States

{wangjiyuan, zhangqian, harryxu, miryung}@cs.ucla.edu

Abstract—Over the past few years, several quantum software stacks (QSS) have been developed in response to rapid hardware advances in quantum computing. A QSS includes a quantum programming language, an optimizing compiler that translates a quantum algorithm written in a high-level language into quantum gate instructions, a quantum simulator that emulates these instructions on a classical device, and a software controller that sends analog signals to a very expensive quantum hardware based on quantum circuits. In comparison to traditional compilers and architecture simulators, QSSes are difficult to tests due to the probabilistic nature of results, the lack of clear hardware specifications, and quantum programming complexity.

This work devises a novel differential testing approach for QSSes, named QDIFF with three major innovations: (1) We generate input programs to be tested via semantics-preserving, source to source transformation to explore program variants. (2) We speed up differential testing by filtering out quantum circuits that are not worthwhile to execute on quantum hardware by analyzing static characteristics such as a circuit depth, 2-gate operations, gate error rates, and T1 relaxation time. (3) We design an extensible equivalence checking mechanism via distribution comparison functions such as Kolmogorov-Smirnov test and cross entropy.

We evaluate QDIFF with three widely-used open source QSSes: Qiskit from IBM, Cirq from Google, and Pyquil from Rigetti. By running QDIFF on both real hardware and quantum simulators, we found several critical bugs revealing potential instabilities in these platforms. QDIFF's source transformation is effective in producing semantically equivalent yet not-identical circuits (i.e., 34% of trials), and its filtering mechanism can speed up differential testing by 66%.

I. INTRODUCTION

Quantum computing is an emerging computing paradigm that promises unique advantages over classical computing. However, quantum programming is challenging. Quantum computation logic is expressed in qubits and quantum gates, and the states of quantum registers are measured probabilistically. Due to the physical properties of quantum mechanics, qubits and quantum gates are fundamentally different from classical bits and gate logic. For example, quantum indeterminacy dictates that the same quantum program can produce different results in different executions.

To this end, many quantum software stacks such as Google's Cirq [1], Rigetti's Pyquil [2], and IBM's Qiskit [3] have been developed to provide user-friendly high-level languages for quantum programming, abstracting away the underlying physical and mathematical intricacies.

A quantum software track (QSS) includes (1) APIs and language constructs to express quantum algorithms, (2) a compiler that transforms and optimizes a given input quantum algorithm at the circuit level, and (3) a backend executor that either simulates the resulting gates on classical devices or executes directly on quantum hardware. Consider Qiskit [4], which consists of four components: QiskitTerra that compiles and optimizes programs, QiskitAer that supports high-performance noisy simulations, QiskitIgnis for error correction, noise characterization, and hardware verification, and QiskitAqua that helps a developer to express a quantum algorithm or an application. Other QSSes [2] such as Pyquil have a similar set of components—e.g., Pyquil uses quilc as a compiler and qvm as a quantum simulator.

As with any compiler framework, a QSS could be error-prone. Developers and users often report bugs on popular QSSes [3], [5], [6], and a simple search on StackOverflow with the keyword “quantum error” would bring up over 500 posts on various QSS components, ranging from compiler settings, simulation, and the actual hardware [7]. These posts often reveal deeper confusion that developers face due to the inherent probabilistic nature of quantum measurements—if a program produces a result that looks different from what is expected, is it due to a bug or the non-determinism inherent in quantum programs? Is there divergence beyond expected noise coming from an input program, a compiler, a simulator, and/or hardware?

Challenges. There are three technical challenges that make it difficult to test QSSes.

The first challenge is how to generate semantically equivalent programs for testing quantum compilers [8], [9]. Though existing compiler testing techniques generate equivalent programs by manipulating code in dead regions or unexecuted branches [10], a quantum program usually does not have many unexecuted branches. Therefore, we must design a technique that can produce a large number of semantically-equivalent variant circuits that may induce divergence on hardware.

The second challenge is that compilers are not the only source of bugs in a QSS. For example, in a line of recent work [11], [12] on verified quantum compilers, compilers are guaranteed to be correct with respect to their optimization and transformation rules. However, the overall correctness of

QSSes goes beyond compiler optimization rules. We must reason about subsequent execution on quantum simulators and hardware, which are often the major sources of instabilities. In fact, Rigetti or Cirq's Github histories indicate that bugs may come from its various backends due to improper initialization [13], problematic APIs [14], or inappropriate synthesis options [15].

The third challenge is how to interpret measurements from quantum simulators or hardware, since quantum measurement operations by definition are probabilistic in nature due to quantum indeterminacy [11]. Therefore, when we execute logically equivalent program variants, comparing their measurement results is not straightforward, as we must take into account inherent noise (e.g., hardware gate errors, readout errors, and decoherence errors) and must determine whether the observed divergence is significant enough to be considered as a meaningful instability.

This Work. QDIFF is a novel differential testing technique for QSSes. QDIFF takes as input a seed quantum program and reports potential bugs with a pair of witness programs (i.e., logically equivalent programs that are supposed to produce identical behavior) but triggers divergent behavior on the target QSS (i.e., meaningful instabilities beyond expected noise). QDIFF overcomes the aforementioned challenges with three technical innovations below.

First, QDIFF generates logically equivalent quantum programs using a set of equivalent gate transformation rules. This is based on the insight that each quantum gate can be represented mathematically as a unitary matrix; a sequence of gates essentially corresponds to the multiplication of their unitary matrices, which also yields a unitary matrix. As such, one sequence of gates is semantically equivalent to another if the two sequences yield the same unitary matrix. We leverage seven gate transformation rules to generate different gate sequences that are guaranteed to yield the same unitary matrix. These sequences essentially define logically equivalent program variants that are supposed to yield identical behavior. Such variants are then executed on a simulator or hardware and their measurements are compared.

Second, with multiple logically equivalent variants generated after optimization, QDIFF selects a subset of those circuits that are worthwhile to run on a noisy simulator or quantum hardware. This selection and filtering process is crucial for both speedup and potential cost saving, because there are only a very few quantum hardware devices in the world, and they are extremely expensive resources—D-wave's quantum computer is reported to be $15 million in 2017 [16]. IBM Qiskit allows public hardware access up to 5 qubits, but a higher number of qubit usage is strictly restricted. Noisy simulators are extremely compute-intensive to run on classical computers as well, taking on more than 4 minutes to do 3000 measurements on a simple four-qubit circuit. This noisy simulation cost becomes extremely unmanageable with the higher number of qubits.

To achieve speed up, QDIFF analyzes the static characteristic of logically equivalent circuits such as the circuit depth (i.e., moments), the number of 2-qubit gates, the known error rates of each gate kind, and T1 relaxation time for quantum hardware. QDIFF obviates the need of executing certain circuits on hardware or noisy simulators, if the logically equivalent circuits are incapable of revealing meaningful instabilities in QSS.

Third, in order to compare executions of logically equivalent circuits, QDIFF first identifies how many measurements are needed for reliable comparison. Based on the literature of distribution sampling, QDIFF adapts closeness testing in L1 norm [17] to estimate the required number of measurements given confidence level p=2/3p = 2/3. Using either a noisy simulator or directly on hardware, it then performs the required number of measurements. To compare two sets of measurements, QDIFF uses distribution comparison methods. Two methods based on Kolmogorov-Smirnov (K-S) test [18], [19] and Cross Entropy [20], [21] are currently supported. This comparison method is easily extensible in QDIFF, as a user can define a new statistical comparison method [17] in QDIFF.

Results. We evaluated QDIFF with the latest versions of three widely-used QSSes: Qiskit, Cirq, and Pyquil. With six seed quantum algorithms, QDIFF generates 730 variant algorithms through semantics-modifying mutations. Starting from the generated algorithms, it generates a total of 14799 program variants using semantics-preserving source transformations. This generation process took QDIFF 14 hours. With the filtering mechanism, QDIFF reduces its testing time by 66%. Using QDIFF, we determined total 6 sources of instabilities. These include 4 software crash bugs in Pyquil and Cirq simulation, and 2 potential root causes that may explain 25 out of 29 cases of divergence beyond expected noise on IBM hardware.

The main contributions of this work include:

  • We present the first differential testing framework for QSSes. This framework is integrated with three widely used QSSes from Google, IBM, and Rigetti.

  • We embody three technical innovations in QDIFF to make differential testing fast and to increase the chance of finding meaningful instabilities beyond the usual expected noise: (1) auto-generation of logically equivalent variants, (2) auto-filtering of circuits that are worthwhile to run on hardware (or a noisy simulator), and (3) pluggable methods of comparing measurements in terms of statistical distribution. QDIFF obviates the need of invoking quantum back-ends by 66%. Using QDIFF, we determined 6 sources of instabilities in three widely used QSSes: 4 crash bugs and 2 root causes for divergences beyond expected noise on IBM hardware.

We provide access to the artifacts of QDIFF at https://github.com/wjy99-c/QDiff.

References (62)