arXiv:2610.11195quant-phOct 2026

Manuscript Offprint

arXiv:2610.11195

Retromorphic Testing of Quantum Compiler Passes

Mushahid Khan, Olivia Di Matteo

Mushahid Khan and Olivia Di Matteo

Electrical and Computer Engineering and Stewart Blusson Quantum Matter Institute

The University of British Columbia

Vancouver, Canada

mkhan103@student.ubc.ca, olivia@ece.ubc.ca

Abstract—Quantum compilers play a critical role in transforming high-level quantum programs into optimized, hardware-compatible circuits. However, verifying the correctness of compiler passes remains challenging, as determining the expected output of large, deeply entangled quantum circuits is computationally intractable. This challenge is further amplified when compiler passes modify already complex circuit structures, making manual validation of transformed circuits impractical.

In this work, we perform a systematic analysis of unit tests for quantum compiler passes in four quantum programming frameworks (PennyLane, Qiskit, Cirq, and pytket). Our findings indicate validation is dominated by program-content and program-metric assertions, and test circuits are generally small and shallow. Motivated by these observations, we introduce a testing methodology for automated validation of quantum compiler passes based on retromorphic testing and principles from the Hadamard test. This methodology analyzes a compiler pass, test circuit, and expected pass behavior to verify semantic preservation and intended structural modifications.

We implement our methods in a framework, RetroQ, and apply it to compiler passes in PennyLane and Qiskit. Experimental evaluation reproduced several existing bugs as well as uncovered previously undetected defects, such as flawed symbolic parameter handling, incorrect commutation logic, failure to recognize self-adjointness of gates, and runtime crashes. These findings highlight the need for compiler-pass-specific testing methodologies to improve the reliability of the evolving quantum software stack.

I. INTRODUCTION

Quantum computing represents a paradigm shift in computational power, promising to solve problems in applications such as cryptography and materials science that are intractable for classical systems [1], [2]. However, the path from a high-level quantum algorithm to a physical result on hardware is complex and requires dedicated quantum software engineering methods [3]–[5]. A key part of this quantum software stack is the quantum compiler, which transforms high-level programs into optimized, hardware-compatible circuits through a series of passes or transformations. Compilation passes reduce target metrics, often circuit depth and gate count, with optimizations such as unitary gate unification (which merges operations) and gate cancellation (which removes gates followed by their adjoints), while ensuring compatibility with specific hardware constraints through qubit mapping and gate scheduling.

Compiler passes are generally equivalence-preserving, meaning the output remains unchanged despite structural optimizations. Validation can be performed with equivalence checking, a low-level method that involves comparing matrix representations of two circuits [6], [7]. This is distinct from higher-level formal verification methods, such as Quantum Hoare Logic [8], which demonstrate that a circuit meets its intended mathematical specifications. Both approaches, however, face significant hurdles [6], [8]–[10], such as the exponential growth of the state space, making it extremely difficult to classically simulate or mathematically model the behavior of large quantum circuits. As a result, developers must pivot to more accessible validation and debugging techniques, such as unit testing, to verify compiler passes. However, unit testing is hindered by the test oracle problem, a long-standing bottleneck in classical software and compiler testing that arises because of system complexity and a lack of clear specifications.

The test oracle problem is the challenge of distinguishing a system's valid, desired output from incorrect behavior for any given input. This problem is complicated in quantum programming due to limited human intuition regarding features such as superposition and entanglement [9]. While unit tests may verify simple cases, they may fail to provide coverage for large, entangled circuits for which determining the expected output is computationally intractable. This difficulty is often heightened by the compound nature of quantum bugs, which typically occur at the intersection of multiple categories [9].

Black-box testing techniques [11] provide a natural way to address the test oracle problem by evaluating program behavior without knowledge of the internal structure. This raises the question of whether it can be used to reliably verify the correctness of quantum compiler passes when manual oracles are computationally intractable for large circuits and formal verification remains complex. To address this problem, we formulate the following research questions (RQ#):

• RQ1: How are quantum compiler passes currently tested and validated, and to what extent are existing approaches sufficient for ensuring their correctness?

• RQ2: How can black-box testing techniques verify quantum compiler passes without explicit computation of the expected circuit output?

• RQ3: What types of compiler pass errors are not captured by existing testing and verification approaches?

To answer these research questions, we developed a testing framework called RetroQ. RetroQ leverages retromorphic testing [12], a black-box methodology inspired by inverse function reasoning, the principles underlying the Hadamard test [13], and knowledge of the expected behavior of the compiler pass to systematically validate compiler correctness. Although implemented with support for testing the PennyLane [14] and Qiskit [15] frameworks, the proposed methodology can be applied to compiler transformations in any framework. It is also generalizable beyond compiler passes to other classes of quantum software: because quantum operations are unitary and reversible, retromorphic testing can be used to verify quantum arithmetic modules, uncomputation subroutines, or encoding circuits in quantum error correction.

RetroQ allows users to input a set of compiler passes along with a target quantum function and expected behavior of each compiler pass, enabling automated evaluation of each compiler pass's behavior without manual derivation of expected outputs. Experimental evaluation revealed correctness issues in quantum compiler passes in PennyLane and Qiskit, such as runtime crashes during inverse cancellations on arbitrary unitary operators, failure to remove identity-equivalent gates when utilizing symbolic parameters, and incorrect commutation logic that led to invalid gate removals. Also, our results expose structural limitations in pattern-matching optimizations for self-adjoint operators and underscore the importance of considering global phase in a controlled context. The complexity of RetroQ scales with the target function and the compiler pass applied to it, with overhead no worse than that expected from applying the pass itself.

The remainder of this paper is organized as follows. Section II reviews the relevant background and literature. Section III analyzes existing unit testing approaches in PennyLane, Qiskit, Cirq [16], and pytket [17]. Section IV presents RetroQ and its two-stage verification approach. Section V reports the evaluation results and discovered compiler bugs. Finally, Section VI concludes the paper and outlines future work.

References (40)