pyqasm

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

https://github.com/qbraid/pyqasm

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.4%) to scientific vocabulary

Keywords

openqasm quantum-computing
Last synced: 6 months ago · JSON representation ·

Repository

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

Basic Info
Statistics
  • Stars: 18
  • Watchers: 3
  • Forks: 18
  • Open Issues: 28
  • Releases: 13
Topics
openqasm quantum-computing
Created over 1 year ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Codeowners

README.md

pyqasm

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.

Env Badge

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:

bash 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: bash pip install 'pyqasm[cli,pulse,visualization]'

You can also install them individually. For example, to install the CLI features only, you can run: bash 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:

bash 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:

```python

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:

```python 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): 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

Owner

  • Name: qBraid
  • Login: qBraid
  • Kind: organization
  • Email: contact@qbraid.com
  • Location: United States of America

Quantum Computing Platform

Citation (CITATION.cff)

cff-version: 1.2.0
title: 'PyQASM: Python toolkit for OpenQASM program analysis and compilation.'
message: If you use this software, please cite it using the metadata from this file.
type: software
authors:
- given-names: Harshit
  family-names: Gupta
  affiliation: qBraid Co.
- given-names: Ryan James
  family-names: Hill
  affiliation: qBraid Co.
  orcid: https://orcid.org/0009-0006-9222-0810
repository-code: https://github.com/qBraid/pyqasm
url: https://qbraid.github.io/pyqasm/
repository-artifact: https://github.com/qBraid/pyqasm/releases/tag/v0.5.0
keywords:
- python
- quantum-computing
- openqasm
- qbraid
license: Apache-2.0
version: 0.5.0
date-released: '2025-08-14'

GitHub Events

Total
  • Fork event: 12
  • Create event: 109
  • Commit comment event: 1
  • Release event: 10
  • Issues event: 128
  • Watch event: 11
  • Delete event: 100
  • Member event: 1
  • Issue comment event: 215
  • Push event: 331
  • Pull request review comment event: 280
  • Pull request review event: 313
  • Pull request event: 253
Last Year
  • Fork event: 12
  • Create event: 109
  • Commit comment event: 1
  • Release event: 10
  • Issues event: 128
  • Watch event: 11
  • Delete event: 100
  • Member event: 1
  • Issue comment event: 215
  • Push event: 331
  • Pull request review comment event: 280
  • Pull request review event: 313
  • Pull request event: 253

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 92
  • Total pull requests: 255
  • Average time to close issues: 19 days
  • Average time to close pull requests: 2 days
  • Total issue authors: 7
  • Total pull request authors: 17
  • Average comments per issue: 0.42
  • Average comments per pull request: 0.96
  • Merged pull requests: 210
  • Bot issues: 0
  • Bot pull requests: 44
Past Year
  • Issues: 90
  • Pull requests: 255
  • Average time to close issues: 19 days
  • Average time to close pull requests: 2 days
  • Issue authors: 6
  • Pull request authors: 17
  • Average comments per issue: 0.42
  • Average comments per pull request: 0.96
  • Merged pull requests: 210
  • Bot issues: 0
  • Bot pull requests: 44
Top Authors
Issue Authors
  • TheGupta2012 (61)
  • ryanhill1 (20)
  • Sola85 (3)
  • arulandu (3)
  • vinayswamik (2)
  • rjain37 (2)
  • bachase (1)
Pull Request Authors
  • TheGupta2012 (105)
  • ryanhill1 (50)
  • dependabot[bot] (23)
  • github-actions[bot] (21)
  • vinayswamik (18)
  • arulandu (10)
  • AshwinKaliyaperumal (6)
  • PranavTupe2000 (4)
  • arunjmoorthy (3)
  • samuraikillers (3)
  • antalszava (2)
  • luffy-orf (2)
  • bhagyasreey (2)
  • LukeAndreesen (2)
  • Sola85 (2)
Top Labels
Issue Labels
enhancement (58) bug (17) qasm3 (14) good first issue (9) no-qc-knowledge-reqd (7) documentation (6) qasm3-coverage (5) duplicate (2) program-validation (2) error-handling (2) gate-decomposition (2) qosf (2) optimization (1) llm-assisted (1) qasm2 (1) help wanted (1)
Pull Request Labels
dependencies (23) github_actions (9) python (2)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 10,839 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 15
  • Total maintainers: 1
pypi.org: pyqasm

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

  • Versions: 15
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 10,839 Last month
Rankings
Dependent packages count: 10.2%
Average: 34.0%
Dependent repos count: 57.7%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/docs.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/format.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/main.yml actions
  • actions/checkout v4 composite
  • actions/download-artifact v4 composite
  • actions/setup-python v5 composite
  • actions/upload-artifact v4 composite
  • codecov/codecov-action v4.4.1 composite
.github/workflows/pre-release.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
  • pypa/gh-action-pypi-publish release/v1 composite
.github/workflows/release.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
  • pypa/gh-action-pypi-publish release/v1 composite
pyproject.toml pypi
  • numpy *
  • openqasm3 [parser]>=1.0.0,<2.0.0
.github/workflows/bump-version.yml actions
  • actions/checkout v4 composite
  • actions/setup-python v5 composite
.github/workflows/gh-pages.yml actions
  • actions/checkout v4 composite
  • actions/configure-pages v5 composite
  • actions/deploy-pages v4 composite
  • actions/setup-python v5 composite
  • actions/upload-pages-artifact v3 composite
.github/workflows/test-release.yml actions
  • actions/checkout v4 composite
  • actions/download-artifact v4 composite
  • actions/setup-python v5 composite
  • actions/upload-artifact v4 composite
  • pypa/gh-action-pypi-publish release/v1 composite