Core API Reference

TargetWaveformSimulator

class qiskit_waveform_sim.core.TargetWaveformSimulator(target: Target, if_freq_hz: float = 0.0, defaults: PulseDefaults | None = None, hardware_profile: HardwareProfile | None = None)[source]

Bases: object

Control-waveform synthesizer for Qiskit 2.x scheduled circuits.

The get_snippet() API is inspired by LabOne Q’s OutputSimulator. It synthesizes control waveforms and does not simulate qubit dynamics.

Tracks Virtual-Z phase accumulation per qubit and synthesizes I/Q waveforms lazily on-demand via windowed snippet extraction.

Memory complexity: O(N_events) for compilation, O(W) for snippet extraction, where W is the requested window length in dt.

Example

>>> backend = GenericBackendV2(num_qubits=2)
>>> qc = QuantumCircuit(2)
>>> qc.h(0); qc.cx(0, 1); qc.measure_all()
>>> pm = generate_preset_pass_manager(backend=backend, scheduling_method="alap")
>>> scheduled_qc = pm.run(qc)
>>> sim = TargetWaveformSimulator(backend.target).compile(scheduled_qc)
>>> snippet = sim.get_snippet("d0", start_dt=0, length_dt=1000)
>>> print(snippet.wave.shape)  # (1000,) complex array
__init__(target: Target, if_freq_hz: float = 0.0, defaults: PulseDefaults | None = None, hardware_profile: HardwareProfile | None = None)[source]

Initialize simulator with backend target.

Parameters:
  • target (Target) – Qiskit 2.x Target containing instruction durations and properties

  • if_freq_hz (float, optional) – Intermediate frequency for digital upconversion (Hz). 0.0 = baseband, non-zero = NCO modulation prior to DAC.

  • defaults (PulseDefaults, optional) – Placeholder amplitudes and shapes for gates without a pulse annotation. Defaults to PulseDefaults().

  • hardware_profile (HardwareProfile, optional) – Control-hardware impairments (channel skew, IQ imbalance, DC offset, DAC resolution, bandwidth) applied to the samples get_snippet() returns. None keeps the ideal waveforms. These are waveform impairments, not a fidelity prediction.

Raises:

ValueError – If the profile is incompatible with the target’s sample period (a bandwidth at or above the Nyquist frequency).

channel_delay_dt(channel: str) → int[source]

Whole samples the channel’s output extends past the ideal one (delay rounded up).

channel_delay_ns(channel: str) → float[source]

Latency of channel in ns under the hardware profile (0.0 without one).

compile(scheduled_qc: QuantumCircuit, start_times: Sequence[int] | None = None) → TargetWaveformSimulator[source]

Compile a scheduled circuit into channel events with frame tracking.

Parameters:
  • scheduled_qc (QuantumCircuit) – Circuit with op_start_times populated (via scheduling pass), or any circuit when start_times is given.

  • start_times (Sequence[int], optional) – Start time in dt of every top-level instruction, in scheduled_qc.data order. Used instead of scheduled_qc.op_start_times. Required for circuits containing BoxOp, which Qiskit’s scheduler rejects. Must have one non-negative integer per instruction.

Returns:

Self, for method chaining

Return type:

TargetWaveformSimulator

Raises:

ValueError – If the circuit is unscheduled and start_times is not given, or if start_times has the wrong length or invalid entries.

Examples

Hand-schedule a boxed circuit whose box starts at t = 0:

qc = QuantumCircuit(1)
with qc.box(duration=160, unit="dt"):
    qc.sx(0)
sim = TargetWaveformSimulator(target).compile(qc, start_times=[0])
export_openqasm3(scheduled_qc: QuantumCircuit, annotation_handlers: dict | None = None) → str[source]

Export scheduled circuit to OpenQASM 3 with serialized pulse annotations.

Parameters:
  • scheduled_qc (QuantumCircuit) – Scheduled circuit to export

  • annotation_handlers (dict, optional) – Custom annotation serializers. Defaults to including PulseAnnotationSerializer for the “pulse_sim.envelope” namespace. e.g., {“pulse_sim.envelope”: PulseAnnotationSerializer()}

Returns:

OpenQASM 3 string with pulse annotation pragmas

Return type:

str

get_channels() → list[str][source]

Return list of all channels with events.

get_phase_history(qubit: int) → list[tuple[int, float]][source]

Return phase history for a qubit as list of (dt, phase_rad).

get_snippet(channel: str, start_dt: int = 0, length_dt: int | None = None, ideal: bool = False) → WaveformSnippet[source]

Synthesize the complex I(t) + 1j*Q(t) waveform strictly within [start_dt, start_dt + length_dt].

Memory complexity is O(length_dt), independent of total circuit depth. Uses binary search to find only overlapping events.

With a hardware_profile, the channel’s impairments are applied in a fixed order: timing (delay, evaluated analytically, so fractional delays are exact), digital gain, DAC quantization and clipping, bandwidth low-pass, IQ imbalance, DC offset. A fractional delay makes a pulse span duration + 1 samples; the envelope is zero outside [0, duration). The default window grows by the channel’s delay.

Parameters:
  • channel (str) – Channel identifier (e.g., “d0”, “u(0,1)”, “m0”)

  • start_dt (int) – Start time in dt units

  • length_dt (int, optional) – Window length in dt. Defaults to remaining circuit duration (plus the channel’s delay when a hardware profile is active).

  • ideal (bool, optional) – Skip all impairments and return the ideal waveform, bit-identical to a simulator without a profile. Use this for hardware export.

