Skip to main content

Static Analysis of Quantum Programs

  • Conference paper
  • First Online:
Static Analysis (SAS 2024)

Abstract

In principle, the design and implementation of quantum programming languages are the same essential tasks as for conventional (classical) programming languages. High-level programming constructs and compilation tools are structurally similar in both cases. The difference is mainly in the hardware machine executing the final code, which in the case of quantum programming languages is a quantum processor, i.e. a physical object obeying the laws of quantum mechanics. Therefore, special technical solutions are required to comply with such laws. In this paper, we show how static analysis can guarantee the correct implementation of quantum programs by introducing two data-flow analyses for detecting some ‘wrong’ uses of quantum variables. A compiler including such analyses would allow for a higher level of abstraction in the quantum language, relieving the programmer of low-level tasks such as the safe removal of temporary variables.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    The ket notation \(\left| {\psi }\right\rangle \) is due to Dirac and represents the vector \((\alpha ,\beta )^T\) in linear algebraic notation.

  2. 2.

    The Toffoli gate corresponds to a double controlled not; in particular we negate the target if both controllers are 1.

  3. 3.

    Given two sets A and B, .

  4. 4.

    Functions that contain only classical gates, such as the NOT and the CNOT gates.

References

  1. Aho, A.V., Lam, M.S., Sethi, R., Ullman, J.D.: Compilers: Principles, Techniques, and Tools, 2nd edn. Addison-Wesley Longman Publishing Co., Inc., USA (2006)

    MATH  Google Scholar 

  2. Amy, M.: Formal Methods in Quantum Circuit Design. Ph.D. thesis, University of Waterloo (2019)

    Google Scholar 

  3. Amy, M., Gheorghiu, V.: staq–A full-stack quantum processing toolkit. Quantum Sci. Technol. 5(3), 034016 (2020)

    Article  MATH  Google Scholar 

  4. Amy, M., Maslov, D., Mosca, M.: Polynomial-time T-depth optimization of Clifford+ T circuits via matroid partitioning. IEEE Trans. Comput. Aided Des. Integr. Circuits Syst. 33(10), 1476–1489 (2014)

    Article  MATH  Google Scholar 

  5. Amy, M., Roetteler, M., Svore, K.M.: Verified compilation of space-efficient reversible circuits. In: Majumdar, R., Kunčak, V. (eds.) Computer Aided Verification, pp. 3–21. Springer International Publishing, Cham (2017)

    Google Scholar 

  6. Bichsel, B., Baader, M., Gehr, T., Vechev, M.: 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, pp. 286–300. PLDI 2020, Association for Computing Machinery, New York, NY, USA (2020)

    Google Scholar 

  7. Bruni, R., Giacobazzi, R., Gori, R., Ranzato, F.: A correctness and incorrectness program logic. J. ACM 70(2), 1–45 (2023)

    Article  MathSciNet  MATH  Google Scholar 

  8. Chen, Y., Stade, Y.: Quantum Constant Propagation. In: International Static Analysis Symposium, pp. 164–189. Springer (2023)

    Google Scholar 

  9. Cousot, P., Cousot, R.: Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In: Proceedings of the 4th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, pp. 238–252 (1977)

    Google Scholar 

  10. Cross, A., et al.: OpenQASM 3: a broader and deeper quantum assembly language. ACM Trans. Quantum Comput. 3(3), 1–50 (2022)

    Article  MathSciNet  MATH  Google Scholar 

  11. Ding, Y., et al.: SQUARE: strategic quantum ancilla reuse for modular quantum programs via cost-effective uncomputation. In: 2020 ACM/IEEE 47th Annual International Symposium on Computer Architecture (ISCA), pp. 570–583 (2020)

    Google Scholar 

  12. Feng, Y., Li, S.: Abstract interpretation, Hoare logic, and incorrectness logic for quantum programs. Inf. Comput. 294, 105077 (2023)

    Article  MathSciNet  MATH  Google Scholar 

  13. Fu, P., Kishida, K., Ross, N.J., Selinger, P.: A Tutorial Introduction to Quantum Circuit Programming in Dependently Typed Proto-Quipper. In: Lanese, I., Rawski, M. (eds.) RC 2020. LNCS, vol. 12227, pp. 153–168. Springer, Cham (2020). https://doi.org/10.1007/978-3-030-52482-1_9

    Chapter  MATH  Google Scholar 

  14. Green, A.S., Lumsdaine, P.L., Ross, N.J., Selinger, P., Valiron, B.: Quipper: a scalable quantum programming language. In: Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation, pp. 333–342. PLDI ’13, Association for Computing Machinery, New York, NY, USA (2013)

    Google Scholar 

  15. Guo, J., et al.: ISQ: towards a practical software stack for quantum programming. arXiv preprint arXiv:2205.03866 (2022)

  16. Guo, J., et al.: ISQ: an integrated software stack for quantum programming. IEEE Trans. Quantum Eng. (2023)

    Google Scholar 

  17. Honda, K.: Analysis of quantum entanglement in quantum programs using stabilizer formalism. arXiv preprint arXiv:1511.01572 (2015)

  18. Ittah, D., Häner, T., Kliuchnikov, V., Hoefler, T.: Enabling dataflow optimization for quantum programs. arXiv preprint arXiv:2101.11030 (2021)

  19. JavadiAbhari, A., et al.: ScaffCC: a framework for compilation and analysis of quantum computing programs. In: Proceedings of the 11th ACM Conference on Computing Frontiers, pp. 1–10 (2014)

    Google Scholar 

  20. Johnston, E., Harrigan, N., Gimeno-Segovia, M.: Programming Quantum Computers: Essential Algorithms and Code Samples. O’Reilly Media, Incorporated (2019)

    Google Scholar 

  21. Kaul, M., Küchler, A., Banse, C.: A uniform representation of classical and quantum source code for static code analysis. In: 2023 IEEE International Conference on Quantum Computing and Engineering (QCE), vol. 1, pp. 1013–1019. IEEE (2023)

    Google Scholar 

  22. Kitaev, A.Y., Shen, A.H., Vyalyi, M.N.: Classical and Quantum Computation. American Mathematical Society, USA (2002)

    Google Scholar 

  23. Koch, M., Lawrence, A., Singhal, K., Sivarajah, S., Duncan, R.: GUPPY: pythonic quantum-classical programming. https://popl24.sigplan.org/details/planqc-2024-papers/8/GUPPY-Pythonic-Quantum-Classical-Programming

  24. Matsakis, N.D., Klock, F.S.: The rust language. ACM SIGAda Ada Lett. 34(3), 103–104 (2014)

    Article  MATH  Google Scholar 

  25. Nielsen, M.A., Chuang, I.L.: Quantum Computation and Quantum Information. Cambridge University Press, Cambridge (2010)

    Google Scholar 

  26. Nielson, F., Nielson, H.R., Hankin, C.: Principles of program analysis. Springer (2015)

    Google Scholar 

  27. O’Hearn, P.W.: Incorrectness logic. Proc. ACM Program. Lang. 4(POPL), 1–32 (2019)

    Google Scholar 

  28. Paltenghi, M., Pradel, M.: LintQ: a static analysis framework for qiskit quantum programs. arXiv preprint arXiv:2310.00718 (2023)

  29. Paradis, A., Bichsel, B., Steffen, S., Vechev, M.: Unqomp: synthesizing uncomputation in quantum circuits. In: Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation, pp. 222–236. Association for Computing Machinery (2021)

    Google Scholar 

  30. Paradis, A., Bichsel, B., Vechev, M.: Reqomp: space-constrained uncomputation for quantum circuits (2022)

    Google Scholar 

  31. Parent, A., Roetteler, M., Svore, K.M.: Reversible circuit compilation with space constraints. arXiv preprint arXiv:1510.00377 (2015)

  32. Parent, A., Roetteler, M., Svore, K.M.: REVS: a tool for space-optimized reversible circuit synthesis. In: Phillips, I., Rahaman, H. (eds.) Reversible Computation, pp. 90–101. Springer International Publishing (2017)

    Google Scholar 

  33. Paykin, J., Rand, R., Zdancewic, S.: QWIRE: a core language for quantum circuits. ACM SIGPLAN Notices 52(1), 846–858 (2017)

    Article  MATH  Google Scholar 

  34. Peduri, A., Bhat, S., Grosser, T.: QSSA: an SSA-based IR for quantum computing. In: Proceedings of the 31st ACM SIGPLAN International Conference on Compiler Construction, pp. 2–14 (2022)

    Google Scholar 

  35. Perdrix, S.: Quantum patterns and types for entanglement and separability. Electron. Notes Theor. Comput. Sci. 170, 125–138 (2007)

    Article  MATH  Google Scholar 

  36. Perdrix, S.: Quantum entanglement analysis based on abstract interpretation. In: International Static Analysis Symposium, pp. 270–282. Springer (2008)

    Google Scholar 

  37. Quantinuum: guppylang (2024). https://github.com/CQCL/guppylang

  38. Rand, R., Paykin, J., Lee, D.H., Zdancewic, S.: ReQWIRE: reasoning about reversible quantum circuits. Electron. Proc. Theor. Comput. Sci. 287, 299–312 (2019)

    Google Scholar 

  39. Seidel, R., Bock, S., Tcholtchev, N., Hauswirth, M.: Qrisp: a framework for compilable high-level programming of gate-based quantum computers. PlanQC-Programming Languages for Quantum Computing (2022)

    Google Scholar 

  40. Seidel, R., Tcholtchev, N., Bock, S., Hauswirth, M.: Uncomputation in the qrisp high-level quantum programming framework. In: International Conference on Reversible Computation, pp. 150–165. Springer (2023)

    Google Scholar 

  41. Seidl, H., Wilhelm, R., Hack, S.: Compiler Design: Analysis and Transformation. Springer (2012)

    Google Scholar 

  42. Svore, K., et al.: 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 (2018)

    Google Scholar 

  43. Voichick, F., Li, L., Rand, R., Hicks, M.: Qunity: a unified language for quantum and classical computing. Proc. ACM Programm. Lang. 7(POPL), 921–951 (2023)

    Google Scholar 

  44. Winskel, G.: The Formal Semantics of Programming Languages: An Introduction. MIT Press, Cambridge (1993)

    Google Scholar 

  45. Yamaguchi, F., Golde, N., Arp, D., Rieck, K.: Modeling and discovering vulnerabilities with code property graphs. In: 2014 IEEE Symposium on Security and Privacy, pp. 590–604. IEEE (2014)

    Google Scholar 

  46. Yu, N., Palsberg, J.: Quantum abstract interpretation. In: Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation, pp. 542–558 (2021)

    Google Scholar 

  47. Zhao, P., Wu, X., Li, Z., Zhao, J.: Qchecker: detecting bugs in quantum programs via static analysis. In: 2023 IEEE/ACM 4th International Workshop on Quantum Software Engineering (Q-SE), pp. 50–57. IEEE (2023)

    Google Scholar 

Download references

Funding

This work was partially supported by “INdAM - GNCS Project”, code CUP_E53C22001930001, and partially supported by the project SERICS (PE00000014) under the MUR National Recovery and Resilience Plan funded by the European Union - NextGenerationEU, and by PRIN2022PNRR “RAP-ARA” (PE6) - codice MUR: P2022HXNSC.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Nicola Assolini .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2025 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Assolini, N., Di Pierro, A., Mastroeni, I. (2025). Static Analysis of Quantum Programs. In: Giacobazzi, R., Gorla, A. (eds) Static Analysis. SAS 2024. Lecture Notes in Computer Science, vol 14995. Springer, Cham. https://doi.org/10.1007/978-3-031-74776-2_1

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-74776-2_1

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-74775-5

  • Online ISBN: 978-3-031-74776-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics