QTestBench: A Test Framework for Evaluating LLM-Generated Quantum Code
作者: Meriem Terki, Nouhaila Innan, Minghao Shao, Muhammad Kashif, Alberto Marchisio, Muhammad Shafique
分类: cs.LG, cs.CL, quant-ph
发布日期: 2026-10-09
备注: Accepted at the 2026 IEEE 2nd International Conference on Quantum Artificial Intelligence (QAI), 2026
💡 一句话要点
提出QTestBench框架以评估LLM生成的量子代码测试
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 量子代码生成 大型语言模型 测试框架 量子软件 基准测试 错误检测 可执行性评估
📋 核心要点
- 现有的量子程序测试方法未能有效评估LLM生成的测试是否能区分正确与错误的实现。
- QTestBench框架通过独立的基准检查器评估LLM生成的量子测试,确保测试结果的可靠性。
- 实验结果显示,生成的测试套件几乎总是可执行,但在区分能力上仍有不足,最佳生成器在QHack和Qiskit HumanEval上的测试质量分别为0.71和0.34。
📝 摘要(中文)
大型语言模型(LLMs)在经典代码生成中表现出色,并逐渐用于编写保护这些代码的单元测试。然而,LLMs在量子软件测试中的有效性尚不明确,因为量子程序具有概率性,依赖于数值容差,并由特定领域的检查器进行评判。现有的量子基准测试主要关注模型是否生成正确的解决方案,而未能评估其测试是否能区分正确与错误的实现。为此,本文提出了QTestBench框架,该框架通过独立的基准检查器评估LLM生成的量子测试套件,确保测试本身不被视为真理。QTestBench能够生成语法、语义和行为测试,并在运行时注入候选解决方案,比较每个测试结果与检查器标签的差异。我们在八个PennyLane QHack挑战和十个Qiskit HumanEval任务上对五个LLM进行了基准测试。
🔬 方法详解
问题定义:本文旨在解决LLM生成的量子代码测试的有效性评估问题。现有方法主要关注生成的解决方案是否正确,而忽视了测试本身的有效性和可靠性。
核心思路:QTestBench框架的核心思想是通过独立的基准检查器来评估LLM生成的测试套件,确保测试结果不被视为绝对真理,从而提高测试的可信度。
技术框架:QTestBench的整体架构包括三个主要模块:生成测试、运行测试和验证结果。首先,模型生成语法、语义和行为测试;然后在运行时注入候选解决方案;最后,将测试结果与检查器标签进行比较。
关键创新:QTestBench的创新之处在于其不将生成的测试视为真理,而是通过独立的检查器进行验证。这种方法与现有的量子基准测试方法本质上不同,后者通常只关注解决方案的正确性。
关键设计:在设计中,QTestBench采用了多种验证群体,以回答不同的诊断问题。此外,使用了Oracle验证的合成突变体来稳定缺陷检测估计,尤其是在自然缺陷解决方案稀缺的情况下。具体参数设置和损失函数的细节在论文中有详细描述。
🖼️ 关键图片
📊 实验亮点
实验结果表明,生成的测试套件几乎总是可执行,但在区分能力上仍有不足。最佳生成器在QHack挑战中的测试质量达到0.71,而在Qiskit HumanEval任务中仅为0.34,显示出仅依赖可执行性来评估测试质量是不够的。
🎯 应用场景
QTestBench框架的潜在应用领域包括量子软件开发和测试,尤其是在需要高可靠性的量子程序中。通过提供一个可重复的跨框架基准,QTestBench能够帮助开发者评估和改进LLM生成的量子测试的可信度,进而推动量子计算领域的进步。
📄 摘要(原文)
Large language models (LLMs) have shown strong results in classical code generation and are increasingly used to write the unit tests that safeguard that code. Whether they can do the same for quantum software is less clear, because quantum programs are probabilistic, depend on numerical tolerances, and are judged by domain-specific checkers, so a well-formed test can still disagree with the benchmark's verdict. Existing quantum benchmarks measure whether a model produces a correct solution, but not whether its tests can distinguish correct implementations from faulty ones. We introduce QTestBench, a framework that evaluates LLM-generated quantum test suites against independent benchmark checkers, never treating the tests themselves as ground truth. For each task, QTestBench prompts models to produce syntactic, semantic, and behavioral tests, injects candidate solutions at runtime, and compares each test verdict with the checker's label under three validation cohorts, each answering a distinct diagnostic question. We benchmark five LLMs on eight PennyLane QHack challenges and ten Qiskit HumanEval tasks. Generated suites almost always execute, but discrimination lags behind: the best generator reaches a test quality of 0.71 on QHack and 0.34 on Qiskit HumanEval, so executability alone overstates test quality. Oracle-verified synthetic mutants stabilize bug-detection estimates when natural faulty solutions are scarce, as on three of ten Qiskit tasks that yield none. QTestBench offers a reproducible, cross-framework benchmark for the trustworthiness of LLM-generated quantum tests.