pyqasm
Python toolkit providing OpenQASM 3 semantic analyzer and utilities for program analysis and compilation.
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
Repository
Python toolkit providing OpenQASM 3 semantic analyzer and utilities for program analysis and compilation.
Basic Info
- Host: GitHub
- Owner: qBraid
- License: apache-2.0
- Language: Python
- Default Branch: main
- Homepage: https://docs.qbraid.com/pyqasm
- Size: 1020 KB
Statistics
- Stars: 18
- Watchers: 3
- Forks: 18
- Open Issues: 28
- Releases: 13
Topics
Metadata Files
README.md
pyqasm
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:
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
- API Reference: Developer documentation.
- Usage Examples: Scripts and Markdown examples demonstrating core functionality.
- Supported Operations: OpenQASM language features supported, in progress, and planned for future support.
Contributing
- Interested in contributing code, or making a PR? See CONTRIBUTING.md
- For feature requests and bug reports: Submit an issue
- For discussions, and specific questions about pyqasm, or other topics, join our discord community
- For questions that are more suited for a forum, post to
QCSE
with the
pyqasmtag. - By participating, you are expected to uphold our code of conduct.
License
Owner
- Name: qBraid
- Login: qBraid
- Kind: organization
- Email: contact@qbraid.com
- Location: United States of America
- Website: https://qbraid.com/
- Twitter: qbraid_official
- Repositories: 9
- Profile: https://github.com/qBraid
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
Pull Request Labels
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.
- Documentation: https://pyqasm.readthedocs.io/
- License: Apache 2.0
-
Latest release: 0.5.0
published 6 months ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v4 composite
- actions/setup-python v5 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- 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
- actions/checkout v4 composite
- actions/setup-python v5 composite
- pypa/gh-action-pypi-publish release/v1 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- pypa/gh-action-pypi-publish release/v1 composite
- numpy *
- openqasm3 [parser]>=1.0.0,<2.0.0
- actions/checkout v4 composite
- actions/setup-python v5 composite
- 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
- 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