QuCheck:基于属性的Qiskit量子程序测试框架
QuCheck: A Property-based Testing Framework for Quantum Programs in Qiskit
摘要 Abstract
在Q#中,基于属性的测试方法已被提出并实现为QSharpCheck;然而,该实现功能有限、缺乏可扩展性,并且仅在少数程序上通过单一属性进行了评估。为了解决这些局限性,我们提出了QuCheck,这是一个增强版的Qiskit中的基于属性的测试框架。通过利用Qiskit和更广泛的Python生态系统,QuCheck实现了属性构建,引入了灵活的输入生成器和断言,并支持表达性强的前提条件。我们通过针对五个量子程序(2到10个量子比特)的变异分析对其有效性进行了评估,通过调整属性数量、输入数量以及测量次数来评估它们对故障检测的影响,并展示了在各种条件下基于属性测试的有效性。结果显示,变异分数(即故障检测程度的衡量标准)与评估的属性数量之间存在强正相关关系,而误报率与测量次数之间存在适度负相关关系。在最全面的测试配置中,评估三个属性的测试对五个算法的平均变异分数在0.90到0.92之间,误报率为0到0.04。与QSharpCheck相比,QuCheck识别的故障数量增加了36.0%,尽管有一个误报,但执行时间减少了81.1%。这些结果强调了基于属性测试在验证量子系统方面的可行性。
Property-based testing has been previously proposed for quantum programs in Q# with QSharpCheck; however, this implementation was limited in functionality, lacked extensibility, and was evaluated on a narrow range of programs using a single property. To address these limitations, we propose QuCheck, an enhanced property-based testing framework in Qiskit. By leveraging Qiskit and the broader Python ecosystem, QuCheck facilitates property construction, introduces flexible input generators and assertions, and supports expressive preconditions. We assessed its effectiveness through mutation analysis on five quantum programs (2-10 qubits), varying the number of properties, inputs, and measurement shots to assess their impact on fault detection and demonstrate the effectiveness of property-based testing across a range of conditions. Results show a strong positive correlation between the mutation score (a measure of fault detection) and number of properties evaluated, with a moderate negative correlation between the false positive rate and number of measurement shots. Among the most thorough test configurations, those evaluating three properties achieved a mean mutation score ranging from 0.90 to 0.92 across all five algorithms, with the false positive rate between 0 and 0.04. QuCheck identified 36.0% more faults than QSharpCheck, with execution time reduced by 81.1%, despite one false positive. These findings underscore the viability of property-based testing for verifying quantum systems.