Skip to main content

PyQASM Logo (Light Mode) PyQASM Logo (Dark Mode)

CI codecov GitHub Pages PyPI version PyPI Downloads Python verions License

Python toolkit providing an OpenQASM 3 semantic analyzer and utilities for program analysis 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 the openqasm3.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

Optional Dependencies

PyQASM offers optional extras such as -

  1. cli : command-line interface (CLI) functionality
  2. visualization: for program visualization
  3. pulse : pulse/calibration features (in progress)

To install these features along with the core package, you can use the following command:

pip install 'pyqasm[cli,pulse,visualization]'

You can also install them individually. For example, to install the CLI features only, you can run:

pip install 'pyqasm[cli]'      

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__

Key Features: Unroll & Validate OpenQASM 3 Programs

PyQASM offers robust support for the extensive grammar of OpenQASM 3, including custom gates, subroutines, loops, conditionals, classical control, and more. Its core utilities allow you to validate programs for semantic correctness and unroll (flatten) all high-level constructs into a linear sequence of basic quantum operations, ready for execution or further compilation.

Highlights

  • Comprehensive Grammar Support: PyQASM supports the full breadth of OpenQASM 3 operations, and backward compatibility with OpenQASM 2, including:

    • Classical and quantum registers
    • Loops (for, while)
    • Conditionals (if, else)
    • Parameterized and custom gates
    • Subroutine inlining
    • Switch statements
    • Classical expressions and assignments
    • Variables and arrays
    • Type casting and conversions
    • Built-in and user-defined constants
    • Quantum-classical interaction (measurement, reset, etc.)
    • Inclusion of standard libraries (stdgates.inc, etc.)
  • Unrolling:
    Expands all custom gates, loops, subroutines, branches, etc. into a flat, hardware-ready sequence of instructions.

  • Validation:
    Performs semantic analysis to ensure programs are correct and conform to the OpenQASM 3 specification.


Example: Unroll and Validate a Complex QASM Program

Below is an example demonstrating PyQASM's efficacy on a non-trivial OpenQASM 3 program. This program uses custom gates, loops, and classical control, and is fully unrolled and validated by PyQASM:

from pyqasm import loads, dumps

qasm = """
OPENQASM 3;
include "stdgates.inc";

gate h2 a, b { h a; h b; }
def parity_flip(qubit[4] q) {
    for int i in [0:3] {
        if (i % 2 == 0) {
            x q[i];
        }
    }
}

qubit[4] q;
bit[4] c;

h2 q[0], q[1];
parity_flip(q);

for int i in [0:3] {
    measure q[i] -> c[i];
}
"""

module = loads(qasm)      # Parse and build the program
module.validate()         # Check for semantic errors
module.unroll()           # Flatten all gates, loops, and subroutines

print(dumps(module))      # Output the fully unrolled QASM

Output (fully unrolled QASM):

OPENQASM 3.0;
include "stdgates.inc";
qubit[4] q;
bit[4] c;
h q[0];
h q[1];
x q[0];
x q[2];
c[0] = measure q[0];
c[1] = measure q[1];
c[2] = measure q[2];
c[3] = measure q[3];

PyQASM ensures your OpenQASM programs are semantically correct and hardware-ready, supporting the language's most advanced features with ease.

Resources

Contributing

GitHub QCSE Discord

License

Apache-2.0 License

Download files

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

Source Distribution

