Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Analyzing Quantum Programs with LintQ: A Static Analysis Framework for Qiskit

Published: 12 July 2024 Publication History

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.

References

[1]
[n. d.]. Flake8: Your Tool For Style Guide Enforcement — Flake8 6.0.0 Documentation. https://flake8.pycqa.org/en/latest/.
[2]
[n. d.]. Nbconvert: Convert Notebooks to Other Formats — Nbconvert 7.2.9 Documentation. https://nbconvert.readthedocs.io/en/latest/index.html.
[3]
[n. d.]. OptimizeSwapBeforeMeasure Pass Drops Swap Gate (Even If There Is NO Measure after It) ⋅ Issue #7642 ⋅ Qiskit/Qiskit. https://github.com/Qiskit/qiskit/issues/7642.
[4]
[n. d.]. Pylint - Code Analysis for Python | Www.Pylint.Org. https://www.pylint.org/.
[5]
2021. Qiskit/Qiskit. https://github.com/Qiskit/qiskit.
[6]
Shaukat Ali, Paolo Arcaini, Xinyi Wang, and Tao Yue. 2021. 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. issn:2159-4848 https://doi.org/10.1109/ICST49551.2021.00014
[7]
Sven Amann, Hoan Anh Nguyen, Sarah Nadi, Tien N. Nguyen, and Mira Mezini. 2019. A Systematic Evaluation of Static API-Misuse Detectors. IEEE Transactions on Software Engineering, 45, 12 (2019), Dec., 1170–1188. issn:1939-3520 https://doi.org/10.1109/TSE.2018.2827384
[8]
Pavel Avgustinov, Oege de Moor, Michael Peyton Jones, and Max Schäfer. 2016. QL: Object-oriented Queries on Relational Data. In 30th European Conference on Object-Oriented Programming (ECOOP 2016), Shriram Krishnamurthi and Benjamin S. Lerner (Eds.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 56). Schloss Dagstuhl– Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany. 2:1–2:25. isbn:978-3-95977-014-9 issn:1868-8969 https://doi.org/10.4230/LIPIcs.ECOOP.2016.2
[9]
Wilson Baker, Michael O’Connor, Seyed Reza Shahamiri, and Valerio Terragni. 2022. Detect, Fix, and Verify TensorFlow API Misuses. In 2022 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER). 925–929. issn:1534-5351 https://doi.org/10.1109/SANER53432.2022.00110
[10]
Ville Bergholm, Josh Izaac, Maria Schuld, Christian Gogolin, M. Sohaib Alam, Shahnawaz Ahmed, Juan Miguel Arrazola, Carsten Blank, Alain Delgado, Soran Jahangiri, Keri McKiernan, Johannes Jakob Meyer, Zeyue Niu, Antal Száva, and Nathan Killoran. 2020. PennyLane: Automatic Differentiation of Hybrid Quantum-Classical Computations. arXiv:1811.04968 [physics, physics:quant-ph], Feb., arxiv:1811.04968.
[11]
Al Bessey, Ken Block, Ben Chelf, Andy Chou, Bryan Fulton, Seth Hallem, Charles Henri-Gros, Asya Kamsky, Scott McPeak, and Dawson Engler. 2010. A Few Billion Lines of Code Later: Using Static Analysis to Find Bugs in the Real World. Commun. ACM, 53, 2 (2010), Feb., 66–75. issn:0001-0782 https://doi.org/10.1145/1646353.1646374
[12]
Benjamin Bichsel, Maximilian Baader, Timon Gehr, and Martin Vechev. 2020. 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. isbn:978-1-4503-7613-6 https://doi.org/10.1145/3385412.3386007
[13]
Cristiano Calcagno, Dino Distefano, Jérémy Dubreil, Dominik Gabi, Pieter Hooimeijer, Martino Luca, Peter O’Hearn, Irene Papakonstantinou, Jim Purbrick, and Dulma Rodriguez. 2015. Moving fast with software verification. In NASA Formal Methods: 7th International Symposium, NFM 2015, Pasadena, CA, USA, April 27-29, 2015, Proceedings 7. 3–11.
[14]
Qihong Chen, Rúben Câmara, José Campos, André Souto, and Iftekhar Ahmed. 2023. 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., https://doi.org/10.5281/ZENODO.7556360
[15]
James Dargan. 2022. Top 5 Quantum Programming Languages in 2022.
[16]
David Elieser Deutsch and Roger Penrose. 1997. Quantum Computational Networks. Proceedings of the Royal Society of London. A. Mathematical and Physical Sciences, 425, 1868 (1997), Jan., 73–90. https://doi.org/10.1098/rspa.1989.0099
[17]
Cirq Developers. 2021. Cirq. Zenodo. https://doi.org/10.5281/zenodo.5182845
[18]
Qiskit Developers. 2021. Qiskit: An Open-Source Framework for Quantum Computing. https://doi.org/10.5281/zenodo.2573505
[19]
Egretta.Thula. 2023. Answer to "Why Does Composing a Clifford Circuit to Another Circuit Not Work? (Qiskit)" - Quantum Computing Stack Exchange.
[20]
Cormac Flanagan, K. Rustan M. Leino, Mark Lillibridge, Greg Nelson, James B. Saxe, and Raymie Stata. 2002. Extended Static Checking for Java. ACM SIGPLAN Notices, 37, 5 (2002), May, 234–245. issn:0362-1340 https://doi.org/10.1145/543552.512558
[21]
Daniel Fortunato, José Campos, and Rui Abreu. 2022. 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. isbn:978-1-4503-9223-5 https://doi.org/10.1145/3510454.3528649
[22]
Daniel Fortunato, José Campos, and Rui Abreu. 2022. 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. isbn:978-1-4503-9379-9 https://doi.org/10.1145/3533767.3543296
[23]
Asem Ghaleb, Julia Rubin, and Karthik Pattabiraman. 2023. AChecker: Statically Detecting Smart Contract Access Control Vulnerabilities. In 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE). 945–956. issn:1558-1225 https://doi.org/10.1109/ICSE48619.2023.00087
[24]
Google. 2015. Error Prone: static analysis tool for Java. http://errorprone.info/
[25]
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. issn:2643-1572 https://doi.org/10.1145/3238147.3238213
[26]
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. isbn:978-1-4503-6669-4 https://doi.org/10.1145/3307650.3322213
[27]
Ali JavadiAbhari, Shruti Patil, Daniel Kudrow, Jeff Heckey, Alexey Lvov, Frederic T. Chong, and Margaret Martonosi. 2014. 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. isbn:978-1-4503-2870-8 https://doi.org/10.1145/2597917.2597939
[28]
Brittany Johnson, Yoonki Song, Emerson Murphy-Hill, and Robert Bowdidge. 2013. 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. isbn:978-1-4673-3076-3
[29]
René Just, Darioush Jalali, and Michael D. Ernst. 2014. 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. isbn:978-1-4503-2645-2 https://doi.org/10.1145/2610384.2628055
[30]
Maximilian Kaul, Alexander Küchler, and Christian Banse. 2023. A Uniform Representation of Classical and Quantum Source Code for Static Code Analysis. https://doi.org/10.48550/arXiv.2308.06113 arxiv:2308.06113.
[31]
Sifis Lagouvardos, Julian Dolby, Neville Grech, Anastasios Antoniadis, and Yannis Smaragdakis. 2020. Static Analysis of Shape in TensorFlow Programs. In 34th European Conference on Object-Oriented Programming (ECOOP 2020), Robert Hirschfeld and Tobias Pape (Eds.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 166). Schloss Dagstuhl– Leibniz-Zentrum für Informatik, Dagstuhl, Germany. 15:1–15:29. isbn:978-3-95977-154-2 issn:1868-8969 https://doi.org/10.4230/LIPIcs.ECOOP.2020.15
[32]
Ang Li, Samuel Stein, Sriram Krishnamoorthy, and James Ang. 2023. QASMBench: A Low-Level Quantum Benchmark Suite for NISQ Evaluation and Simulation. ACM Transactions on Quantum Computing, 4, 2 (2023), Feb., 10:1–10:26. https://doi.org/10.1145/3550488
[33]
Gushu Li, Li Zhou, Nengkun Yu, Yufei Ding, Mingsheng Ying, and Yuan Xie. 2020. Projection-Based Runtime Assertions for Testing and Debugging Quantum Programs. Proceedings of the ACM on Programming Languages, 4, OOPSLA (2020), Nov., 150:1–150:29. https://doi.org/10.1145/3428218
[34]
Benjamin Livshits, Manu Sridharan, Yannis Smaragdakis, Ondrej Lhoták, José Nelson Amaral, Bor-Yuh Evan Chang, Samuel Z. Guyer, Uday P. Khedker, Anders Møller, and Dimitrios Vardoulakis. 2015. In defense of soundiness: a manifesto. Commun. ACM, 58, 2 (2015), 44–46.
[35]
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.
[36]
Junjie Luo, Pengzhan Zhao, Zhongtao Miao, Shuhan Lan, and Jianjun Zhao. 2022. A Comprehensive Study of Bug Fixes in Quantum Programs. In 2022 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER). 1239–1246. issn:1534-5351 https://doi.org/10.1109/SANER53432.2022.00147
[37]
Andriy Miranskyy, Lei Zhang, and Javad Doliskani. 2020. Is Your Quantum Program Bug-Free? Proceedings of the ACM/IEEE 42nd International Conference on Software Engineering: New Ideas and Emerging Results, June, 29–32. https://doi.org/10.1145/3377816.3381731 arxiv:2001.10870.
[38]
Michael A Nielsen, Isaac Chuang, and Lov K Grover. 2002. Quantum Computation and Quantum Information. Am. J. Phys., 70, 5 (2002), 4.
[39]
Matteo Paltenghi and Michael Pradel. 2022. Bugs in Quantum Computing Platforms: An Empirical Study. Proceedings of the ACM on Programming Languages, 6, OOPSLA1 (2022), April, 86:1–86:27. https://doi.org/10.1145/3527330
[40]
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. isbn:978-1-66545-701-9 https://doi.org/10.1109/ICSE48619.2023.00202
[41]
Anouk Paradis, Benjamin Bichsel, Samuel Steffen, and Martin Vechev. 2021. 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. isbn:978-1-4503-8391-2 https://doi.org/10.1145/3453483.3454040
[42]
Simon Perdrix. 2008. Quantum Entanglement Analysis Based on Abstract Interpretation. In Static Analysis, María Alpuente and Germán Vidal (Eds.) (Lecture Notes in Computer Science). Springer, Berlin, Heidelberg. 270–282. isbn:978-3-540-69166-2 https://doi.org/10.1007/978-3-540-69166-2_18
[43]
Seyon Sivarajah, Silas Dilkes, Alexander Cowtan, Will Simmons, Alec Edgington, and Ross Duncan. 2020. T|ket〉 : A Retargetable Compiler for NISQ Devices. Quantum Science and Technology, 6, 1 (2020), Nov., 014003. issn:2058-9565 https://doi.org/10.1088/2058-9565/ab8e92
[44]
Krysta Svore, Alan Geller, Matthias Troyer, John Azariah, Christopher Granade, Bettina Heim, Vadym Kliuchnikov, Mariia Mykhailova, Andres Paz, and Martin Roetteler. 2018. 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. isbn:978-1-4503-6355-6 https://doi.org/10.1145/3183895.3183901
[45]
user19571. 2022. Question: "Remove Inactive Qubits from Qiskit Circuit" - Quantum Computing Stack Exchange.
[46]
Jiyuan Wang, Fucheng Ma, and Yu Jiang. 2021. Poster: Fuzz Testing of Quantum Program. In 2021 14th IEEE Conference on Software Testing, Verification and Validation (ICST). 466–469. issn:2159-4848 https://doi.org/10.1109/ICST49551.2021.00061
[47]
Jiyuan Wang, Qian Zhang, Guoqing Harry Xu, and Miryung Kim. 2021. QDiff: Differential Testing of Quantum Software Stacks. In 2021 36th IEEE/ACM International Conference on Automated Software Engineering (ASE). 692–704. issn:2643-1572 https://doi.org/10.1109/ASE51524.2021.9678792
[48]
Manuela Weigold, Johanna Barzen, Frank Leymann, and Marie Salm. 2021. Encoding Patterns for Quantum Algorithms. IET Quantum Communication, 2, 4 (2021), 141–152. issn:2632-8925 https://doi.org/10.1049/qtc2.12032
[49]
Chunqiu Steven Xia, Matteo Paltenghi, Jia Le Tian, Michael Pradel, and Lingming Zhang. 2024. 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. isbn:9798400702174 https://doi.org/10.1145/3597503.3639121
[50]
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
[51]
Fabian Yamaguchi, Nico Golde, Daniel Arp, and Konrad Rieck. 2014. Modeling and Discovering Vulnerabilities with Code Property Graphs. In 2014 IEEE Symposium on Security and Privacy. 590–604. issn:2375-1207 https://doi.org/10.1109/SP.2014.44
[52]
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. isbn:978-1-4503-8391-2 https://doi.org/10.1145/3453483.3454061
[53]
Pengzhan Zhao, Zhongtao Miao, Shuhan Lan, and Jianjun Zhao. 2023. Bugs4Q: A Benchmark of Existing Bugs to Enable Controlled Testing and Debugging Studies for Quantum Programs. Journal of Systems and Software, 205 (2023), Nov., 111805. issn:0164-1212 https://doi.org/10.1016/j.jss.2023.111805
[54]
Pengzhan Zhao, Xiongfei Wu, Zhuo Li, and Jianjun Zhao. 2023. QChecker: Detecting Bugs in Quantum Programs via Static Analysis. https://doi.org/10.48550/arXiv.2304.04387 arxiv:2304.04387.
[55]
Pengzhan Zhao, Jianjun Zhao, and Lei Ma. 2021. Identifying Bug Patterns in Quantum Programs. In 2021 IEEE/ACM 2nd International Workshop on Quantum Software Engineering (Q-SE). 16–21. isbn:978-1-66544-462-0 https://doi.org/10.1109/Q-SE52541.2021.00011
[56]
Pengzhan Zhao, Jianjun Zhao, Zhongtao Miao, and Shuhan Lan. 2021. Bugs4Q: A Benchmark of Real Bugs for Quantum Programs. In 2021 36th IEEE/ACM International Conference on Automated Software Engineering (ASE). issn:2643-1572 https://doi.org/10.1109/ASE51524.2021.9678908

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Software Engineering
Proceedings of the ACM on Software Engineering  Volume 1, Issue FSE
July 2024
2770 pages
EISSN:2994-970X
DOI:10.1145/3554322
  • Editor:
  • Luciano Baresi
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 12 July 2024
Published in PACMSE Volume 1, Issue FSE

Badges

Author Tags

  1. bug detection
  2. program analysis
  3. quantum computing
  4. static analysis

Qualifiers

  • Research-article

Funding Sources

  • Deutsche Forschungsgemeinschaft
  • European Research Council

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 247
    Total Downloads
  • Downloads (Last 12 months)247
  • Downloads (Last 6 weeks)67
Reflects downloads up to 14 Jan 2025

Other Metrics

Citations

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media