3.6.7. qupulse.pulses.mapping_pulse_template¶
Defines the pulse template for parameter, channel and measurement mapping.
Classes
|
This class can be used to map a pulse template's parameters with mathematical expressions and rename its measurements and channels. |
Exceptions
|
Indicates that a mapping may apply to multiple objects |
|
Indicates that the auto match of mappings to mapped objects by the keys failed |
|
Indicates that multiple mappings are fitting for the same parameter type |
|
Indicates that no mapping was specified for some parameter declaration of a SequencePulseTemplate's subtemplate. |
|
Indicates that a mapping was provided that does not correspond to any of a SequencePulseTemplate's subtemplate's parameter declarations and is thus obsolete. |
- class MappingPulseTemplate(template: PulseTemplate, *, identifier: str | None = None, parameter_mapping: Dict[str, ExpressionLike] | None = None, measurement_mapping: Dict[str, str | None] | None = None, channel_mapping: Dict[str | int, str | int | None] | None = None, parameter_constraints: List[str] | None = None, allow_partial_parameter_mapping: bool = None, metadata: TemplateMetadata | dict = None, registry: MutableMapping[str, Serializable] | None = None)[source]¶
Bases:
PulseTemplate,ParameterConstrainerThis class can be used to map a pulse template’s parameters with mathematical expressions and rename its measurements and channels.
Besides the standard constructor which is intended for verbose construction with keyword arguments, there is
MappingPulseTemplate.from_tuple()which allows compact code style. It is also used by the convenience functionPulseTemplate.with_mapping().The class allows constraining the newly mapped parameters by deriving from
ParameterConstrainer.Mappings that are not specified are defaulted to identity mappings. Channels and measurement names of the encapsulated template can be mapped partially by default. For example, if
channel_mappingonly contains one of two channels the other channel name is mapped to itself.>>> from qupulse.pulses import * >>> inner = ConstantPT(duration=1, amplitude_dict={'A': 1.0, 'B': 2.0}) >>> inner.defined_channels {'A', 'B'} >>> mapped = MappingPT(inner, channel_mapping={'A': 'X'}) >>> mapped.defined_channels {'X', 'B'}
Channels that are mapped to None are dropped.
>>> mapped = MappingPT(inner, channel_mapping={'A': None}) >>> mapped.defined_channels {'B'}
However,
allow_partial_parameter_mappingis set False or if it is unset and the default valueMappingPulseTemplate.ALLOW_PARTIAL_PARAMETER_MAPPINGis used, the parameter mappings must map all parameters. Otherwise, aMissingMappingExceptionis raised.- Raises:
ValueError – If the channel mapping maps multiple channels to the same channel.
- Parameters:
template – The encapsulated pulse template whose parameters, measurement names and channels are mapped
parameter_mapping – if not none, mappings for all parameters must be specified
measurement_mapping – mappings for other measurement names are inserted
channel_mapping – mappings for other channels are auto inserted. Mapping to None drops the channel.
parameter_constraints – See
ParameterConstrainerallow_partial_parameter_mapping – If None it defaults to
MappingPulseTemplate.ALLOW_PARTIAL_PARAMETER_MAPPINGmetadata – Used to initialize
PulseTemplate.metadata.registry – If specified, the new pulse template is registered there after initialization.
- ALLOW_PARTIAL_PARAMETER_MAPPING = True¶
Default value for
allow_partial_parameter_mappingof the initialization.
- build_waveform(parameters: Dict[str, Real], channel_mapping: Dict[str | int, str | int]) Waveform[source]¶
This gets called if the parent is atomic
- property defined_channels: Set[str | int]¶
Implements
PulseTemplate.defined_channels.
- classmethod deserialize(serializer: Serializer | None = None, **kwargs) MappingPulseTemplate[source]¶
Reconstructs the Serializable object from a dictionary.
Implementation hint: For greater clarity, implementations of this method should be precise in their return value, i.e., give their exact class name, and also replace the kwargs argument by a list of arguments required, i.e., those returned by get_serialization_data. Using old serialization routines, if this Serializable contains complex objects which are itself of type Serializable, their dictionary representations MUST be converted into objects using serializers deserialize() method. This is DEPRECATED behavior. Using the new routines, a serializable is only responsible to decode it’s own dictionary, not those of nested objects (i.e., all incoming arguments are already processed by the serialization routines). For the transition time where both variants are available, implementations of this method should support the old and new routines, using the presence of the serializer argument to differentiate between both. For the new routines, just call this base class function. After the transition period, subclasses likely need not implement deserialize separately anymore at all.
- Parameters:
serializer – DEPRECATED (May 2018). A serializer instance used when deserializing subelements.
**kwargs – All relevant properties of the object as keyword arguments. For every (key,value) pair returned by get_serialization_data, the same pair is given as keyword argument as input to this method.
- property duration: Expression¶
Implements
PulseTemplate.duration.
- property final_values: Dict[str | int, ExpressionScalar]¶
Values of defined channels at t == self.duration
- classmethod from_tuple(mapping_tuple: Tuple[PulseTemplate] | Tuple[PulseTemplate, Dict] | Tuple[PulseTemplate, Dict, Dict] | Tuple[PulseTemplate, Dict, Dict, Dict]) MappingPulseTemplate[source]¶
Construct a MappingPulseTemplate from a tuple of mappings. The mappings are automatically assigned to the mapped elements based on their content. :param mapping_tuple: A tuple of mappings :return: Constructed MappingPulseTemplate
- get_measurement_windows(parameters: Dict[str, Real], measurement_mapping: Dict[str, str | None]) List[source]¶
- get_serialization_data(serializer: Serializer | None = None) Dict[str, Any][source]¶
Returns all data relevant for serialization as a dictionary containing only base types.
Implementation hint: In the old serialization routines, if the Serializable contains complex objects which are itself Serializables, a serialized representation for these MUST be obtained by calling the dictify() method of serializer. The reason is that serializer may decide to either return a dictionary to embed or only a reference to the Serializable subelement. This is DEPRECATED behavior as of May 2018. In the new routines, this will happen automatically and every Serializable is only responsible for returning it’s own data and leave nested Serializables in object form.
For the transition time where both implementations are available, implementations of this method should support the old and new routines, using the presence of the serializer argument to differentiate between both. Don’t make use of the implementation in this base class when implementing this method for the old routines.
- Parameters:
serializer (Serializer) – DEPRECATED (May 2018).A Serializer instance used to serialize complex subelements of this Serializable.
- Returns:
- A dictionary of Python base types (strings, integers, lists/tuples containing these,
etc..) which fully represent the relevant properties of this Serializable for storing and later reconstruction as a Python object.
- get_updated_channel_mapping(channel_mapping: Dict[str | int, str | int | None]) Dict[str | int, str | int | None][source]¶
This function integrates this object’s channel mapping with the supplied
channel_mappingi.e., it translates a mapping that is valid in the outer namespace to a mapping that is valid in the inner namespace.- Parameters:
channel_mapping – Channel mapping to translate.
- Returns:
The channel mapping translated for the inner template to consume.
- get_updated_measurement_mapping(measurement_mapping: Dict[str, str]) Dict[str, str][source]¶
This function integrates this object’s measurement mapping with the supplied
measurement_mappingi.e., it translates a mapping that is valid in the outer namespace to a mapping that is valid in the inner namespace.- Parameters:
measurement_mapping – Measurement mapping to translate.
- Returns:
The measurement mapping translated for the inner template to consume.
- property initial_values: Dict[str | int, ExpressionScalar]¶
Values of defined channels at t == 0
- property integral: Dict[str | int, ExpressionScalar]¶
Implements
PulseTemplate.integral.
- map_parameter_values(parameters: Dict[str, Real], volatile: Set[str] = frozenset({})) Dict[str, Real][source]¶
Map parameter values according to the defined mappings.
- Parameters:
parameters – Dictionary with numeric values
volatile (Optional) – Forwarded to validate_parameter_constraints
- Returns:
A new dictionary with mapped numeric values.
- map_parameters(parameters: Dict[str, Real]) Dict[str, Real][source]¶
Map parameter values according to the defined mappings.
- Parameters:
parameters – A mapping of parameter names to parameter objects/values.
- Returns:
A new dictionary which maps parameter names to parameter values which have been mapped according to the mappings defined for template.
- map_scope(scope: Scope) MappedScope[source]¶
- property measurement_names: Set[str]¶
Implements
PulseTemplate.measurement_names.
- property parameter_mapping: Mapping[str, Expression]¶
- property parameter_names: Set[str]¶
Implements
PulseTemplate.parameter_names.
- property template: PulseTemplate¶