3.5.7. qupulse.program.waveforms

This module contains all waveform classes

Classes:
  • Waveform: An instantiated pulse which can be sampled to a raw voltage value array.

Classes

ArithmeticWaveform(lhs, arithmetic_operator, rhs)

Channels only present in one waveform have the operations neutral element on the other.

ConstantWaveform(duration, amplitude, channel)

Create a qupulse waveform corresponding to a ConstantPulseTemplate

FunctionWaveform(expression, duration, channel)

Waveform obtained from instantiating a FunctionPulseTemplate.

FunctorWaveform(inner_waveform, functor)

MultiChannelWaveform(sub_waveforms)

A MultiChannelWaveform is a Waveform object that allows combining arbitrary Waveform objects to into a single waveform defined for several channels.

RepetitionWaveform(body, repetition_count)

This class allows putting multiple PulseTemplate together in one waveform on the hardware.

ReversedWaveform(inner)

Reverses the inner waveform in time.

SequenceWaveform(sub_waveforms)

This class allows putting multiple PulseTemplate together in one waveform on the hardware.

SubsetWaveform(inner_waveform, channel_subset)

TableWaveform(channel, waveform_table)

Create a new TableWaveform instance.

TableWaveformEntry(t, v, interp)

Create new instance of TableWaveformEntry(t, v, interp)

TransformingWaveform(inner_waveform, ...)

Waveform(duration)

Represents an instantiated PulseTemplate which can be sampled to retrieve arrays of voltage values for the hardware.

WaveformMetadata(**kwargs)

Metadata for a waveform.

Exceptions

ConstantFunctionPulseTemplateWarning

This warning indicates a constant waveform is constructed from a FunctionPulseTemplate

class ArithmeticWaveform(lhs: Waveform, arithmetic_operator: str, rhs: Waveform)[source]

Bases: Waveform

Channels only present in one waveform have the operations neutral element on the other.

property arithmetic_operator: str
property compare_key: Tuple[str, Waveform, Waveform]
constant_value(channel: str | int) float | None[source]

Checks if the requested channel has a constant value and returns it if so.

Guarantee that this assertion passes for every t in waveform duration: >>> assert waveform.constant_value(channel) is None or waveform.constant_value(t) = waveform.get_sampled(channel, t)

Parameters:

channel – The channel to check

Returns:

None if there is no guarantee that the channel is constant. The value otherwise.

constant_value_dict() Mapping[str | int, float] | None[source]
property defined_channels: AbstractSet[str | int]

The channels this waveform should played on. Use get_measurement_windows() to get a waveform for a subset of these.

property duration: TimeType

The duration of the waveform in time units.

classmethod from_operator(lhs: Waveform, arithmetic_operator: str, rhs: Waveform)[source]
is_constant() bool[source]

Convenience function to check if all channels are constant. The result is equal to all(waveform.constant_value(ch) is not None for ch in waveform.defined_channels) but might be more performant.

Returns:

True if all channels have constant values.

property lhs: Waveform
numpy_operator_map = {'+': <ufunc 'add'>, '-': <ufunc 'subtract'>}
numpy_rhs_only_map = {'+': <ufunc 'positive'>, '-': <ufunc 'negative'>}
operator_map = {'+': <built-in function add>, '-': <built-in function sub>}
property rhs: Waveform
rhs_only_map = {'+': <built-in function pos>, '-': <built-in function neg>}
unsafe_get_subset_for_channels(channels: Set[str | int]) Waveform[source]

Unsafe version of get_measurement_windows().

