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
|
Channels only present in one waveform have the operations neutral element on the other. |
|
Create a qupulse waveform corresponding to a ConstantPulseTemplate |
|
Waveform obtained from instantiating a FunctionPulseTemplate. |
|
|
|
A MultiChannelWaveform is a Waveform object that allows combining arbitrary Waveform objects to into a single waveform defined for several channels. |
|
This class allows putting multiple PulseTemplate together in one waveform on the hardware. |
|
Reverses the inner waveform in time. |
|
This class allows putting multiple PulseTemplate together in one waveform on the hardware. |
|
|
|
Create a new TableWaveform instance. |
|
Create new instance of TableWaveformEntry(t, v, interp) |
|
|
|
Represents an instantiated PulseTemplate which can be sampled to retrieve arrays of voltage values for the hardware. |
|
Metadata for a waveform. |
Exceptions
This warning indicates a constant waveform is constructed from a FunctionPulseTemplate |
- class ArithmeticWaveform(lhs: Waveform, arithmetic_operator: str, rhs: Waveform)[source]¶
Bases:
WaveformChannels only present in one waveform have the operations neutral element on the other.
- 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.
- 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.
- 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.
- 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>}¶
- 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:
UserWarningThis warning indicates a constant waveform is constructed from a FunctionPulseTemplate
- class ConstantWaveform(duration: Real, amplitude: Any, channel: str | int)[source]¶
Bases:
WaveformCreate a qupulse waveform corresponding to a ConstantPulseTemplate
- 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.
- 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.
- 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:
WaveformWaveform 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 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_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:
WaveformA 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 –
- 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.
- 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.
- 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:
WaveformThis class allows putting multiple PulseTemplate together in one waveform on 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.
- 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.
- 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:
WaveformThis 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
- 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.
- 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_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.
- 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:
WaveformCreate 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 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:
TableWaveformEntryCreate 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.
- 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]¶
- 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:
objectRepresents 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.
- 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.
- 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¶
- 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.