3.7.13. qupulse.pulses.pulse_template¶
This module defines the abstract PulseTemplate class which is the basis of any pulse model in the qupulse.
- Classes:
PulseTemplate: Represents the parametrized general structure of a pulse.
- AtomicPulseTemplate: PulseTemplate that does imply any control flow disruptions and can be
directly translated into a waveform.
Classes
|
A PulseTemplate that does not imply any control flow disruptions and can be directly translated into a waveform. |
|
A PulseTemplate represents the parametrized general structure of a pulse. |
Exceptions
|
|
- class qupulse.pulses.pulse_template.AtomicPulseTemplate(*, identifier: Optional[str], measurements: Optional[List[Tuple[str, Union[qupulse.expressions.sympy.Expression, str, numbers.Real], Union[qupulse.expressions.sympy.Expression, str, numbers.Real]]]])[source]¶
Bases:
qupulse.pulses.pulse_template.PulseTemplate
,qupulse.pulses.measurement.MeasurementDefiner
A PulseTemplate that does not imply any control flow disruptions and can be directly translated into a waveform.
Implies that no AtomicPulseTemplate object is interruptable.
Initializes a Serializable.
- Parameters
identifier – An optional, non-empty identifier for this Serializable. If set, this Serializable will always be stored as a separate data item and never be embedded.
- Raises
ValueError – If identifier is the empty string
- abstract build_waveform(parameters: Mapping[str, numbers.Real], channel_mapping: Dict[Union[str, int], Optional[Union[str, int]]]) Optional[qupulse.program.waveforms.Waveform] [source]¶
Translate this PulseTemplate into a waveform according to the given parameters.
Subclasses of AtomicPulseTemplate must check for ParameterConstraintViolation errors in their build_waveform implementation and raise corresponding exceptions.
- Parameters
parameters (Dict(str -> Parameter)) – A mapping of parameter names to real numbers.
channel_mapping (Dict(ChannelID -> ChannelID) – A mapping of Channel IDs
- Returns
- Waveform object represented by this PulseTemplate object or None, if this object
does not represent a valid waveform of finite length.
- property final_values: Dict[Union[str, int], qupulse.expressions.sympy.ExpressionScalar]¶
Values of defined channels at t == self.duration
- property initial_values: Dict[Union[str, int], qupulse.expressions.sympy.ExpressionScalar]¶
Values of defined channels at t == 0
- property integral: Dict[Union[str, int], qupulse.expressions.sympy.ExpressionScalar]¶
Implements
integral
.
- property measurement_names: Set[str]¶
Return the names of measurements that are directly declared on self. Does _not_ visit eventual child objects.
- with_parallel_atomic(*parallel: qupulse.pulses.pulse_template.AtomicPulseTemplate) qupulse.pulses.pulse_template.AtomicPulseTemplate [source]¶
- exception qupulse.pulses.pulse_template.DoubleParameterNameException(templateA: qupulse.pulses.pulse_template.PulseTemplate, templateB: qupulse.pulses.pulse_template.PulseTemplate, names: Set[str])[source]¶
Bases:
Exception
- class qupulse.pulses.pulse_template.PulseTemplate(*, identifier: Optional[str])[source]¶
Bases:
qupulse.serialization.Serializable
A PulseTemplate represents the parametrized general structure of a pulse.
A PulseTemplate described a pulse in an abstract way: It defines the structure of a pulse but might leave some timings or voltage levels undefined, thus declaring parameters. This allows to reuse a PulseTemplate for several pulses which have the same overall structure and differ only in concrete values for the parameters. Obtaining an actual pulse which can be executed by specifying values for these parameters is called instantiation of the PulseTemplate and achieved by invoking the sequencing process.
Initializes a Serializable.
- Parameters
identifier – An optional, non-empty identifier for this Serializable. If set, this Serializable will always be stored as a separate data item and never be embedded.
- Raises
ValueError – If identifier is the empty string
- create_program(*, parameters: Optional[Mapping[str, Union[qupulse.expressions.sympy.Expression, str, numbers.Number]]] = None, measurement_mapping: Optional[Mapping[str, Optional[str]]] = None, channel_mapping: Optional[Mapping[Union[str, int], Optional[Union[str, int]]]] = None, global_transformation: Optional[qupulse.program.transformation.Transformation] = None, to_single_waveform: Optional[Set[Union[str, qupulse.pulses.pulse_template.PulseTemplate]]] = None, volatile: Optional[Union[Set[str], str]] = None) Optional[qupulse.program.loop.Loop] [source]¶
Translates this PulseTemplate into a program Loop.
The returned Loop represents the PulseTemplate with all parameter values instantiated provided as dictated by the parameters argument. Optionally, channels and measurements defined in the PulseTemplate can be renamed/mapped via the channel_mapping and measurement_mapping arguments.
- Parameters
parameters – A mapping of parameter names to Parameter objects.
measurement_mapping – A mapping of measurement window names. Windows that are mapped to None are omitted.
channel_mapping – A mapping of channel names. Channels that are mapped to None are omitted.
global_transformation – This transformation is applied to every waveform
to_single_waveform – A set of pulse templates (or identifiers) which are directly translated to a waveform. This might change how transformations are applied. TODO: clarify
volatile – Everything in the final program that depends on these parameters is marked as volatile
- Returns
A Loop object corresponding to this PulseTemplate.
- abstract property defined_channels: Set[Union[str, int]]¶
Returns the number of hardware output channels this PulseTemplate defines.
- abstract property duration: qupulse.expressions.sympy.ExpressionScalar¶
An expression for the duration of this PulseTemplate.
- property final_values: Dict[Union[str, int], qupulse.expressions.sympy.ExpressionScalar]¶
Values of defined channels at t == self.duration
- property initial_values: Dict[Union[str, int], qupulse.expressions.sympy.ExpressionScalar]¶
Values of defined channels at t == 0
- abstract property integral: Dict[Union[str, int], qupulse.expressions.sympy.ExpressionScalar]¶
Returns an expression giving the integral over the pulse.
- abstract property measurement_names: Set[str]¶
The set of measurement identifiers in this pulse template.
- pad_to(to_new_duration: Union[qupulse.expressions.ExpressionLike, Callable[[qupulse.expressions.sympy.Expression], qupulse.expressions.ExpressionLike]], pt_kwargs: Optional[Mapping[str, Any]] = None) qupulse.pulses.pulse_template.PulseTemplate [source]¶
Pad this pulse template to the given duration. The target duration can be numeric, symbolic or a callable that returns a new duration from the current duration.
Examples
# pad to a fixed duration >>> padded_1 = my_pt.pad_to(1000)
# pad to a fixed sample coun >>> padded_2 = my_pt.pad_to(‘sample_rate * 1000’)
# pad to the next muliple of 16 samples with a symbolic sample rate >>> padded_3 = my_pt.pad_to(to_next_multiple(‘sample_rate’, 16))
# pad to the next muliple of 16 samples with a fixed sample rate of 1 GHz >>> padded_4 = my_pt.pad_to(to_next_multiple(1, 16))
- Parameters
to_new_duration – Duration or callable that maps the current duration to the new duration
pt_kwargs – Keyword arguments for the newly created sequence pulse template.
- Returns
A pulse template that has the duration given by
to_new_duration
. It can beself
if the duration is already as required. It is neverself
ifpt_kwargs
is non-empty.
- abstract property parameter_names: Set[str]¶
The set of names of parameters required to instantiate this PulseTemplate.
- with_appended(*appended: qupulse.pulses.pulse_template.PulseTemplate)[source]¶
Create a
SequencePT
that represents a sequence of this pulse template and appendedYou can also use the @ operator to do this or call
qupulse.pulses.SequencePT.concatenate()
directly.
- with_iteration(loop_idx: str, loop_range) qupulse.pulses.pulse_template.PulseTemplate [source]¶
Create a
ForLoopPT
with the given index and range.Examples
>>> from qupulse.pulses import ConstantPT ... const = ConstantPT('t_hold', {'x': 'start_x + i_x * step_x', 'y': 'start_y + i_y * step_y'}) ... scan_2d = const.with_iteration('i_x', 'n_x').with_iteration('i_y', 'n_y')
- with_mapping(*mapping_tuple_args: Mapping, **mapping_kwargs: Mapping) qupulse.pulses.pulse_template.PulseTemplate [source]¶
Map parameters / channel names / measurement names. You may either specify the mappings as positional arguments XOR as keyword arguments. Positional arguments are forwarded to
from_tuple()
which automatically determines the “type” of the mappings. Keyword arguments must be one of the keyword arguments ofMappingPT
.- Parameters
*mapping_tuple_args – Mappings for parameters / channel names / measurement names
**mapping_kwargs – Mappings for parameters / channel names / measurement names
Examples
Equivalent ways to rename a channel and map a parameter value >>> from qupulse.pulses import FunctionPT … fpt = FunctionPT(‘sin(f * t)’, duration_expression=10, channel=’A’) … mapped = fpt.with_mapping({‘f’: 0.1}, {‘A’: ‘B’}) … mapped.defined_channels {‘B’}
>>> from qupulse.pulses import FunctionPT ... fpt = FunctionPT('sin(f * t)', duration_expression=10, channel='A') ... mapped = fpt.with_mapping(parameter_mapping={'f': 0.1}, channel_mapping={'A': 'B'}) ... mapped.defined_channels {'B'}
- Returns
A newly created mapping pulse template
- with_parallel_channels(values: Mapping[Union[str, int], qupulse.expressions.ExpressionLike]) qupulse.pulses.pulse_template.PulseTemplate [source]¶
Create a new pulse template that sets the given channels to the corresponding values.
See
ParallelChannelPulseTemplate
for implementation details and restictions.Examples
>>> from qupulse.pulses import FunctionPT ... fpt = FunctionPT('sin(0.1 * t)', duration_expression=10) ... fpt_and_marker = fpt.with_parallel_channels({'marker': 1})
- Parameters
values – Values to be set for each channel.
- Returns
A newly created pulse template.
- with_repetition(repetition_count: qupulse.expressions.ExpressionLike) qupulse.pulses.pulse_template.PulseTemplate [source]¶
Repeat this pulse template repetition_count times via a
RepetitionPulseTemplate
.Examples
>>> from qupulse.pulses import FunctionPT ... fpt = FunctionPT('sin(0.1 * t)', duration_expression=10) ... repeated = fpt.with_repetition('n_periods')
- Parameters
repetition_count – Amount of times this pulse template is repeated in the return value.
- Returns
A newly created pulse template.
- with_time_reversal() qupulse.pulses.pulse_template.PulseTemplate [source]¶
Reverse this pulse template by creating a
TimeReversalPT
.Examples
>>> from qupulse.pulses import FunctionPT ... forward = FunctionPT('sin(f * t)', duration_expression=10, channel='A') ... backward = fpt.with_time_reversal() ... forward_and_backward = forward @ backward
- exception qupulse.pulses.pulse_template.UnknownVolatileParameter[source]¶
Bases:
RuntimeWarning