3.6.4. qupulse.program.waveforms

This module contains all waveform classes

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

Functions

_to_time_type(duration)

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.

Exceptions

ConstantFunctionPulseTemplateWarning

This warning indicates a constant waveform is constructed from a FunctionPulseTemplate

class qupulse.program.waveforms.ArithmeticWaveform(lhs: qupulse.program.waveforms.Waveform, arithmetic_operator: str, rhs: qupulse.program.waveforms.Waveform)[source]

Bases: qupulse.program.waveforms.Waveform

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

property arithmetic_operator: str
property compare_key: Tuple[str, qupulse.program.waveforms.Waveform, qupulse.program.waveforms.Waveform]

Implements compare_key.

constant_value(channel: Union[str, int]) Optional[float][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() Optional[Mapping[Union[str, int], float]][source]
property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

property duration: qupulse.utils.types.TimeType

The duration of the waveform in time units.

classmethod from_operator(lhs: qupulse.program.waveforms.Waveform, arithmetic_operator: str, rhs: qupulse.program.waveforms.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: qupulse.program.waveforms.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: qupulse.program.waveforms.Waveform
rhs_only_map = {'+': <built-in function pos>, '-': <built-in function neg>}
unsafe_get_subset_for_channels(channels: Set[Union[str, int]]) qupulse.program.waveforms.Waveform[source]

Implements unsafe_get_subset_for_channels().

unsafe_sample(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Implements unsafe_sample().

exception qupulse.program.waveforms.ConstantFunctionPulseTemplateWarning[source]

Bases: UserWarning

This warning indicates a constant waveform is constructed from a FunctionPulseTemplate

class qupulse.program.waveforms.ConstantWaveform(duration: numbers.Real, amplitude: Any, channel: Union[str, int])[source]

Bases: qupulse.program.waveforms.Waveform

Create a qupulse waveform corresponding to a ConstantPulseTemplate

__init__(duration: numbers.Real, amplitude: Any, channel: Union[str, int])[source]

Create a qupulse waveform corresponding to a ConstantPulseTemplate

property compare_key: Tuple[Any, ...]

Implements compare_key.

constant_value(channel: Union[str, int]) Optional[float][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() Optional[Mapping[Union[str, int], float]][source]
property defined_channels: AbstractSet[Union[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: numbers.Real, constant_values: Mapping[Union[str, int], float]) Union[qupulse.program.waveforms.ConstantWaveform, qupulse.program.waveforms.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() qupulse.program.waveforms.Waveform[source]

Returns a reversed version of this waveform.

unsafe_get_subset_for_channels(channels: Set[Union[str, int]]) qupulse.program.waveforms.Waveform[source]

Unsafe version of get_measurement_windows().

unsafe_sample(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Implements unsafe_sample().

class qupulse.program.waveforms.FunctionWaveform(expression: qupulse.expressions.sympy.ExpressionScalar, duration: float, channel: Union[str, int])[source]

Bases: qupulse.program.waveforms.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

__init__(expression: qupulse.expressions.sympy.ExpressionScalar, duration: float, channel: Union[str, int]) None[source]

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

Implements compare_key.

constant_value_dict() Optional[Mapping[Union[str, int], float]][source]
property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

property duration: qupulse.utils.types.TimeType

The duration of the waveform in time units.

classmethod from_expression(expression: qupulse.expressions.sympy.ExpressionScalar, duration: float, channel: Union[str, int]) Union[qupulse.program.waveforms.FunctionWaveform, qupulse.program.waveforms.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[Union[str, int]]) qupulse.program.waveforms.Waveform[source]

Implements unsafe_get_subset_for_channels().

unsafe_sample(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Implements unsafe_sample().

class qupulse.program.waveforms.MultiChannelWaveform(sub_waveforms: List[qupulse.program.waveforms.Waveform])[source]

Bases: qupulse.program.waveforms.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

__init__(sub_waveforms: List[qupulse.program.waveforms.Waveform]) None[source]

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

Implements compare_key.

constant_value(channel: Union[str, int]) Optional[float][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() Optional[Mapping[Union[str, int], float]][source]
property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

property duration: qupulse.utils.types.TimeType

The duration of the waveform in time units.

static from_parallel(waveforms: Sequence[qupulse.program.waveforms.Waveform]) qupulse.program.waveforms.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[Union[str, int]]) qupulse.program.waveforms.Waveform[source]

Implements unsafe_get_subset_for_channels().

unsafe_sample(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Implements unsafe_sample().

class qupulse.program.waveforms.RepetitionWaveform(body: qupulse.program.waveforms.Waveform, repetition_count: int)[source]

Bases: qupulse.program.waveforms.Waveform

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

property compare_key: Tuple[Any, int]

Implements compare_key.

constant_value(channel: Union[str, int]) Optional[float][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() Optional[Mapping[Union[str, int], float]][source]
property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

classmethod from_repetition_count(body: qupulse.program.waveforms.Waveform, repetition_count: int) qupulse.program.waveforms.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[Union[str, int]]) qupulse.program.waveforms.Waveform[source]

Implements unsafe_get_subset_for_channels().

unsafe_sample(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Implements unsafe_sample().

class qupulse.program.waveforms.SequenceWaveform(sub_waveforms: Iterable[qupulse.program.waveforms.Waveform])[source]

Bases: qupulse.program.waveforms.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

__init__(sub_waveforms: Iterable[qupulse.program.waveforms.Waveform])[source]

Use Waveform.from_sequence for optimal construction

Parameters

subwaveforms – All waveforms must have the same defined channels

property compare_key: Tuple[qupulse.program.waveforms.Waveform]

Implements compare_key.

constant_value(channel: Union[str, int]) Optional[float][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() Optional[Mapping[Union[str, int], float]][source]
property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

property duration: qupulse.utils.types.TimeType

The duration of the waveform in time units.

classmethod from_sequence(waveforms: Sequence[qupulse.program.waveforms.Waveform]) qupulse.program.waveforms.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[qupulse.program.waveforms.Waveform]
unsafe_get_subset_for_channels(channels: AbstractSet[Union[str, int]]) qupulse.program.waveforms.Waveform[source]

Implements unsafe_get_subset_for_channels().

unsafe_sample(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Implements unsafe_sample().

class qupulse.program.waveforms.TableWaveform(channel: Union[str, int], waveform_table: Tuple[qupulse.program.waveforms.TableWaveformEntry, ...])[source]

Bases: qupulse.program.waveforms.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 Union[qupulse.program.waveforms.TableWaveformEntry, Tuple[float, float, qupulse.pulses.interpolation.InterpolationStrategy]]

__init__(channel: Union[str, int], waveform_table: Tuple[qupulse.program.waveforms.TableWaveformEntry, ...]) None[source]

Create a new TableWaveform instance.

Parameters

waveform_table – A tuple of instantiated and validated table entries

property compare_key: Any

Implements compare_key.

constant_value_dict() Optional[Mapping[Union[str, int], float]][source]
property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

classmethod from_table(channel: Union[str, int], table: Sequence[Union[qupulse.program.waveforms.TableWaveformEntry, Tuple[float, float, qupulse.pulses.interpolation.InterpolationStrategy]]]) Union[qupulse.program.waveforms.TableWaveform, qupulse.program.waveforms.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[Union[str, int]]) qupulse.program.waveforms.Waveform[source]

Implements unsafe_get_subset_for_channels().

unsafe_sample(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Implements unsafe_sample().

class qupulse.program.waveforms.TableWaveformEntry(t: numbers.Real, v: float, interp: qupulse.pulses.interpolation.InterpolationStrategy)[source]

Bases: qupulse.program.waveforms.TableWaveformEntry

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

class qupulse.program.waveforms.TransformingWaveform(inner_waveform: qupulse.program.waveforms.Waveform, transformation: qupulse.program.transformation.Transformation)[source]

Bases: qupulse.program.waveforms.Waveform

property compare_key: Tuple[qupulse.program.waveforms.Waveform, qupulse.program.transformation.Transformation]

Implements compare_key.

constant_value(channel: Union[str, int]) Optional[float][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() Optional[Mapping[Union[str, int], float]][source]
property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

classmethod from_transformation(inner_waveform: qupulse.program.waveforms.Waveform, transformation: qupulse.program.transformation.Transformation) qupulse.program.waveforms.Waveform[source]
property inner_waveform: qupulse.program.waveforms.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: qupulse.program.transformation.Transformation
unsafe_get_subset_for_channels(channels: Set[Union[str, int]]) qupulse.program.waveforms.SubsetWaveform[source]

Implements unsafe_get_subset_for_channels().

unsafe_sample(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Implements unsafe_sample().

class qupulse.program.waveforms.Waveform(duration: qupulse.utils.types.TimeType)[source]

Bases: qupulse.comparable.Comparable

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

constant_value(channel: Union[str, int]) Optional[float][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() Optional[Mapping[Union[str, int], float]][source]
abstract property defined_channels: AbstractSet[Union[str, int]]

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

property duration: qupulse.utils.types.TimeType

The duration of the waveform in time units.

get_sampled(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.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[Union[str, int]]) qupulse.program.waveforms.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.

reversed() qupulse.program.waveforms.Waveform[source]

Returns a reversed version of this waveform.

abstract unsafe_get_subset_for_channels(channels: AbstractSet[Union[str, int]]) qupulse.program.waveforms.Waveform[source]

Unsafe version of get_measurement_windows().

abstract unsafe_sample(channel: Union[str, int], sample_times: numpy.ndarray, output_array: Optional[numpy.ndarray] = None) numpy.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.