Formalization of Quantum Intermediate Representations for code safety - Luo, Junjie; Zhao, Jianjun (The Journal of systems and software, 2025)
Quantum Intermediate Representation (QIR) is an LLVM-based intermediary representation developed by Microsoft for quantum program compilers. QIR’s objective is to serve as a versatile solution for quantum program compilers, irrespective of the programming languages used at the front end and the hardware utilized at the back end. This approach minimizes redundant development efforts involving intermediary representations and compilers. Currently, QIR remains in the development phase and is described informally in natural language, lacking a formal definition. This informal description leads to interpretational ambiguity and a shortage of precision when implementing quantum functions. Our work aims to address this gap by providing formal definitions for QIR’s data types and instruction sets. We strive to establish correctness and safety assurances for operations and intermediate code conversions within the QIR framework. To substantiate our design, we present potentially unsafe QIR code instances that our formal approach can detect and rectify. This contribution enhances the reliability and robustness of quantum program development within the QIR context. •A formalized syntax for QIR, refining existing structures and introducing QIR-specific data types.•Developed semantics for key QIR instructions, ensuring safe execution of quantum programs.•A qubit management model for unsafe practices detecting.•Validation on real QIR code to demonstrate the effectiveness of the formal methods in practice.