Annotations API Reference

PulseEnvelopeAnnotation

class qiskit_waveform_sim.annotations.PulseEnvelopeAnnotation(shape: str = 'drag', amp: float = 0.5, beta: float = 0.08, sigma_ratio: float = 0.25, risefall_dt: int = 16)[source]

Bases: Annotation

Custom Qiskit 2.x Annotation attaching parametric pulse specs to a BoxOp.

This annotation can be attached to a qc.box() context to override the default pulse envelope for gates within that box. It implements OpenQASM3Serializer for round-trip serialization via qiskit.qasm3.dumps() and qiskit.qpy.dump().

Examples

>>> from qiskit import QuantumCircuit
>>> from qiskit_waveform_sim import PulseEnvelopeAnnotation
>>>
>>> qc = QuantumCircuit(1)
>>> with qc.box(duration=160, unit="dt",
...             annotations=[PulseEnvelopeAnnotation(shape="drag", amp=0.55, beta=0.25)]):
...     qc.sx(0)

QPY Round-trip Example >>> from qiskit import qpy >>> from qiskit_waveform_sim import PulseAnnotationSerializer >>> import io >>> >>> qc = QuantumCircuit(1) >>> with qc.box(duration=160, unit=”dt”, … annotations=[PulseEnvelopeAnnotation(shape=”drag”, amp=0.55, beta=0.25)]): … qc.sx(0) >>> >>> serializer = PulseAnnotationSerializer() >>> buf = io.BytesIO() >>> qpy.dump(qc, buf, annotation_factories={“pulse_sim.envelope”: serializer.as_qpy()}) >>> buf.seek(0) >>> loaded = qpy.load(buf, annotation_factories={“pulse_sim.envelope”: serializer.as_qpy()})[0]

__init__(shape: str = 'drag', amp: float = 0.5, beta: float = 0.08, sigma_ratio: float = 0.25, risefall_dt: int = 16)[source]

Initialize pulse envelope annotation.

Parameters:
  • shape (str) – Pulse shape: “drag” or “gaussian_square”

  • amp (float) – Peak amplitude as a fraction of DAC full-scale, -1.0 to 1.0 (negative values flip the drive phase by pi). For rx(θ) gates, amp is the π-rotation amplitude and is scaled by θ/π (the same convention as the unannotated default).

  • beta (float) – DRAG leakage suppression parameter (for drag shape)

  • sigma_ratio (float) – Gaussian sigma as ratio of pulse duration; must be > 0 for drag (ignored for gaussian_square)

  • risefall_dt (int) – Rise/fall duration in dt, >= 0 (for gaussian_square shape)

Raises:

ValueError – If the shape is unsupported or a parameter is out of range.

classmethod from_dict(data: dict[str, Any]) → PulseEnvelopeAnnotation[source]

Build an annotation from to_dict() output.

namespace = 'pulse_sim.envelope'
to_dict() → dict[str, Any][source]

Plain-dictionary form of the parameters (inverse of from_dict).

PulseAnnotationSerializer

class qiskit_waveform_sim.annotations.PulseAnnotationSerializer[source]

Bases: OpenQASM3Serializer

Serializes PulseEnvelopeAnnotation to/from OpenQASM 3 and QPY.

OpenQASM 3 Export Format:

@pulse_sim.envelope {'shape': 'drag', 'amp': 0.5, 'beta': 0.08, 'sigma_ratio': 0.25, 'risefall_dt': 16}
box[160dt] {
    sx $0;
}

QPY Serialization:

Uses the standard QPY annotation mechanism with namespace "pulse_sim.envelope"
via the `as_qpy()` method. Example:

>>> from qiskit import qpy
>>> from qiskit_waveform_sim import PulseAnnotationSerializer
>>> import io
>>>
>>> serializer = PulseAnnotationSerializer()
>>> buf = io.BytesIO()
>>> qpy.dump(qc, buf, annotation_factories={"pulse_sim.envelope": serializer.as_qpy()})
>>> buf.seek(0)
>>> loaded = qpy.load(buf, annotation_factories={"pulse_sim.envelope": serializer.as_qpy()})[0]
dump(annotation: Annotation) → str[source]

Serialize annotation to OpenQASM 3 pragma string.

Returns NotImplemented if namespace doesn’t match.

load(namespace: str, payload: str) → Annotation[source]

Deserialize annotation from OpenQASM 3 pragma string.

Returns NotImplemented if namespace doesn’t match.