Registry / ai-ml / openpulse

openpulse

JSON →
library1.0.1pypypi✓ verified 85d ago

OpenPulse (version 1.0.1) is a Python library providing a reference Abstract Syntax Tree (AST) for the OpenPulse grammar. It enables the representation and manipulation of pulse-level definitions (`cal` and `defcal` blocks) within the OpenQASM 3 ecosystem, reusing classical types and statements from the `openqasm3` library. The library includes AST nodes and a parser, serving as a foundational component for tools that process pulse-level control in quantum computing.

pip install openpulse
INSTALL
IMPORT
SIG · OPENPULSE
O
openpulse
ai-mlpythonv1.0.1
Install
2.6s avg
Import
576ms
Disk
31MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.588s · 30.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.6s · import 0.564s · 31MB
31MB installed
● package 31MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parser
from openpulse import parser
The primary entry point for parsing OpenPulse strings into an AST.
ast
from openpulse import ast
Accesses the Abstract Syntax Tree node definitions for OpenPulse constructs. Many nodes are re-exported from `openqasm3.ast`.

This quickstart demonstrates how to use the `openpulse.parser` to parse a basic OpenPulse string into its Abstract Syntax Tree representation. The resulting `Program` object is an instance of the `openpulse.ast.Program` class, allowing programmatic inspection and manipulation of the pulse-level instructions.

from openpulse import parser from openpulse.ast import Program # Define a simple OpenPulse string pulse_string = """ OPENQASM 3.0; cal { waveform w = sine(1.0, 0.5, 0.0, 0.0); play(0, w); } """ # Parse the OpenPulse string into an AST ast_program = parser.parse(pulse_string) # Verify the type of the parsed program assert isinstance(ast_program, Program) print("Successfully parsed OpenPulse program.") # print(ast_program.pretty_print()) # Uncomment to see structured output if available
Debug
Known issues
breakingUpdates to the OpenPulse or OpenQASM 3 grammar specifications can lead to breaking changes in the `openpulse` AST structure and parser behavior. Code relying on specific AST node names or hierarchies may need adjustment.
fix
Always review the release notes of `openpulse` and `openqasm3` for grammar updates. Update your code to reflect changes in AST node names, attributes, or the expected parsing output.
affects: All versions, especially with new OpenQASM/OpenPulse specification releases.
gotchaThe `openpulse` library heavily depends on and reuses components from `openqasm3`. Errors related to classical types, statements, or overall program structure within OpenPulse definitions often stem from issues or misunderstandings of the underlying OpenQASM 3 grammar.
fix
Ensure `openqasm3` is correctly installed and compatible. Familiarize yourself with the OpenQASM 3 specification in addition to OpenPulse, particularly regarding classical control flow and type systems.
affects: All versions
Errors
Common errors & fixes
from openpulse import parse ModuleNotFoundError: No module named 'openpulse.parse'
The main parsing function is not directly exposed as `parse` at the top-level `openpulse` module. It resides in `openpulse.parser`.
fix
Use `from openpulse import parser` and then call `parser.parse(pulse_string)`.
openpulse.parser.exceptions.ParseError: MismatchedTokenException(...) openpulse.parser.exceptions.NoViableAltException(...)
The input OpenPulse string does not conform to the OpenPulse grammar. This could be due to syntax errors, incorrect keywords, or malformed pulse definitions.
fix
Carefully review the `pulse_string` for syntax errors against the OpenPulse specification. Ensure all required elements (like `OPENQASM 3.0;` or `cal { ... }`) are present and correctly formatted. Consult OpenPulse examples for valid syntax.
Upgrade
Version history
1.0.1latest on PyPI · released Oct 1, 2024
Audit
Dependencies
openqasm3requiredOpenPulse reuses classical types and statements from OpenQASM 3, making 'openqasm3' a core dependency for correct AST structure and parsing.
Agent activity
6 hits · last 30 days
node
6
Resources
openpulse — pip install openpulse · libregistry