Python toolkit providing an OpenQASM 3 semantic analyzer and utilities for program analysis and compilation.
[!WARNING] This project is "pre-alpha", and is not yet stable or fully realized. Use with caution, as the API and functionality are subject to significant changes.
The current OpenQASM 3 standard 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 the openqasm parser, and providing support for semantic analysis and utilities for program compilation.
pyqasm requires Python 3.10 or greater, and can be installed with pip as follows:
pip install pyqasm
You can also install from source by cloning this repository and running a pip install command in the root directory of the repository:
git clone https://github.com/qBraid/pyqasm.git
cd pyqasm
pip install .
You can view the version of pyqasm you have installed within a Python shell as follows:
import pyqasm
pyqasm.__version__
import pyqasm
program = """
OPENQASM 3;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
h q[0];
cx q[0], q[1];
c = measure q;
"""
unrolled_qasm = pyqasm.unroll(program)
print(unrolled_qasm)
For a more complex example, see the Deutsch Josza program unrolling
import pyqasm
program = """
OPENQASM 3;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
// create a Bell state
h q[0];
cx q[0], q[1];
// measure the qubits
measure q -> c;
"""
pyqasm.validate(program)
validate
returns None if the program is semantically valid, otherwise raises an Exception. See the validation example for more insight into the capabilities of our analyser.
qbraid
tag.