Specifying the OpenQASM Version in Your Programs

    Selecting the correct OpenQASM version string is one of the first and most important steps in quantum programming. The version string tells the quantum execution environment which set of syntax rules and features to apply to your code. This chapter provides a comprehensive understanding of the OpenQASM version string and its correct usage with practical examples.

    What is the OpenQASM Version String?

    The version string is an essential directive at the beginning of an OpenQASM file that specifies the version of the language used. This directive ensures compatibility and proper interpretation across different quantum processing environments.

    The version string is formatted as "OPENQASM V.v;", where "V" is the major version and "v" is the minor version number.

    Example of a Version String

    For example, to specify that your program is written in OpenQASM version 2.01:

    OPENQASM 2.0; // Indicates we are using OpenQASM version 2.0 [^1]
    

    Rules for Version String Declaration

    There are two fundamental rules for properly declaring the version string:

    1. Uniqueness: There must only be one version string present in any OpenQASM file.
    2. Positioning: The version string must be the first executable statement in the file.

    Experiment: Declaring the Version String

    Here's a valid OpenQASM program with a correctly positioned version string. 12345

    Diagram

    // PhotonQ Experiment: Version String Declaration [^5] OPENQASM 2.0; // Correctly specifies OpenQASM version [^1] include "qelib1.inc"; // Including the standard library for convenience [^2] // Quantum gate application qreg qubits[2]; // Declaring a quantum register with two qubits [^3] cx qubits[0], qubits[1]; // Applying a CNOT gate to the qubits [^4]

    Translation

    Powered by Perceval, Qiskit, PyZX

    Not run yet

    Simulation

    Not run yet

    Incorrect Examples

    Multiple declarations of the version string are not allowed and will result in an error:

    OPENQASM 2.0; // Redundant declarations cause conflicts and errors
    OPENQASM 3.0;
    

    Placing the version string after executable lines is incorrect and should be avoided:

    // Declaration before the version string results in an invalid program structure
    qreg qubits[4]; // This will cause an error
    OPENQASM 2.0;   // Incorrectly placed after an executable line
    

    Understanding and using the OpenQASM version string correctly is foundational for constructing valid and functional quantum programs. In our upcoming chapters, we'll delve into more exciting aspects of quantum computing using OpenQASM, like working with quantum registers and implementing quantum gates!

    Footnotes

    1. Version String Documentation 2

    2. Include Documentation

    3. Quantum Registers Documentation

    4. CNOT Gate Documentation

    5. Declaring the Version String

    Comments
    Syntax

    Exploring

    Quantum Frontiers

    Join us on our journey to push the boundaries of quantum computing and unlock the potential of this transformative technology, as we strive to make quantum accessible to all and shape the future of computing.

    Register Now
    University of Vienna Logo

    Links

    DocumentationExperimentsImprintContact

    Copyright © 2024 Walther Group, Faculty of Physics, University of Vienna. All rights reserved.