3.1.6. qupulse._program.waveforms

This module contains all waveform classes

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

class qupulse._program.waveforms.ArithmeticWaveform(lhs, arithmetic_operator, rhs)[source]

Bases: qupulse._program.waveforms.Waveform

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

property arithmetic_operator: str
Return type

str

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

Implements compare_key.

Return type

Tuple[str, Waveform, Waveform]

constant_value(channel)[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 (Union[str, int]) – The channel to check

Return type

Optional[float]

Returns

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

constant_value_dict()[source]
Return type

Optional[Mapping[Union[str, int], float]]

property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

Return type

AbstractSet[Union[str, int]]

property duration: qupulse.utils.types.TimeType

Implements duration.

Return type

TimeType

classmethod from_operator(lhs, arithmetic_operator, rhs)[source]
is_constant()[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.

Return type

bool

Returns

True if all channels have constant values.

property lhs: qupulse._program.waveforms.Waveform
Return type

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
Return type

Waveform

rhs_only_map = {'+': <built-in function pos>, '-': <built-in function neg>}
unsafe_get_subset_for_channels(channels)[source]

Implements unsafe_get_subset_for_channels().

Return type

Waveform

unsafe_sample(channel, sample_times, output_array=None)[source]

Implements unsafe_sample().

Return type

ndarray

class qupulse._program.waveforms.FunctionWaveform(expression, duration, channel)[source]

Bases: qupulse._program.waveforms.Waveform

Waveform obtained from instantiating a FunctionPulseTemplate.

Creates a new FunctionWaveform instance.

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

  • duration (float) – The duration of the waveform

  • measurement_windows – A list of measurement windows

  • channel (Union[str, int]) – The channel this waveform is played on

__init__(expression, duration, channel)[source]

Creates a new FunctionWaveform instance.

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

  • duration (float) – The duration of the waveform

  • measurement_windows – A list of measurement windows

  • channel (Union[str, int]) – The channel this waveform is played on

property compare_key: Any

Implements compare_key.

Return type

Any

constant_value_dict()[source]
Return type

Optional[Mapping[Union[str, int], float]]

property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

Return type

AbstractSet[Union[str, int]]

property duration: qupulse.utils.types.TimeType

Implements duration.

Return type

TimeType

classmethod from_expression(expression, duration, channel)[source]
Return type

Union[FunctionWaveform, ConstantWaveform]

is_constant()[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.

Return type

bool

Returns

True if all channels have constant values.

unsafe_get_subset_for_channels(channels)[source]

Implements unsafe_get_subset_for_channels().

Return type

Waveform

unsafe_sample(channel, sample_times, output_array=None)[source]

Implements unsafe_sample().

Return type

ndarray

class qupulse._program.waveforms.MultiChannelWaveform(sub_waveforms)[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 (List[Waveform]) – 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)[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 (List[Waveform]) – 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.

Return type

Any

constant_value(channel)[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 (Union[str, int]) – The channel to check

Return type

Optional[float]

Returns

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

constant_value_dict()[source]
Return type

Optional[Mapping[Union[str, int], float]]

property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

Return type

AbstractSet[Union[str, int]]

property duration: qupulse.utils.types.TimeType

Implements duration.

Return type

TimeType

static from_parallel(waveforms)[source]
Return type

Waveform

is_constant()[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.

Return type

bool

Returns

True if all channels have constant values.

unsafe_get_subset_for_channels(channels)[source]

Implements unsafe_get_subset_for_channels().

Return type

Waveform

unsafe_sample(channel, sample_times, output_array=None)[source]

Implements unsafe_sample().

Return type

ndarray

class qupulse._program.waveforms.RepetitionWaveform(body, repetition_count)[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.

Return type

Tuple[Any, int]

property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

Return type

AbstractSet[Union[str, int]]

property duration: qupulse.utils.types.TimeType

Implements duration.

Return type

TimeType

classmethod from_repetition_count(body, repetition_count)[source]
Return type

Waveform

unsafe_get_subset_for_channels(channels)[source]

Implements unsafe_get_subset_for_channels().

Return type

RepetitionWaveform

unsafe_sample(channel, sample_times, output_array=None)[source]

Implements unsafe_sample().

Return type

ndarray

class qupulse._program.waveforms.SequenceWaveform(sub_waveforms)[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)[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.

Return type

Tuple[Waveform]

constant_value(channel)[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 (Union[str, int]) – The channel to check

Return type

Optional[float]

Returns

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

constant_value_dict()[source]
Return type

Optional[Mapping[Union[str, int], float]]

property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

Return type

AbstractSet[Union[str, int]]

property duration: qupulse.utils.types.TimeType

Implements duration.

Return type

TimeType

classmethod from_sequence(waveforms)[source]

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

Return type

Waveform

is_constant()[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.

Return type

bool

Returns

True if all channels have constant values.

property sequenced_waveforms: Sequence[qupulse._program.waveforms.Waveform]
Return type

Sequence[Waveform]

unsafe_get_subset_for_channels(channels)[source]

Implements unsafe_get_subset_for_channels().

Return type

Waveform

unsafe_sample(channel, sample_times, output_array=None)[source]

Implements unsafe_sample().

Return type

ndarray

class qupulse._program.waveforms.TableWaveform(channel, waveform_table)[source]

Bases: qupulse._program.waveforms.Waveform

Create a new TableWaveform instance.

Parameters

waveform_table (Tuple[TableWaveformEntry, …]) – 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, waveform_table)[source]

Create a new TableWaveform instance.

Parameters

waveform_table (Tuple[TableWaveformEntry, …]) – A tuple of instantiated and validated table entries

property compare_key: Any

Implements compare_key.

Return type

Any

constant_value_dict()[source]
Return type

Optional[Mapping[Union[str, int], float]]

property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

Return type

AbstractSet[Union[str, int]]

property duration: qupulse.utils.types.TimeType

Implements duration.

Return type

TimeType

classmethod from_table(channel, table)[source]
Return type

Union[TableWaveform, ConstantWaveform]

is_constant()[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.

Return type

bool

Returns

True if all channels have constant values.

unsafe_get_subset_for_channels(channels)[source]

Implements unsafe_get_subset_for_channels().

Return type

Waveform

unsafe_sample(channel, sample_times, output_array=None)[source]

Implements unsafe_sample().

Return type

ndarray

class qupulse._program.waveforms.TableWaveformEntry(t, v, interp)[source]

Bases: qupulse._program.waveforms.TableWaveformEntry

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

class qupulse._program.waveforms.TransformingWaveform(inner_waveform, transformation)[source]

Bases: qupulse._program.waveforms.Waveform

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

Implements compare_key.

Return type

Tuple[Waveform, Transformation]

constant_value(channel)[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 (Union[str, int]) – The channel to check

Return type

Optional[float]

Returns

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

constant_value_dict()[source]
Return type

Optional[Mapping[Union[str, int], float]]

property defined_channels: AbstractSet[Union[str, int]]

Implements defined_channels.

Return type

AbstractSet[Union[str, int]]

property duration: qupulse.utils.types.TimeType

Implements duration.

Return type

TimeType

classmethod from_transformation(inner_waveform, transformation)[source]
Return type

Waveform

property inner_waveform: qupulse._program.waveforms.Waveform
Return type

Waveform

is_constant()[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.

Return type

bool

Returns

True if all channels have constant values.

property transformation: qupulse._program.transformation.Transformation
Return type

Transformation

unsafe_get_subset_for_channels(channels)[source]

Implements unsafe_get_subset_for_channels().

Return type

SubsetWaveform

unsafe_sample(channel, sample_times, output_array=None)[source]

Implements unsafe_sample().

Return type

ndarray

class qupulse._program.waveforms.Waveform[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)[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 (Union[str, int]) – The channel to check

Return type

Optional[float]

Returns

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

constant_value_dict()[source]
Return type

Optional[Mapping[Union[str, int], float]]

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.

Return type

AbstractSet[Union[str, int]]

abstract property duration: qupulse.utils.types.TimeType

The duration of the waveform in time units.

Return type

TimeType

get_sampled(channel, sample_times, output_array=None)[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 (ndarray) – Times at which this Waveform will be sampled.

  • output_array (Optional[ndarray]) – 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

Return type

ndarray

get_subset_for_channels(channels)[source]

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

Parameters

channels (AbstractSet[Union[str, int]]) – A channel set the return value should confine to.

Raises

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

Return type

Waveform

Returns

A waveform with waveform.defined_channels == channels

is_constant()[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.

Return type

bool

Returns

True if all channels have constant values.

abstract unsafe_get_subset_for_channels(channels)[source]

Unsafe version of get_measurement_windows().

Return type

Waveform

abstract unsafe_sample(channel, sample_times, output_array=None)[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 (ndarray) – Times at which this Waveform will be sampled.

  • output_array (Optional[ndarray]) – 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.

Return type

ndarray