
Python toolkit for OpenQASM program analysis, validation and compilation.
Motivation
OpenQASM is a powerful language for expressing hybrid quantum-classical programs, but it lacks a comprehensive tool supporting the full capabilities of the language. PyQASM aims to fill this gap by building upon theopenqasm3.parser,
and providing support for semantic analysis and utilities for program compilation.
Installation
PyQASM requires Python 3.10 or greater, and can be installed with pip as follows:Optional dependencies
PyQASM offers integrations that require extra (optional) dependencies, which can be installed as follows: To use the CLI tool, install thecli extra:
visualization extra:
Install from source
You can also install from source by cloning this repository and running a pip install command in the root directory of the repository:Check version
You can view the version of pyqasm you have installed within a Python shell as follows:Using PyQASM
We will use simple QASM strings for demonstrating the core functionalities ofpyqasm API.
A detailed overview of the supported QASM features can be found in the Usage Examples section.
load and dump
The load and dump functions are used to read QASM code from a file and write QASM code to a file, respectively.
load: Reads QASM code from a file and returns aQasmModuleobject.dump: Writes QASM code from aQasmModuleobject to a file.
loads and dumps
The loads and dumps functions are used to read QASM code from a string and write QASM code to a string, respectively.
loads: Reads QASM code from a string and returns aQasmModuleobject.dumps: Writes QASM code from aQasmModuleobject to a string.
The QasmModule object
The QasmModule object is the main data structure used to represent a QASM program. The two important
methods of the QasmModule object are validate and unroll -
validate: Used to check the semantic validity of the QASM program represented by theQasmModuleobject.
unroll: Used to unroll the QASM program represented by theQasmModuleobject. Also performs semantic validation while unrolling the program.
external_gates that takes in a list of gate names
considered external to the program. Only the number of parameters and qubit arguments must
be declared for validation but the body of the gate is not required in the program.
QasmModule and its features, please refer to our
API Reference.
Currently Supported Operations for OpenQASM language
features supported, in progress, and planned for future support.
Contributing
- Interested in contributing code, or making a PR? See CONTRIBUTING.md
- For feature requests and bug reports: Submit an issue
- For discussions, and specific questions about pyqasm, or other topics, join our discord community
- For questions that are more suited for a forum, post to
Quantum Computing Stack Exchange
with the
pyqasmtag.
