Refinement calculus of quantum programs with projective assertions

Yuan Feng, Li Zhou, Yingte Xu, Xiaoquan XuACM Transactions on Software Engineering and Methodology 2023

Quantum programming remains a complex and error-prone endeavor, largely due to the counter-intuitive nature of quantum mechanics. While verification techniques like Hoare logic exist for post-hoc analysis, there is a significant gap in tools for the design phase—specifically, a "correct-by-construction" methodology. This paper introduces a formal refinement calculus for quantum programming that utilizes projective assertions and specialized quantum logic to bridge this gap.

The Challenge of Quantum Program Design

Classical software engineering often employs refinement calculus to systematically decompose high-level specifications into executable code. Previous attempts to adapt this to quantum systems used "effects" (positive operators) as assertions. However, effects lack the mathematical structure necessary for efficient automation. This research proposes using projective assertions—representing properties as subspaces of the Hilbert state space—to provide a more elegant and practical framework for stepwise refinement.

Methodology: A Projective Approach

The core of the framework is the prescription statement, a placeholder that defines a program's required pre- and postconditions before the actual code is written. To handle the logic of these assertions, the authors leverage Sasaki operators (implication and conjunction). These operators, originating from 1930s quantum logic, are uniquely suited to quantum programming because they account for the "disturbance" caused by asserting a property (akin to measurement).

Figure 1: An example of a quantum circuit and its corresponding program code, pCircuit, illustrating the relationship between formal specifications and executable gates.

Key technical innovations include:

  • Modular Lattice Structure: Projective assertions form a complete modular lattice, simplifying the combination and comparison of properties.
  • Computable Preconditions: Unlike classical loops, the "weakest liberal precondition" for quantum loops is often computable because the sequence of subspaces involved typically decreases in dimension.
  • Refinement Rules: A library of rules allows developers to replace abstract prescriptions with concrete operations such as unitary gates, measurements, and branching logic.

Practical Implementation and Benchmarking

The framework was implemented in a Python-based tool called Quire. Quire uses NumPy for linear algebra and supports interactive, tactic-based programming. The authors validated their approach using three benchmarks:

  1. Z-rotation gate implementation: Deriving a circuit that performs a specific rotation with a 5/8 success probability.
  2. Quantum Repetition Code: Designing a program to detect and correct bit-flip errors.
  3. Quantum-to-Quantum Bernoulli Factory: A complex algorithm used to produce specific quantum states from unknown input parameters.

The successful derivation of the Bernoulli factory—a complex algorithm involving branching and loops—demonstrates that the calculus is capable of handling non-trivial quantum programs beyond simple "toy" examples.

Conclusion and Future Directions

The current framework focuses on partial correctness, ensuring that if a program terminates, the result is correct. It does not yet guarantee termination (total correctness). Additionally, the underlying mathematical simulations in Quire face the "state space explosion" problem, scaling exponentially with the number of qubits. Future work aims to incorporate ranking functions for termination proofs and improve the tool's scalability and language expressivity, such as supporting Dirac notation and complex data structures.

Summary updated

BibTeX
@misc{feng2023refinement,
  author = {Yuan Feng and Li Zhou and Yingte Xu and Xiaoquan Xu},
  title = {{Refinement calculus of quantum programs with projective assertions}},
  year = {2023},
  eprint = {2311.14215},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.14215},
}
Figure