pyqasm-1.1.0.tar.gz (120.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyqasm-1.1.0-cp314-cp314-win_amd64.whl (220.4 kB view details)

Uploaded CPython 3.14Windows x86-64

pyqasm-1.1.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (747.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pyqasm-1.1.0-cp314-cp314-macosx_11_0_arm64.whl (222.8 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyqasm-1.1.0-cp314-cp314-macosx_10_15_x86_64.whl (233.5 kB view details)

Uploaded CPython 3.14macOS 10.15+ x86-64

pyqasm-1.1.0-cp313-cp313-win_amd64.whl (218.7 kB view details)

Uploaded CPython 3.13Windows x86-64

pyqasm-1.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (753.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pyqasm-1.1.0-cp313-cp313-macosx_11_0_arm64.whl (222.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyqasm-1.1.0-cp313-cp313-macosx_10_13_x86_64.whl (233.2 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

pyqasm-1.1.0-cp312-cp312-win_amd64.whl (218.9 kB view details)

Uploaded CPython 3.12Windows x86-64

pyqasm-1.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (755.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pyqasm-1.1.0-cp312-cp312-macosx_11_0_arm64.whl (223.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyqasm-1.1.0-cp312-cp312-macosx_10_13_x86_64.whl (233.8 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

pyqasm-1.1.0-cp311-cp311-win_amd64.whl (218.6 kB view details)

Uploaded CPython 3.11Windows x86-64

pyqasm-1.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (762.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pyqasm-1.1.0-cp311-cp311-macosx_11_0_arm64.whl (223.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyqasm-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl (233.1 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

pyqasm-1.1.0-cp310-cp310-win_amd64.whl (218.5 kB view details)

Uploaded CPython 3.10Windows x86-64

pyqasm-1.1.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (726.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pyqasm-1.1.0-cp310-cp310-macosx_11_0_arm64.whl (223.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyqasm-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl (233.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pyqasm-1.1.0.tar.gz
  • Upload date:
  • Size: 120.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyqasm-1.1.0.tar.gz
Algorithm Hash digest
SHA256 4647d0e369c412d5cf0088f6adcdd20d8d0c7811c312bf8db78b6d632e348bc1
MD5 b309a3210a007d3181015a4fa56524fd
BLAKE2b-256 6ffaa8465b29da77fadf7966076c8b75eff2ae994c55105fd7970676e85fe779

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pyqasm-1.1.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 220.4 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyqasm-1.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ba826a86fab36142b0da6e2e827aa377b8d3b00ec356487870b1c92dc6b9f5f7
MD5 fd72f9e1c61c0fdde69ec2242ecd00c5
BLAKE2b-256 bb954dc699545f2aea2a6dd64efdc6e75835aaeb72dfe7573ede3ab4cdc8bd95

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 369a96faff19a1eeb557619ac71c719cfe3c90b19a8cc692b2fe696fc57bb65e
MD5 fdd53fb3e93d1f09bd62ab5a6c9d8d54
BLAKE2b-256 beb410ed06eb716ff7e40ce2c923b4f799fe48d576f628685e57899df532c1b4

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a280e844e21ffcd98403976d1d5ab711cdf7715182ea56b2cf3c1e0424a43efe
MD5 9c6963ca46ed09c10adafd5d0c1af99d
BLAKE2b-256 8f647fbaa133b0203ff667645c303e490b17fd2e5d8d4bda87b7d4c5b8d7c310

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp314-cp314-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ee88fd82385258cb645f09eb637214600123fc5275cb3f8ec2ba1571f1b69a94
MD5 ad0e3b6cf4551616c6477dd7664b7001
BLAKE2b-256 658093911236ac92f1dfca9c65584d67606fea205742bcfdab6cec774e62cab8

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pyqasm-1.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 218.7 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyqasm-1.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5643f90aca14df2b80c7ce220716880ab3dcea171f2a7cdd4134d5ba2f3d6652
MD5 f13da828e83c5045401d0218817ba177
BLAKE2b-256 d19762891f76d3a51d3311244f56f44fee4628ad83c5bb9e08b0507790ae877b

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5b026d5ebd002ae16f8dd41a0ba74124d37e1e6442b8ca2f263e13ac52313e28
MD5 459170ef2b8cbeba00a1f235707fa8da
BLAKE2b-256 ff2098147a8da8d2e7ad06a02ba7f3cee49df8d13e5d1df4ca403e40f9414d15

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e65d9a341a4f43cc5d0cad72c1f5b585b0c2308aa1955928229938d317b8ce0
MD5 d5ce3458f47cae6b9b12eb282fc9b578
BLAKE2b-256 e588f0b31e96fb9ceb09e6aaa9e8dec35ac111832cbd22b23957599799ca2cf6

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 18722de0244db76a2a591eee709fe4d974731993da67ed0bb4254090e8626aed
MD5 7a8afaa96848ce0b195c05c347b6519b
BLAKE2b-256 b1d871ab8e233089df20ada1936d6b86e1fb9d079710a4056664637dec3af7f3

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyqasm-1.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 218.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyqasm-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 97f237bdcb2b3f997fd8796842b3245757fd5bea3407c3aa4d047c7013d0274c
MD5 6bd9e2dc6823429551bd094e1f3be642
BLAKE2b-256 d74e7967cdeb53a8ef77d7337e891524a972efdb9d24f207be940af651c07e01

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e29a95caef6e65e65d7dd99d6b50003e6ddd1cd0b85029d5a961054cb18a0ced
MD5 89624d1c1366faa070766f0affc94855
BLAKE2b-256 70479964090a71f42ace0acfeb28eb1ddf641c34937eb289bb97c2660fff7c7f

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f6fc9f7d13085d1a1d876a03f0ceec4369ab76c5ba56b99b6222d512b7fdc161
MD5 5f673f92b672cfe45aaa5efc4dc7e1ec
BLAKE2b-256 262ca3275b48211626593850a563ea1340e5437589b40efe692003f8403c6442

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 c085db919af2fd453c7f252fb8f00622d6349ceed755297b77e63abe331ec5f6
MD5 c3b1ab5c5ef51a13a87ecc72dbd5eaa7
BLAKE2b-256 c5f7806877c918d82e45e2424ebba6efe491a0eaa06db72814dbd5df7276812f

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyqasm-1.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 218.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyqasm-1.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a1c6674331871ef519fe53918152a9233a118c47bde372c6bcf5f6c1168acf7f
MD5 290ff99ae247cf465370fa171eba520e
BLAKE2b-256 64ff02b5bee54ae772be116905d7a22b78d5d7f90b326c344fe6b37149e80642

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c76def15ee9fa7611dfe04234097486030e5094a7688d3b18d534289c45eb77d
MD5 51fbe2b1ed6ce49df66197b0b6b9c4b3
BLAKE2b-256 d31e7593b253dd77368b44ba214abd5ffd619512dec5bfed7f4f0a46067dd1a9

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b05c695785e42883d35e8af207463bd52f96a3c9b5179dbf1ea9ba832017d1aa
MD5 8daf86ee73866ae89b2af7eec9014834
BLAKE2b-256 8c2a663f8b57875486c5acd989cd80f8c959526e4ab566f46ad16c5bd876d389

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7d0ed2bc2022e95950223abf40ff9731e04eefa95d95ab81d718e448b71b45fc
MD5 d0cd1e8412de9d319db8308691b4c6e8
BLAKE2b-256 009cec4848ef4e91deba42b1d108755d8a4817da9aa91fe1c519cdeffbc90bcb

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyqasm-1.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 218.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyqasm-1.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 38717fb8050cf66a4047acf675930c4e06b3a830fa4eba9822f0c116839edc79
MD5 59c36b397f627b1194270b122b2956ae
BLAKE2b-256 a9dda4bf83ba9b35a6f839d429f780c991db9281044fb7e0c4927bd2dc4401af

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7b7e925abd4278486e61791a25c822b7c956b7b7adc5fba624af9930b3abbe82
MD5 9098c0ecbb6f21749d0c4205d7ba154e
BLAKE2b-256 cb0388eb0daac0a9509e353e88e56b4ef72cfcf8ab518241fc42db0cbc50ff76

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fa41d58316d8d55f44293ba29b9de65c784db8817db0118829109b2351c05d2f
MD5 2cc115fba1b267000114784435b10ab3
BLAKE2b-256 9b516edc1818d0c90bd70a1b72ccc1837b3b4ef8d852390dda4302ef25e6b3b1

See more details on using hashes here.

File details

Details for the file pyqasm-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyqasm-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f1c2246dfcf9f7c4bbbad9a087eda6e84b37cccd75d9e7b15a571c4ef9bccd79
MD5 d158a8eb6f5beb5315afa01b5dfd8b0e
BLAKE2b-256 90c36efbc56b9d255ff1aa16b536b35a5028026e34537b2d7135f9ecc3439cfc

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0 This release

21 files

1.0.4

21 files

1.0.3

21 files

1.0.2

21 files

1.0.1

17 files

1.0.0

17 files

0.5.0

17 files

0.4.0

17 files

0.3.2

17 files

0.3.1

17 files

0.3.0

17 files

0.2.1

17 files

0.2.0

17 files

0.1.0

17 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

0.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page