OpenPulse Python AST Reference

1.0.1 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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

view raw JSON →