We would like to run a small experiment of adding an OpenQASM dialect in MLIR. Having a native
representation of the OpenQASM standard available in MLIR would be beneficial in several ways,
like facilitating the translation of an OpenQASM text file into and out of MLIR, enabling
transformations on OpenQASM programs, and more generally improving inter-operability between tools.
Goal
For this experiment we would like to focus on the representation of OpenQASM in MLIR and its
translation to the OpenQASM text format.
For the first step, we would like to keep things simple and create a new dialect called "OpenQASM"
with only three elements in it:
It may also be helpful to look at the existing dialect files provided there, although for this
implementation the full structure does not need to be replicated. It would be sufficient to have a single
TableGen (.td), header (.h), and source (.cpp) file for the dialect components and the
translation pass, but other configurations are also fine.
For the translation pass, the method to produce the textual OpenQASM format from the IR can be
freely chosen, although one possible approach may simply iterate over the MLIR module and print the
equivalent OpenQASM out to console. See also:
Context
We would like to run a small experiment of adding an OpenQASM dialect in MLIR. Having a native representation of the OpenQASM standard available in MLIR would be beneficial in several ways, like facilitating the translation of an OpenQASM text file into and out of MLIR, enabling transformations on OpenQASM programs, and more generally improving inter-operability between tools.
Goal
For this experiment we would like to focus on the representation of OpenQASM in MLIR and its translation to the OpenQASM text format.
For the first step, we would like to keep things simple and create a new dialect called "OpenQASM" with only three elements in it:
Let's have a look at a simple OpenQASM program:
We can represent this program in MLIR using the dialect sketched out above, where the IR might look something like this:
We would then like to be able to traverse the MLIR and print out the program in the OpenQASM format.
Technical Details
A few more details on the dialect and operations which could be helpful:
oq.
was used in the exampleq
in the example) and known globallyThe MLIR documentation has a few resources about defining new dialects, notably:
It will be easiest to set up the dialect in the existing Catalyst source tree.
It may also be helpful to look at the existing dialect files provided there, although for this implementation the full structure does not need to be replicated. It would be sufficient to have a single TableGen (
.td
), header (.h
), and source (.cpp
) file for the dialect components and the translation pass, but other configurations are also fine.For the translation pass, the method to produce the textual OpenQASM format from the IR can be freely chosen, although one possible approach may simply iterate over the MLIR module and print the equivalent OpenQASM out to console. See also:
The pass could then be registered with the quantum-opt tool and run as
quantum-opt --translate-to-openqasm example_ir.mlir
.Installation Help
Refer to the Catalyst installation guide for how to install a source build of the project.