Skip to main content

Python toolkit providing an OpenQASM 3 semantic analyzer and utilities for program analysis and compilation.

Project description

pyqasm

CI codecov Documentation Status PyPI version Python verions License

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.

Motivation

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.

Installation

pyqasm requires Python 3.10 or greater, and can be installed with pip as follows:

pip install pyqasm

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:

git clone https://github.com/qBraid/pyqasm.git
cd pyqasm
pip install .

Check version

You can view the version of pyqasm you have installed within a Python shell as follows:

import pyqasm

pyqasm.__version__

Usage Examples

Unrolling OpenQASM 3 program

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

Validating OpenQASM 3 program

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.

Contributing

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqasm-0.0.2.tar.gz (250.7 kB view details)

Uploaded Source

Built Distribution

pyqasm-0.0.2-py3-none-any.whl (57.6 kB view details)

Uploaded Python 3

File details

Details for the file pyqasm-0.0.2.tar.gz.

File metadata

  • Download URL: pyqasm-0.0.2.tar.gz
  • Upload date:
  • Size: 250.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyqasm-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6a100fdc4498683b1a5c276ace9f7938e59be99c13bd31807ed8c4edf879eb77
MD5 f1f87864d03cc23740983a28b80f42e9
BLAKE2b-256 14fbae1f3c464fdc66de9d7653a1a7cf14d057246eb63fe61891fc3dd98f781b

See more details on using hashes here.

File details

Details for the file pyqasm-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyqasm-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 57.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyqasm-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b57bd77f9dc4495d62855d02f0c249e25953573f6612da6af831a6b8d95642ce
MD5 0f0f4902330d07034caf682a17fdc76e
BLAKE2b-256 f3d1ec6e1a2f1451e098fd9822cd42070749c24db6e74e2c4491f652d336faea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page