arXiv:2610.10258cs.SEOct 2026

Manuscript Offprint

arXiv:2610.10258

QuSema: Detecting Silent Bugs in Quantum Libraries via Quantum-knowledge-enhanced Agents

Yujin Song, Kaining Zhang, Qixin Zhang, Shuai Wang, Pingchuan Ma, Yuxuan Du

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

YUJIN SONG, Nanyang Technological University, Singapore

KAINING ZHANG ∗^{*}, Nanyang Technological University, Singapore

QIXIN ZHANG, Nanyang Technological University, Singapore

SHUAI WANG, Hong Kong University of Science and Technology, Hong Kong, China

PINGCHUAN MA ∗^{*}, Zhejiang University of Technology, Hangzhou, China

YUXUAN DU ∗^{*}, Nanyang Technological University, Singapore

Quantum libraries are now critical infrastructure for quantum algorithm development, yet their correctness remains difficult to test. Existing testing techniques mainly rely on failure-based or comparison-based oracles, exposing bugs only when executions fail, violate runtime checks, or disagree with another implementation. Their applicability is limited when suitable execution-based oracles are unavailable, leaving some silent bugs undetected. Such missed bugs can produce incorrect results that propagate into experimental conclusions, simulation studies, and algorithmic designs. Here we present QuSema, an autonomous testing agent for finding silent bugs in quantum libraries. QuSema uses constraints from quantum semantics and documentation as a source-level semantic oracle to assess whether implementation logic can produce invalid outputs from valid inputs. It operates through an agentic loop that repeatedly inspects library API documentation and source code, reasons about the intended behavior of quantum operations, identifies potential semantic deviations, and validates them by generating executable tests through library APIs. Guided by quantum-domain reasoning, QuSema turns high-level behavioral mismatches into concrete, user-triggerable bug reports, enabling it to uncover non-crash defects. We implement QuSema for Qiskit and PennyLane. On a benchmark of 20 historical silent bugs, QuSema achieves higher mean bug relocation counts than Claude Code and Codex, with the DeepSeek configuration costing less than Claude Code. QuSema also discovers 40 previously unknown bugs confirmed by the developers, including 30 silent bugs.

Additional Key Words and Phrases: quantum library testing, quantum computing, silent bugs, coding agents

1 Introduction

Quantum computing [1, 2] offers the potential to tackle computational problems beyond the reach of classical methods, with promising applications in quantum chemistry [3], optimization [4], and machine learning [5]. To facilitate the design and refinement of quantum algorithms, quantum software libraries such as Qiskit [6] and PennyLane [7] have been developed and widely adopted. These libraries provide essential support for building, simulating, and executing quantum algorithms, and have become critical infrastructure in the quantum software ecosystem. However, quantum software is still in its early stage, and these rapidly evolving libraries contain bugs that lead to incorrect or unexpected behaviors [8]. Accordingly, systematic quantum software testing [9] is becoming increasingly essential for building a reliable and robust quantum software ecosystem.

Substantial research effort has been devoted to quantum software testing, particularly automated bug detection for quantum libraries [10]. Existing approaches have shown promising results [11, 12] for crash bugs [13], where exceptions or program termination provide explicit failure signals. Beyond crash bugs, quantum libraries also contain silent bugs [14], which return incorrect results that

∗^{*}Corresponding authors.

Authors' Contact Information: Yujin Song, Nanyang Technological University, Singapore, SONG0316@e.ntu.edu.sg; Kaining Zhang, Nanyang Technological University, Singapore, kaining.zhang@ntu.edu.sg; Qixin Zhang, Nanyang Technological University, Singapore, qixin.zhang@ntu.edu.sg; Shuai Wang, Hong Kong University of Science and Technology, Hong Kong, China, shuaiw@cse.ust.hk; Pingchuan Ma, Zhejiang University of Technology, Hangzhou, China, pma@zjut.edu.cn; Yuxuan Du, Nanyang Technological University, Singapore, yuxuan.du@ntu.edu.sg.

Song et al.

violate intended behavior or quantum semantics without explicit failures. For example, a quantum library may return an incorrect commutativity judgment for a pair of quantum operators [15] or apply a quantum circuit optimization method that does not preserve semantics of the original circuit [16]. These incorrect but undetected results can propagate through downstream workflows, which in turn mislead algorithm design, lead to erroneous hardware executions, and waste quantum computing resources [17]. To mitigate these risks and improve reliability, quantum software testing should be capable of effectively detecting silent bugs in quantum libraries.

