Quasar.jl - Pure Julia OpenQASM3 lexing and parsing
Links: GitHub
Quasar.jl is a pure Julia package for lexing and parsing OpenQASM, a popular intermediate representation for quantum programs. Quasar supports:
- Subroutines
- Custom gate definitions
- Gate modifiers
- Control flow
- Inputs
- Type casting
- Supplying your own
pragmadefinitions
What’s not yet supported:
- Output variables (coming soon!)
- OpenPulse
angletypes and their logic (coming soon!)
You can parse an OpenQASM program, str, in string form like so:
parsed = Quasar.parse_qasm(str)
visitor = Quasar.QasmProgramVisitor(inputs)
visitor(parsed)
The process occurs in two steps: first an AST is generated then visited with any inputs (a Dict{String, <:Any}), so that you can re-use the AST with various sets of inputs.
Then you can query instructions(visitor) to get a list of CircuitInstructions, which you can turn into your own program’s gates and other instructions using a package like StructTypes.jl..
Quasar.jl is built on top of Automa.jl, and many thanks to the developers and maintainers of that package for creating it and answering my many questions.
Future plans are to add proper support for angles and outputs, and improve documentation for pragmas and generating your idiomatic gate dialects.