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.0.4.tar.gz (110.6 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.0.4-cp314-cp314-win_amd64.whl (210.8 kB view details)

Uploaded CPython 3.14Windows x86-64

pyqasm-1.0.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (734.7 kB view details)

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

pyqasm-1.0.4-cp314-cp314-macosx_11_0_arm64.whl (213.3 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyqasm-1.0.4-cp314-cp314-macosx_10_15_x86_64.whl (223.9 kB view details)

Uploaded CPython 3.14macOS 10.15+ x86-64

pyqasm-1.0.4-cp313-cp313-win_amd64.whl (209.1 kB view details)

Uploaded CPython 3.13Windows x86-64

pyqasm-1.0.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (740.5 kB view details)

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

pyqasm-1.0.4-cp313-cp313-macosx_11_0_arm64.whl (213.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyqasm-1.0.4-cp313-cp313-macosx_10_13_x86_64.whl (223.6 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

pyqasm-1.0.4-cp312-cp312-win_amd64.whl (209.3 kB view details)

Uploaded CPython 3.12Windows x86-64

pyqasm-1.0.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (752.1 kB view details)

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

pyqasm-1.0.4-cp312-cp312-macosx_11_0_arm64.whl (213.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyqasm-1.0.4-cp312-cp312-macosx_10_13_x86_64.whl (224.3 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

pyqasm-1.0.4-cp311-cp311-win_amd64.whl (209.0 kB view details)

Uploaded CPython 3.11Windows x86-64

pyqasm-1.0.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (753.2 kB view details)

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

pyqasm-1.0.4-cp311-cp311-macosx_11_0_arm64.whl (213.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyqasm-1.0.4-cp311-cp311-macosx_10_9_x86_64.whl (223.6 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

pyqasm-1.0.4-cp310-cp310-win_amd64.whl (208.9 kB view details)

Uploaded CPython 3.10Windows x86-64

pyqasm-1.0.4-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (716.7 kB view details)

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

pyqasm-1.0.4-cp310-cp310-macosx_11_0_arm64.whl (214.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyqasm-1.0.4-cp310-cp310-macosx_10_9_x86_64.whl (224.3 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pyqasm-1.0.4.tar.gz
  • Upload date:
  • Size: 110.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyqasm-1.0.4.tar.gz
Algorithm Hash digest
SHA256 2a7a4505cc1e5e15e7c3a97149d1dfeedc8165ce937c136c700f5bbf5067828c
MD5 c84da54ebb12b7fe2522e3ae56543d88
BLAKE2b-256 bd84763307de6fc221864019622b639c6433fe3e757cc9ad28e86563836f1725

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyqasm-1.0.4-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 210.8 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyqasm-1.0.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 075299a575111d597754c5592b3e4fa5e7d24d53f9bbd73a748f2beb41dc62ef
MD5 a104ec87e55f005b460b09a6934054bc
BLAKE2b-256 26ac77b905215b336b533ae01ac4870c5bb5512b9df22454b86265c34732bf64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e58bc3afb64214b6fb142573ae07b11be1e2bec07b57905e6d5cafe2fe6ba1b2
MD5 8c82b94ed5f4ee48b0e7d781743c9433
BLAKE2b-256 fbba5b75940ab8bc08f19cb7701e844aee27d9a6cb82c6c1150bace06fe4d649

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3da719066bbb2f066b3ea7c1d23ad27db7bd5934f1c61828f320e91528c40ea0
MD5 d183e7419bd8298c90bdabded9b4fb85
BLAKE2b-256 920faeaa2161ca91b6d63020d8fa900820ac39c2804b76ba9a453aeab92c6d3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 16e2df3efa00acea02405f4ff763013de21dfba5517911bfa19c4088c590b7a3
MD5 85e78022e528ada22ccdcb65b63c7fdb
BLAKE2b-256 c8b086d5660fe278048eb2718aa080aa51273361599e7d874f3bff66515840b4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyqasm-1.0.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 209.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyqasm-1.0.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 aa2cf3c25392f9b83c98fae73e3dc020e96ffaefbaa7952ed7027bfec97f2627
MD5 574e5cc4c0bb225c7cebc0115a03c6c9
BLAKE2b-256 5a3552e511328a7eea251b9f0294646987757ca6612119e6bd1d2374aa6c72eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2f21969aefefdf18858508476a694df5de927f4512199c590b0031c3ec688bf5
MD5 79809e483f4895f6abcc2324203774b9
BLAKE2b-256 d10d9a1ebef8198f21978673f086cae80f794501f53e6d35756367cfbc990480

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5cc3b044df8d4c9c1c9bee1e43e9de4fc19afd7b749d75d89da8b9c4eb588493
MD5 810c698040a388b3e76e8a324de38f23
BLAKE2b-256 a4fa6ea1223980493e06e81dcdcfa781e5386d43231df6ef9e2a79bbf2c9401a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 73fa02346daebc2682673e98f2008b0bcb2b53ab55185f9344bcab5b99036ab7
MD5 fae361c3c61400714ca9791acca7684b
BLAKE2b-256 1b7ed9111ed47dc9828278e2110de3f5dc10ba92b055c00004ab757985bd457f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyqasm-1.0.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 209.3 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyqasm-1.0.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1a28e7b57a1d7715dd9f3ecb698651d249cf3d14049fff561e73ed79876d3fe2
MD5 080aaa8ddf48a401a008ad544e9d1fa8
BLAKE2b-256 26f1da4f3f21918b74102c8ac03d293b3b74afd426c8d954d92fbdeee96655fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 19b5155079af70cdf8adc41e5308c5d5353fe2441ebf55e14fc1c887a7326bc0
MD5 4023ca1a7fbecbc829d7f723d94f880d
BLAKE2b-256 b4784c70152f8d8a15aab6eca26b45008353c8311f51a386e39b962e4f10fb5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 101efb86d1263eef7d625c01ef4a89de5922529af5214e1f7edc71394ede7781
MD5 a5d4c759cb3ccce510ab5ad75dd57de9
BLAKE2b-256 79413ea7d3fc7e7dd9d2f6fe2be30430b95fda85ac30e624f3b653f7101b6bb9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 6b4a1ffb74719768bd42adfa2348d6a26da6b446b9c5afdcbfeef65f4da4f7aa
MD5 a083c23d68f2da72e049358e40e29ea9
BLAKE2b-256 164c0dd38e660feb46297047f3aa0dbbdcbd1555e5206a7252db135e2aadd9b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyqasm-1.0.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 209.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyqasm-1.0.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 52bfa135962f6a6f58607012a14975621bfac0c64b2bec13a8b21b20852037e7
MD5 40fc2a45dc1fbdd20ade3c3141e03615
BLAKE2b-256 a595afeea4857e43f6d7276151e9c49cd0ffd2ee78765d1994d689e5a988d998

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 891d074a481ba5d5311b85664d6a53bc5eb37f9bd2e398f0e14497cc6b6aa1cf
MD5 0f0ac5cf56507af1c50196a1d5ebdb4d
BLAKE2b-256 13b0ad36796290353b0bff3a512fc4234733dfc2fb44df11365f47d865f6d24f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e8cb89c6c2742a8c003d5fd8f1d9615a8f75aad3aa1adfbb1a6421622d1a6290
MD5 2dc0a9dca8f87464e056d0a53ae2dc4e
BLAKE2b-256 a367e1b53f3834bddbe44beeaffa246ee2477a34bdf77217794002734b88aa11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 18e811b37b5fcd9f84f94a665af8b6ae290b63a3e939bdbe5b4b934c19349dad
MD5 94f591fa3dcb5a5e8555d77287c3d2f6
BLAKE2b-256 b2ccc861db292d6c9e1e9abe415e6b44ae329e032426b8e924623378f67f3d34

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyqasm-1.0.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 208.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyqasm-1.0.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b6f3218f6f234072788980d6d096523eb5b0be030afac274fab1213e64caa92b
MD5 1ae2a0a23d2943d28f58ed6c9a340f22
BLAKE2b-256 a0cb1a85e842fd2cfe2959527e0d6eeb1b6266e85ae9c1b1564a2a151d7ec99a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fb04119beb0fa60cfd3c9926f41941ce545e3fe58240ab04e0de0f8f04837daf
MD5 122eee4f85d55d9d89f9190b08861482
BLAKE2b-256 957d23bbccc2755c075237763cecff7cf4a05636f0fe943a7ac76a6bf93c293d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a760884ca5aae445f3833e4c78d8fa4773f6555ff41a3ec3fb0ef32238a49af
MD5 f3394cc5aa518d41a8187ee8c02f8991
BLAKE2b-256 c62a3c30f08a03182523fe8fc98542ec61b6982a69ee8e60ab456eb6854aba6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqasm-1.0.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 291cec3585cdcf0ae575b21640571a19726db737f765f0109947410fba9f62bf
MD5 385a8d416493168d6a6b79f9afe45667
BLAKE2b-256 72002d9ebdb81a8ccf0f8ac79e1aa067f475d831d04b074fd41b1fd2e237a42c

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

21 files

This release

1.0.4 This release

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