unsafe_sample(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

Sample the waveform at given sample times.

The unsafe means that there are no sanity checks performed. The provided sample times are assumed to be monotonously increasing and lie in the range of [0, waveform.duration]

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If not None, the sampled values will be written here and this array will be returned

Result:

The sampled values of this Waveform at the provided sample times. Has the same number of elements as sample_times.

exception ConstantFunctionPulseTemplateWarning[source]

Bases: UserWarning

This warning indicates a constant waveform is constructed from a FunctionPulseTemplate

class ConstantWaveform(duration: Real, amplitude: Any, channel: str | int)[source]

Bases: Waveform

Create a qupulse waveform corresponding to a ConstantPulseTemplate

property compare_key: Tuple[Any, ...]
constant_value(channel: str | int) float | None[source]

Checks if the requested channel has a constant value and returns it if so.

Guarantee that this assertion passes for every t in waveform duration: >>> assert waveform.constant_value(channel) is None or waveform.constant_value(t) = waveform.get_sampled(channel, t)

Parameters:

channel – The channel to check

Returns:

None if there is no guarantee that the channel is constant. The value otherwise.

constant_value_dict() Mapping[str | int, float] | None[source]
property defined_channels: AbstractSet[str | int]

The channels this waveform should played on. Use get_measurement_windows() to get a waveform for a subset of these.

classmethod from_mapping(duration: Real, constant_values: Mapping[str | int, float]) ConstantWaveform | MultiChannelWaveform[source]

Construct a ConstantWaveform or a MultiChannelWaveform of ConstantWaveforms with given duration and values

is_constant() bool[source]

Convenience function to check if all channels are constant. The result is equal to all(waveform.constant_value(ch) is not None for ch in waveform.defined_channels) but might be more performant.

Returns:

True if all channels have constant values.

reversed() Waveform[source]

Returns a reversed version of this waveform.

unsafe_get_subset_for_channels(channels: Set[str | int]) Waveform[source]

Unsafe version of get_measurement_windows().

unsafe_sample(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

Sample the waveform at given sample times.

The unsafe means that there are no sanity checks performed. The provided sample times are assumed to be monotonously increasing and lie in the range of [0, waveform.duration]

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If not None, the sampled values will be written here and this array will be returned

Result:

The sampled values of this Waveform at the provided sample times. Has the same number of elements as sample_times.

class FunctionWaveform(expression: ExpressionScalar, duration: float, channel: str | int)[source]

Bases: Waveform

Waveform obtained from instantiating a FunctionPulseTemplate.

Creates a new FunctionWaveform instance.

Parameters:
  • expression – The function represented by this FunctionWaveform as a mathematical expression where ‘t’ denotes the time variable. It must not have other variables

  • duration – The duration of the waveform

  • measurement_windows – A list of measurement windows

  • channel – The channel this waveform is played on

property compare_key: Any
constant_value_dict() Mapping[str | int, float] | None[source]
property defined_channels: AbstractSet[str | int]

The channels this waveform should played on. Use get_measurement_windows() to get a waveform for a subset of these.

property duration: TimeType

The duration of the waveform in time units.

classmethod from_expression(expression: ExpressionScalar, duration: float, channel: str | int) FunctionWaveform | ConstantWaveform[source]
is_constant() bool[source]

Convenience function to check if all channels are constant. The result is equal to all(waveform.constant_value(ch) is not None for ch in waveform.defined_channels) but might be more performant.

Returns:

True if all channels have constant values.

unsafe_get_subset_for_channels(channels: AbstractSet[str | int]) Waveform[source]

Unsafe version of get_measurement_windows().

unsafe_sample(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

Sample the waveform at given sample times.

The unsafe means that there are no sanity checks performed. The provided sample times are assumed to be monotonously increasing and lie in the range of [0, waveform.duration]

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If not None, the sampled values will be written here and this array will be returned

Result:

The sampled values of this Waveform at the provided sample times. Has the same number of elements as sample_times.

class MultiChannelWaveform(sub_waveforms: List[Waveform])[source]

Bases: Waveform

A MultiChannelWaveform is a Waveform object that allows combining arbitrary Waveform objects to into a single waveform defined for several channels.

The number of channels used by the MultiChannelWaveform object is the sum of the channels used by the Waveform objects it consists of.

MultiChannelWaveform allows an arbitrary mapping of channels defined by the Waveforms it consists of and the channels it defines. For example, if the MultiChannelWaveform consists of a two Waveform objects A and B which define two channels each, then the channels of the MultiChannelWaveform may be 0: A.1, 1: B.0, 2: B.1, 3: A.0 where A.0 means channel 0 of Waveform object A.

The following constraints must hold:
  • The durations of all Waveform objects must be equal.

  • The channel mapping must be sane, i.e., no channel of the MultiChannelWaveform must be

    assigned more than one channel of any Waveform object it consists of

Create a new MultiChannelWaveform instance. Use MultiChannelWaveform.from_parallel for optimal construction.

Requires a list of subwaveforms in the form (Waveform, List(int)) where the list defines the channel mapping, i.e., a value y at index x in the list means that channel x of the subwaveform will be mapped to channel y of this MultiChannelWaveform object.

Parameters:

sub_waveforms – The list of sub waveforms of this MultiChannelWaveform. List might get sorted!

Raises:
  • ValueError, if a channel mapping is out of bounds of the channels defined by this – MultiChannelWaveform

  • ValueError, if several subwaveform channels are assigned to a single channel of this – MultiChannelWaveform

  • ValueError, if subwaveforms have inconsistent durations

property compare_key: Any
constant_value(channel: str | int) float | None[source]

Checks if the requested channel has a constant value and returns it if so.

Guarantee that this assertion passes for every t in waveform duration: >>> assert waveform.constant_value(channel) is None or waveform.constant_value(t) = waveform.get_sampled(channel, t)

Parameters:

channel – The channel to check

Returns:

None if there is no guarantee that the channel is constant. The value otherwise.

constant_value_dict() Mapping[str | int, float] | None[source]
property defined_channels: AbstractSet[str | int]

The channels this waveform should played on. Use get_measurement_windows() to get a waveform for a subset of these.

property duration: TimeType

The duration of the waveform in time units.

static from_parallel(waveforms: Sequence[Waveform]) Waveform[source]
is_constant() bool[source]

Convenience function to check if all channels are constant. The result is equal to all(waveform.constant_value(ch) is not None for ch in waveform.defined_channels) but might be more performant.

Returns:

True if all channels have constant values.

unsafe_get_subset_for_channels(channels: AbstractSet[str | int]) Waveform[source]

Unsafe version of get_measurement_windows().

unsafe_sample(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

Sample the waveform at given sample times.

The unsafe means that there are no sanity checks performed. The provided sample times are assumed to be monotonously increasing and lie in the range of [0, waveform.duration]

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If not None, the sampled values will be written here and this array will be returned

Result:

The sampled values of this Waveform at the provided sample times. Has the same number of elements as sample_times.

class RepetitionWaveform(body: Waveform, repetition_count: int)[source]

Bases: Waveform

This class allows putting multiple PulseTemplate together in one waveform on the hardware.

property compare_key: Tuple[Any, int]
constant_value(channel: str | int) float | None[source]

Checks if the requested channel has a constant value and returns it if so.

Guarantee that this assertion passes for every t in waveform duration: >>> assert waveform.constant_value(channel) is None or waveform.constant_value(t) = waveform.get_sampled(channel, t)

Parameters:

channel – The channel to check

Returns:

None if there is no guarantee that the channel is constant. The value otherwise.

constant_value_dict() Mapping[str | int, float] | None[source]
property defined_channels: AbstractSet[str | int]

The channels this waveform should played on. Use get_measurement_windows() to get a waveform for a subset of these.

classmethod from_repetition_count(body: Waveform, repetition_count: int) Waveform[source]
is_constant() bool[source]

Convenience function to check if all channels are constant. The result is equal to all(waveform.constant_value(ch) is not None for ch in waveform.defined_channels) but might be more performant.

Returns:

True if all channels have constant values.

unsafe_get_subset_for_channels(channels: AbstractSet[str | int]) Waveform[source]

Unsafe version of get_measurement_windows().

unsafe_sample(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

Sample the waveform at given sample times.

The unsafe means that there are no sanity checks performed. The provided sample times are assumed to be monotonously increasing and lie in the range of [0, waveform.duration]

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If not None, the sampled values will be written here and this array will be returned

Result:

The sampled values of this Waveform at the provided sample times. Has the same number of elements as sample_times.

class SequenceWaveform(sub_waveforms: Iterable[Waveform])[source]

Bases: Waveform

This class allows putting multiple PulseTemplate together in one waveform on the hardware.

Use Waveform.from_sequence for optimal construction

Parameters:

subwaveforms – All waveforms must have the same defined channels

property compare_key: Tuple[Waveform]
constant_value(channel: str | int) float | None[source]

Checks if the requested channel has a constant value and returns it if so.

Guarantee that this assertion passes for every t in waveform duration: >>> assert waveform.constant_value(channel) is None or waveform.constant_value(t) = waveform.get_sampled(channel, t)

Parameters:

channel – The channel to check

Returns:

None if there is no guarantee that the channel is constant. The value otherwise.

constant_value_dict() Mapping[str | int, float] | None[source]
property defined_channels: AbstractSet[str | int]

The channels this waveform should played on. Use get_measurement_windows() to get a waveform for a subset of these.

property duration: TimeType

The duration of the waveform in time units.

classmethod from_sequence(waveforms: Sequence[Waveform]) Waveform[source]

Returns a waveform the represents the given sequence of waveforms. Applies some optimizations.

is_constant() bool[source]

Convenience function to check if all channels are constant. The result is equal to all(waveform.constant_value(ch) is not None for ch in waveform.defined_channels) but might be more performant.

Returns:

True if all channels have constant values.

property sequenced_waveforms: Sequence[Waveform]
unsafe_get_subset_for_channels(channels: AbstractSet[str | int]) Waveform[source]

Unsafe version of get_measurement_windows().

unsafe_sample(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

Sample the waveform at given sample times.

The unsafe means that there are no sanity checks performed. The provided sample times are assumed to be monotonously increasing and lie in the range of [0, waveform.duration]

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If not None, the sampled values will be written here and this array will be returned

Result:

The sampled values of this Waveform at the provided sample times. Has the same number of elements as sample_times.

class TableWaveform(channel: str | int, waveform_table: Tuple[TableWaveformEntry, ...])[source]

Bases: Waveform

Create a new TableWaveform instance.

Parameters:

waveform_table – A tuple of instantiated and validated table entries

EntryInInit

Waveform obtained from instantiating a TablePulseTemplate.

alias of TableWaveformEntry | Tuple[float, float, InterpolationStrategy]

property compare_key: Any
constant_value_dict() Mapping[str | int, float] | None[source]
property defined_channels: AbstractSet[str | int]

The channels this waveform should played on. Use get_measurement_windows() to get a waveform for a subset of these.

classmethod from_table(channel: str | int, table: Sequence[TableWaveformEntry | Tuple[float, float, InterpolationStrategy]]) TableWaveform | ConstantWaveform[source]
is_constant() bool[source]

Convenience function to check if all channels are constant. The result is equal to all(waveform.constant_value(ch) is not None for ch in waveform.defined_channels) but might be more performant.

Returns:

True if all channels have constant values.

unsafe_get_subset_for_channels(channels: AbstractSet[str | int]) Waveform[source]

Unsafe version of get_measurement_windows().

unsafe_sample(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

Sample the waveform at given sample times.

The unsafe means that there are no sanity checks performed. The provided sample times are assumed to be monotonously increasing and lie in the range of [0, waveform.duration]

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If not None, the sampled values will be written here and this array will be returned

Result:

The sampled values of this Waveform at the provided sample times. Has the same number of elements as sample_times.

class TableWaveformEntry(t: Real, v: float, interp: InterpolationStrategy)[source]

Bases: TableWaveformEntry

Create new instance of TableWaveformEntry(t, v, interp)

class TransformingWaveform(inner_waveform: Waveform, transformation: Transformation)[source]

Bases: Waveform

property compare_key: Tuple[Waveform, Transformation]
constant_value(channel: str | int) float | None[source]

Checks if the requested channel has a constant value and returns it if so.

Guarantee that this assertion passes for every t in waveform duration: >>> assert waveform.constant_value(channel) is None or waveform.constant_value(t) = waveform.get_sampled(channel, t)

Parameters:

channel – The channel to check

Returns:

None if there is no guarantee that the channel is constant. The value otherwise.

constant_value_dict() Mapping[str | int, float] | None[source]
property defined_channels: AbstractSet[str | int]

The channels this waveform should played on. Use get_measurement_windows() to get a waveform for a subset of these.

classmethod from_transformation(inner_waveform: Waveform, transformation: Transformation) Waveform[source]
property inner_waveform: Waveform
is_constant() bool[source]

Convenience function to check if all channels are constant. The result is equal to all(waveform.constant_value(ch) is not None for ch in waveform.defined_channels) but might be more performant.

Returns:

True if all channels have constant values.

property transformation: Transformation
unsafe_get_subset_for_channels(channels: Set[str | int]) SubsetWaveform[source]

Unsafe version of get_measurement_windows().

unsafe_sample(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

Sample the waveform at given sample times.

The unsafe means that there are no sanity checks performed. The provided sample times are assumed to be monotonously increasing and lie in the range of [0, waveform.duration]

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If not None, the sampled values will be written here and this array will be returned

Result:

The sampled values of this Waveform at the provided sample times. Has the same number of elements as sample_times.

class Waveform(duration: TimeType)[source]

Bases: object

Represents an instantiated PulseTemplate which can be sampled to retrieve arrays of voltage values for the hardware.

constant_value(channel: str | int) float | None[source]

Checks if the requested channel has a constant value and returns it if so.

Guarantee that this assertion passes for every t in waveform duration: >>> assert waveform.constant_value(channel) is None or waveform.constant_value(t) = waveform.get_sampled(channel, t)

Parameters:

channel – The channel to check

Returns:

None if there is no guarantee that the channel is constant. The value otherwise.

constant_value_dict() Mapping[str | int, float] | None[source]
abstract property defined_channels: AbstractSet[str | int]

The channels this waveform should played on. Use get_measurement_windows() to get a waveform for a subset of these.

property duration: TimeType

The duration of the waveform in time units.

get_sampled(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

A wrapper to the unsafe_sample method which caches the result. This method enforces the constrains unsafe_sample expects and caches the result to save memory.

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If an array is given, the sampled values will be written into the given array and it will be returned. Otherwise, a new array will be created and cached to save memory.

Result:

The sampled values of this Waveform at the provided sample times. Is output_array if provided

get_subset_for_channels(channels: AbstractSet[str | int]) Waveform[source]

Get a waveform that only describes the channels contained in channels.

Parameters:

channels – A channel set the return value should confine to.

Raises:

KeyError – If channels is not a subset of the waveform’s defined channels.

Returns:

A waveform with waveform.defined_channels == channels

is_constant() bool[source]

Convenience function to check if all channels are constant. The result is equal to all(waveform.constant_value(ch) is not None for ch in waveform.defined_channels) but might be more performant.

Returns:

True if all channels have constant values.

property metadata
reversed() Waveform[source]

Returns a reversed version of this waveform.

abstractmethod unsafe_get_subset_for_channels(channels: AbstractSet[str | int]) Waveform[source]

Unsafe version of get_measurement_windows().

abstractmethod unsafe_sample(channel: str | int, sample_times: ndarray, output_array: ndarray | None = None) ndarray[source]

Sample the waveform at given sample times.

The unsafe means that there are no sanity checks performed. The provided sample times are assumed to be monotonously increasing and lie in the range of [0, waveform.duration]

Parameters:
  • sample_times – Times at which this Waveform will be sampled.

  • output_array – Has to be either None or an array of the same size and type as sample_times. If not None, the sampled values will be written here and this array will be returned

Result:

The sampled values of this Waveform at the provided sample times. Has the same number of elements as sample_times.