Returns:

Container with time array, complex waveform, phase trace, and overlapping events. events holds the ideal-time ChannelEvent records; with a delay they appear on the output axis channel_delay_dt(channel) samples later.

Return type:

WaveformSnippet

WaveformSnippet

class qiskit_waveform_sim.core.WaveformSnippet(channel: str, start_dt: int, dt_sec: float, time_ns: ndarray, wave: ndarray, phase_rad: ndarray, events: list[ChannelEvent] = <factory>)[source]

Bases: object

LabOne Q OutputSimulator-style snippet container.

Contains the synthesized complex waveform for a specific time window on a specific channel, along with metadata for visualization.

channel: str
dt_sec: float
events: list[ChannelEvent]
phase_rad: ndarray
start_dt: int
time_ns: ndarray
wave: ndarray

ChannelEvent

class qiskit_waveform_sim.core.ChannelEvent(channel: str, start_dt: int, duration_dt: int, op_name: str, qubits: tuple[int, ...], frame_phase_rad: float, shape: str, amp: complex, beta: float = 0.0, sigma_dt: float = 16.0, risefall_dt: int = 16)[source]

Bases: object

Lightweight event record representing a scheduled hardware pulse or phase shift.

Memory footprint ~64 bytes per gate, enabling compilation of large circuits without sample array allocation.

amp: complex
beta: float = 0.0
channel: str
duration_dt: int
frame_phase_rad: float
op_name: str
qubits: tuple[int, ...]
risefall_dt: int = 16
shape: str
sigma_dt: float = 16.0
start_dt: int

AnalyticalEnvelopes

class qiskit_waveform_sim.core.AnalyticalEnvelopes[source]

Bases: object

Vectorized NumPy evaluators for physical microwave pulse envelopes.

All methods are static and operate on time arrays in dt units, returning complex baseband envelopes.

static drag(t_dt: ndarray, duration_dt: int, amp: complex, sigma_dt: float, beta: float) → ndarray[source]

DRAG (Derivative Removal by Adiabatic Gate) envelope with pedestal correction.

The I quadrature is a pedestal-corrected Gaussian that is exactly zero at the pulse edges. The Q quadrature is beta times its time derivative, matching Qiskit’s Drag definition; it is small but not exactly zero at the edges.

Parameters:
  • t_dt (np.ndarray) – Time points in dt units, relative to pulse start

  • duration_dt (int) – Total pulse duration in dt

  • amp (complex) – Complex amplitude as a fraction of DAC full scale (phase = drive phase)

  • sigma_dt (float) – Gaussian standard deviation in dt units

  • beta (float) – DRAG leakage suppression parameter (typically 0.05-0.15)

Returns:

Complex baseband envelope Ω(t) = A[g_norm(t) + iβ d(g_norm)/dt]. The Q quadrature is +β times the derivative of the I quadrature envelope.

Return type:

np.ndarray

static gaussian_square(t_dt: ndarray, duration_dt: int, amp: complex, risefall_dt: int) → ndarray[source]

GaussianSquare (flat-top with Gaussian rise/fall) envelope with pedestal correction.

Parameters:
  • t_dt (np.ndarray) – Time points in dt units, relative to pulse start

  • duration_dt (int) – Total pulse duration in dt

  • amp (complex) – Complex amplitude

  • risefall_dt (int) – Rise/fall duration in dt (each edge)

Returns:

Real-valued envelope (0 to 1) scaled by amplitude

Return type:

np.ndarray

PulseDefaults

class qiskit_waveform_sim.core.PulseDefaults(sx_amp: float = 0.45, x_amp: float = 0.9, cr_amp: float = 0.65, measure_amp: float = 0.35, drag_beta: float = 0.08, drag_sigma_ratio: float = 0.25, risefall_dt: int = 16, measure_risefall_dt: int = 24, echo_x_max_dt: int = 160)[source]

Bases: object

Placeholder pulse parameters used when a gate carries no pulse annotation.

Amplitudes are dimensionless fractions of DAC full scale in [-1, 1]. The defaults are uncalibrated placeholders, not Rabi rates; set them from your own calibration. rx(theta) uses x_amp * theta / pi and rzz(theta) scales cr_amp by theta / (pi / 2).

Parameters:
  • sx_amp (float) – Drive amplitude of sx (fraction of full scale).

  • x_amp (float) – Drive amplitude of x and of the ECR echo pulse.

  • cr_amp (float) – Cross-resonance / two-qubit pair-channel amplitude.

  • measure_amp (float) – Readout pulse amplitude.

  • drag_beta (float) – DRAG coefficient for single-qubit drive pulses.

  • drag_sigma_ratio (float) – Gaussian sigma as a fraction of pulse duration (must be > 0).

  • risefall_dt (int) – Rise/fall length in dt for flat-top (gaussian_square) pulses.

  • measure_risefall_dt (int) – Rise/fall length in dt for readout pulses.

  • echo_x_max_dt (int) – Maximum duration in dt of the ECR echo X pulse.

cr_amp: float = 0.65
drag_beta: float = 0.08
drag_sigma_ratio: float = 0.25
echo_x_max_dt: int = 160
measure_amp: float = 0.35
measure_risefall_dt: int = 24
risefall_dt: int = 16
sx_amp: float = 0.45
x_amp: float = 0.9