Analyzing Quantum Programs with LintQ: A Static Analysis Framework for Qiskit (2310.00718v2)
Abstract: As quantum computing is rising in popularity, the amount of quantum programs and the number of developers writing them are increasing rapidly. Unfortunately, writing correct quantum programs is challenging due to various subtle rules developers need to be aware of. Empirical studies show that 40-82% of all bugs in quantum software are specific to the quantum domain. Yet, existing static bug detection frameworks are mostly unaware of quantum-specific concepts, such as circuits, gates, and qubits, and hence miss many bugs. This paper presents LintQ, a comprehensive static analysis framework for detecting bugs in quantum programs. Our approach is enabled by a set of abstractions designed to reason about common concepts in quantum computing without referring to the details of the underlying quantum computing platform. Built on top of these abstractions, LintQ offers an extensible set of ten analyses that detect likely bugs, such as operating on corrupted quantum states, redundant measurements, and incorrect compositions of sub-circuits. We apply the approach to a newly collected dataset of 7,568 real-world Qiskit-based quantum programs, showing that LintQ effectively identifies various programming problems, with a precision of 91.0% in its default configuration with the six best performing analyses. Comparing to a general-purpose linter and two existing quantum-aware techniques shows that almost all problems (92.1%) found by LintQ during our evaluation are missed by prior work. LintQ hence takes an important step toward reliable software in the growing field of quantum computing.
- [n. d.]. Flake8: Your Tool For Style Guide Enforcement — Flake8 6.0.0 Documentation. https://flake8.pycqa.org/en/latest/.
- [n. d.]. Nbconvert: Convert Notebooks to Other Formats — Nbconvert 7.2.9 Documentation. https://nbconvert.readthedocs.io/en/latest/index.html.
- [n. d.]. OptimizeSwapBeforeMeasure Pass Drops Swap Gate (Even If There Is NO Measure after It) ⋅⋅\cdot⋅ Issue #7642 ⋅⋅\cdot⋅ Qiskit/Qiskit. https://github.com/Qiskit/qiskit/issues/7642.
- [n. d.]. Pylint - Code Analysis for Python — Www.Pylint.Org. https://www.pylint.org/.
- 2021. Qiskit/Qiskit. https://github.com/Qiskit/qiskit.
- Assessing the Effectiveness of Input and Output Coverage Criteria for Testing Quantum Programs. In 2021 14th IEEE Conference on Software Testing, Verification and Validation (ICST). 13–23. https://doi.org/10.1109/ICST49551.2021.00014
- A Systematic Evaluation of Static API-Misuse Detectors. IEEE Transactions on Software Engineering 45, 12 (Dec. 2019), 1170–1188. https://doi.org/10.1109/TSE.2018.2827384
- QL: Object-oriented Queries on Relational Data. In 30th European Conference on Object-Oriented Programming (ECOOP 2016) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 56), Shriram Krishnamurthi and Benjamin S. Lerner (Eds.). Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany, 2:1–2:25. https://doi.org/10.4230/LIPIcs.ECOOP.2016.2
- Detect, Fix, and Verify TensorFlow API Misuses. In 2022 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER). 925–929. https://doi.org/10.1109/SANER53432.2022.00110
- PennyLane: Automatic Differentiation of Hybrid Quantum-Classical Computations. arXiv:1811.04968 [physics, physics:quant-ph] (Feb. 2020). arXiv:1811.04968 [physics, physics:quant-ph]
- A Few Billion Lines of Code Later: Using Static Analysis to Find Bugs in the Real World. Commun. ACM 53, 2 (Feb. 2010), 66–75. https://doi.org/10.1145/1646353.1646374
- Silq: A High-Level Quantum Language with Safe Uncomputation and Intuitive Semantics. In Proceedings of the 41st ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2020). Association for Computing Machinery, New York, NY, USA, 286–300. https://doi.org/10.1145/3385412.3386007
- Moving fast with software verification. In NASA Formal Methods: 7th International Symposium, NFM 2015, Pasadena, CA, USA, April 27-29, 2015, Proceedings 7. Springer, 3–11.
- The Smelly Eight: An Empirical Study on the Prevalence of Code Smells in Quantum Computing - Artifact. 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE) (Jan. 2023). https://doi.org/10.5281/ZENODO.7556360
- James Dargan. 2022. Top 5 Quantum Programming Languages in 2022.
- David Elieser Deutsch and Roger Penrose. 1997. Quantum Computational Networks. Proceedings of the Royal Society of London. A. Mathematical and Physical Sciences 425, 1868 (Jan. 1997), 73–90. https://doi.org/10.1098/rspa.1989.0099
- Cirq Developers. 2021a. Cirq. Zenodo. https://doi.org/10.5281/zenodo.5182845
- Qiskit Developers. 2021b. Qiskit: An Open-Source Framework for Quantum Computing. https://doi.org/10.5281/zenodo.2573505
- Egretta.Thula. 2023. Answer to ”Why Does Composing a Clifford Circuit to Another Circuit Not Work? (Qiskit)” - Quantum Computing Stack Exchange.
- Extended Static Checking for Java. ACM SIGPLAN Notices 37, 5 (May 2002), 234–245. https://doi.org/10.1145/543552.512558
- Mutation Testing of Quantum Programs Written in QISKit. In Proceedings of the ACM/IEEE 44th International Conference on Software Engineering: Companion Proceedings (ICSE ’22). Association for Computing Machinery, New York, NY, USA, 358–359. https://doi.org/10.1145/3510454.3528649
- QMutPy: A Mutation Testing Tool for Quantum Algorithms and Applications in Qiskit. In Proceedings of the 31st ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA 2022). Association for Computing Machinery, New York, NY, USA, 797–800. https://doi.org/10.1145/3533767.3543296
- AChecker: Statically Detecting Smart Contract Access Control Vulnerabilities. In 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE). 945–956. https://doi.org/10.1109/ICSE48619.2023.00087
- Google. 2015. Error Prone: static analysis tool for Java. http://errorprone.info/.
- Andrew Habib and Michael Pradel. 2018. How Many of All Bugs Do We Find? A Study of Static Bug Detectors. In 2018 33rd IEEE/ACM International Conference on Automated Software Engineering (ASE). 317–328. https://doi.org/10.1145/3238147.3238213
- Yipeng Huang and Margaret Martonosi. 2019. Statistical Assertions for Validating Patterns and Finding Bugs in Quantum Programs. In Proceedings of the 46th International Symposium on Computer Architecture (ISCA ’19). Association for Computing Machinery, New York, NY, USA, 541–553. https://doi.org/10.1145/3307650.3322213
- ScaffCC: A Framework for Compilation and Analysis of Quantum Computing Programs. In Proceedings of the 11th ACM Conference on Computing Frontiers (CF ’14). Association for Computing Machinery, New York, NY, USA, 1–10. https://doi.org/10.1145/2597917.2597939
- Why Don’t Software Developers Use Static Analysis Tools to Find Bugs?. In Proceedings of the 2013 International Conference on Software Engineering (ICSE ’13). IEEE Press, San Francisco, CA, USA, 672–681.
- Defects4J: A Database of Existing Faults to Enable Controlled Testing Studies for Java Programs. In Proceedings of the 2014 International Symposium on Software Testing and Analysis (ISSTA 2014). Association for Computing Machinery, New York, NY, USA, 437–440. https://doi.org/10.1145/2610384.2628055
- A Uniform Representation of Classical and Quantum Source Code for Static Code Analysis. https://doi.org/10.48550/arXiv.2308.06113 arXiv:2308.06113 [cs]
- Static Analysis of Shape in TensorFlow Programs. In 34th European Conference on Object-Oriented Programming (ECOOP 2020) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 166), Robert Hirschfeld and Tobias Pape (Eds.). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 15:1–15:29. https://doi.org/10.4230/LIPIcs.ECOOP.2020.15
- QASMBench: A Low-Level Quantum Benchmark Suite for NISQ Evaluation and Simulation. ACM Transactions on Quantum Computing 4, 2 (Feb. 2023), 10:1–10:26. https://doi.org/10.1145/3550488
- Projection-Based Runtime Assertions for Testing and Debugging Quantum Programs. Proceedings of the ACM on Programming Languages 4, OOPSLA (Nov. 2020), 150:1–150:29. https://doi.org/10.1145/3428218
- In defense of soundiness: a manifesto. Commun. ACM 58, 2 (2015), 44–46.
- Peixun Long and Jianjun Zhao. 2023. Equivalence, Identity, and Unitarity Checking in Black-Box Testing of Quantum Programs. https://doi.org/10.48550/arXiv.2307.01481 arXiv:2307.01481 [quant-ph]
- A Comprehensive Study of Bug Fixes in Quantum Programs. In 2022 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER). 1239–1246. https://doi.org/10.1109/SANER53432.2022.00147
- Is Your Quantum Program Bug-Free? Proceedings of the ACM/IEEE 42nd International Conference on Software Engineering: New Ideas and Emerging Results (June 2020), 29–32. https://doi.org/10.1145/3377816.3381731 arXiv:2001.10870
- Quantum Computation and Quantum Information. Am. J. Phys. 70, 5 (2002), 4.
- Matteo Paltenghi and Michael Pradel. 2022. Bugs in Quantum Computing Platforms: An Empirical Study. Proceedings of the ACM on Programming Languages 6, OOPSLA1 (April 2022), 86:1–86:27. https://doi.org/10.1145/3527330
- Matteo Paltenghi and Michael Pradel. 2023. MorphQ: Metamorphic Testing of the Qiskit Quantum Computing Platform. In Proceedings of the 45th International Conference on Software Engineering (ICSE ’23). IEEE Press, Melbourne, Victoria, Australia, 2413–2424. https://doi.org/10.1109/ICSE48619.2023.00202
- Unqomp: Synthesizing Uncomputation in Quantum Circuits. In Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI 2021). Association for Computing Machinery, New York, NY, USA, 222–236. https://doi.org/10.1145/3453483.3454040
- Simon Perdrix. 2008. Quantum Entanglement Analysis Based on Abstract Interpretation. In Static Analysis (Lecture Notes in Computer Science), María Alpuente and Germán Vidal (Eds.). Springer, Berlin, Heidelberg, 270–282. https://doi.org/10.1007/978-3-540-69166-2_18
- T—ket⟩⟩\rangle⟩: A Retargetable Compiler for NISQ Devices. Quantum Science and Technology 6, 1 (Nov. 2020), 014003. https://doi.org/10.1088/2058-9565/ab8e92
- Q#: Enabling Scalable Quantum Computing and Development with a High-level DSL. In Proceedings of the Real World Domain Specific Languages Workshop 2018 (RWDSL2018). Association for Computing Machinery, New York, NY, USA, 1–10. https://doi.org/10.1145/3183895.3183901
- user19571. 2022. Question: ”Remove Inactive Qubits from Qiskit Circuit” - Quantum Computing Stack Exchange.
- Poster: Fuzz Testing of Quantum Program. In 2021 14th IEEE Conference on Software Testing, Verification and Validation (ICST). 466–469. https://doi.org/10.1109/ICST49551.2021.00061
- QDiff: Differential Testing of Quantum Software Stacks. In 2021 36th IEEE/ACM International Conference on Automated Software Engineering (ASE). 692–704. https://doi.org/10.1109/ASE51524.2021.9678792
- Encoding Patterns for Quantum Algorithms. IET Quantum Communication 2, 4 (2021), 141–152. https://doi.org/10.1049/qtc2.12032
- Fuzz4All: Universal Fuzzing with Large Language Models. In Proceedings of the IEEE/ACM 46th International Conference on Software Engineering (ICSE ’24). Association for Computing Machinery, New York, NY, USA, 1–13. https://doi.org/10.1145/3597503.3639121
- Shangzhou Xia and Jianjun Zhao. 2023. Static Entanglement Analysis of Quantum Programs. In 2023 IEEE/ACM 4th International Workshop on Quantum Software Engineering (Q-SE). 42–49. https://doi.org/10.1109/Q-SE59154.2023.00013
- Modeling and Discovering Vulnerabilities with Code Property Graphs. In 2014 IEEE Symposium on Security and Privacy. 590–604. https://doi.org/10.1109/SP.2014.44
- Nengkun Yu and Jens Palsberg. 2021. Quantum Abstract Interpretation. In Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI 2021). Association for Computing Machinery, New York, NY, USA, 542–558. https://doi.org/10.1145/3453483.3454061
- Bugs4Q: A Benchmark of Existing Bugs to Enable Controlled Testing and Debugging Studies for Quantum Programs. Journal of Systems and Software 205 (Nov. 2023), 111805. https://doi.org/10.1016/j.jss.2023.111805
- QChecker: Detecting Bugs in Quantum Programs via Static Analysis. https://doi.org/10.48550/arXiv.2304.04387 arXiv:2304.04387 [cs]
- Identifying Bug Patterns in Quantum Programs. In 2021 IEEE/ACM 2nd International Workshop on Quantum Software Engineering (Q-SE). 16–21. https://doi.org/10.1109/Q-SE52541.2021.00011
- Bugs4Q: A Benchmark of Real Bugs for Quantum Programs. In 2021 36th IEEE/ACM International Conference on Automated Software Engineering (ASE). https://doi.org/10.1109/ASE51524.2021.9678908