Current approaches to silent bug detection in quantum libraries mainly rely on differential testing [18–22] and metamorphic testing [23–25]. Differential testing analyzes the same quantum circuit across different quantum software stacks and checks whether equivalent outputs are observed [26]. Metamorphic testing instead applies transformations that should preserve circuit semantics, such as inserting identities or replacing a gate with an equivalent decomposition, and checks the expected relations between execution results from the source and transformed programs [27]. Both approaches use black-box test oracles [28] to validate expected relations between execution results [29]. While these approaches have successfully detected silent bugs in quantum libraries [18–25], their reliance on black-box test oracles introduces two fundamental limitations.

(L1). Limited Availability of Expected Relations Between Execution Results. Some quantum library functionalities lack either semantically corresponding implementations across libraries for differential testing or circuit transformations with predictable output relations for metamorphic testing. For example, PennyLane supports the resource-estimation functionality [30] for predefined algorithms, while Qiskit has no counterpart [31], and semantics-preserving transformations may still change resource quantities such as gate count or circuit depth. Consequently, approaches that employ black-box test oracles cannot provide complete coverage of quantum library functionality.

(L2). Ineffective Triggering Without Semantic Guidance. Many quantum-software functionalities involve complex mathematical semantics [32], and their bugs are triggered only under specific semantic conditions [33]. Such conditions may involve specific parameter values, quantum operations, or circuit layouts [34]. Generic program generation may require extensive exploration to trigger these conditions [35], limiting the effectiveness of black-box testing.

To address these limitations, we develop QuSema, an automated agent for detecting silent bugs in quantum libraries by auditing Quantum Semantics. Its design follows our data-flow analysis, which localizes a silent bug to the library API that first transforms a valid input into an invalid output. Our study of reported bugs in Qiskit and PennyLane provides supporting evidence for this localization. QuSema therefore targets such API-local semantic deviations by directly analyzing the relevant implementation logic. More precisely, QuSema employs large language models (LLMs) [36, 37] to reason about implementation behavior using relevant quantum semantics and documentation. This information serves as a source-level semantic oracle for identifying candidate defects, which are subsequently validated through execution and checked for triggerability through documented library APIs. This design brings quantum semantics into source-level correctness reasoning and extends silent bug detection beyond cases covered by existing execution-based relations.

We systematically evaluate QuSema on Qiskit and PennyLane, two widely used quantum libraries. On a benchmark of 20 historical silent bugs, QuSema substantially outperforms Claude Code and Codex in localizing known defects. When instantiated with DeepSeek as its LLM backend, QuSema achieves this performance at a lower estimated cost than Claude Code and a comparable cost to Codex. Beyond historical benchmarks, applying QuSema to real-world quantum libraries uncovers 40 previously unknown bugs confirmed by developers, including 30 silent bugs. The identified bugs span quantum-program execution, semantic analysis, and library infrastructure. Notably, five of these silent bugs affect functionalities that lack either comparable implementations or suitable circuit transformations with known output relations. Such bugs fall beyond the detection scope of existing differential and metamorphic testing methods. These results validate the practical value of grounding source code inspection in quantum semantics for systematic silent bug detection across large quantum libraries.

In summary, our main contributions can be summarized in threefold:

• We characterize silent bugs in quantum libraries and show that all examined cases are API-local, leaving semantic evidence in implementation logic and documentation. This defines a well-scoped and prevalent bug class for source-level detection with quantum semantics.

• We propose QuSema, an automated testing agent that uses LLMs to reason about quantum semantics and implementation logic. By inferring semantic constraints from library source code and identifying potential implementation logic deviations from contracts and quantum semantics, it provides a new paradigm for silent bug detection in various quantum software libraries.

• We demonstrate the effectiveness of QuSema on 20 historical silent bugs through comparisons with coding agents and ablation studies. In addition, QuSema discovers 40 previously unknown bugs in Qiskit and PennyLane that are confirmed by developers, including 30 silent bugs, 5 of which affect functionality beyond the coverage of existing differential and metamorphic testing.

References (19)