openqasm / qe-qasm

A LALR(1) OpenQASM Parser and AST Generator.
Apache License 2.0
10 stars 4 forks source link

qe-qasm

The Quantum Engine's implementation of an OpenQASM v3.0 lexer and parser written in C++. The Quantum Engine is a system comprised of low-level software components enabling the execution of quantum programs in quantum hardware. The parser is based on Flex and Bison, and therefore it is a LALR parser.

This is a CMake Project. It builds four libraries:

and a simple CLI tool QasmParser for demonstrations and testing.

These libraries can be used to work on further development of a fully functional OpenQASM 3 compiler. In particular, the library is used by the qe-compiler to parse OpenQASM 3 source files to MLIR.

Contents

Building from source

The parser's build system is driven by Cmake. For simplicity of building, packaging and distribution we provide a conan packager and recommend this for development/integration.

Currently the supported platforms are Linux and OSX. It is possible to build on Windows using WSL.

Conan

Building for development and debugging

Make

Running Tests

Static Code Checks

The easiest, fastest, and most automated way to integrate the formatting into your workflow is via pre-commit. Note that this tool requires an internet connection to initially setup because the formatting tools needs to be downloaded.

In environments without an internet connection, please see one of the other solutions documented below.

These should be installed and setup prior to any development work so that they are not forgotten about. The setup is straight forward:

pip install pre-commit
pre-commit install

The first time pre-commit install is run, it will take a minute to setup the environment.

After installation, the hooks will be run prior to every commit, and will be run against all staged changes. Optionally, you can trigger this run via pre-commit run.

If you wish to run the hooks against the entire repository, run:

pre-commit run --all-files

The other checks that are performed can be seen in .pre-commit-config.yaml. At the time of writing, these are:

CI and Release Cycle

Please keep the following points in mind when developing:

CI

CI is currently run on every pull request against the main branch. All CI processes are based on the conan package build.

Branches

Tags

Git tags are used to tag the specific commit associated with a versioned release. Tags must take the form of v<major>.<minor>.<patch>-<labels>. For example the semver v1.5.1 would point to the parser release with major version 1, minor version 5, and, patch version 1. The current development version would therefore be MINOR+1 v1.6.0. All official releases when tagged must always point to the current HEAD of a release branch.

Release cycle

To release a version a new version:

Example release cycle

For this example assume the current release of the parser is version 0.5.1. This will correspond to a commit on release/0.5. The project's development branch reflects the development state of the next release - 0.6.0 and is referred to by version as 0.6.0-dev.

To trigger a bugfix release - 0.5.2:

  1. Create a PR into release/0.5 with all required changes. The PR ideally should begin with title of the form [Backport] <Title>. These may be backported commits from main.
  2. Upon merger of the PR tag the HEAD of release/0.5 with v0.5.2 and push to Github.

To trigger a minor release - 0.6.0:

  1. Create a new release branch release/0.6 using the current development branch (main) as the base branch, eg., git checkout -b release/0.6 main.
    • Note: Branch protection rules are in place for release branches and these steps may only be completed by project administrators.
  2. Push this branch to Github.
  3. Tag the branch with v0.6.0 and push to Github.