3.6.6. qupulse.pulses.mapping_pulse_template

class qupulse.pulses.mapping_pulse_template.MappingPulseTemplate(template, *, identifier=None, parameter_mapping=None, measurement_mapping=None, channel_mapping=None, parameter_constraints=None, allow_partial_parameter_mapping=None, registry=None)[source]

Bases: qupulse.pulses.pulse_template.PulseTemplate, qupulse.pulses.parameters.ParameterConstrainer

This class can be used to remap parameters, the names of measurement windows and the names of channels. Besides the standard constructor, there is a static member function from_tuple for convenience. The class also allows constraining parameters by deriving from ParameterConstrainer

Standard constructor for the MappingPulseTemplate.

Mappings that are not specified are defaulted to identity mappings. Channels and measurement names of the encapsulated template can be mapped partially by default. F.i. if channel_mapping only contains one of two channels the other channel name is mapped to itself. Channels that are mapped to None are dropped. However, if a parameter mapping is specified and one or more parameters are not mapped a MissingMappingException is raised. To allow partial mappings and enable the same behaviour as for the channel and measurement name mapping allow_partial_parameter_mapping must be set to True. Furthermore parameter constrains can be specified.

Parameters
  • template (PulseTemplate) – The encapsulated pulse template whose parameters, measurement names and channels are mapped

  • parameter_mapping (Optional[Dict[str, str]]) – if not none, mappings for all parameters must be specified

  • measurement_mapping (Optional[Dict[str, str]]) – mappings for other measurement names are inserted

  • channel_mapping (Optional[Dict[Union[str, int], Union[str, int]]]) – mappings for other channels are auto inserted. Mapping to None drops the channel.

  • parameter_constraints (Optional[List[str]]) –

  • allow_partial_parameter_mapping (Optional[bool]) – If None the value of the class variable ALLOW_PARTIAL_PARAMETER_MAPPING

ALLOW_PARTIAL_PARAMETER_MAPPING = True

Default value for allow_partial_parameter_mapping of the __init__ method.

__init__(template, *, identifier=None, parameter_mapping=None, measurement_mapping=None, channel_mapping=None, parameter_constraints=None, allow_partial_parameter_mapping=None, registry=None)[source]

Standard constructor for the MappingPulseTemplate.

Mappings that are not specified are defaulted to identity mappings. Channels and measurement names of the encapsulated template can be mapped partially by default. F.i. if channel_mapping only contains one of two channels the other channel name is mapped to itself. Channels that are mapped to None are dropped. However, if a parameter mapping is specified and one or more parameters are not mapped a MissingMappingException is raised. To allow partial mappings and enable the same behaviour as for the channel and measurement name mapping allow_partial_parameter_mapping must be set to True. Furthermore parameter constrains can be specified.

Parameters
  • template (PulseTemplate) – The encapsulated pulse template whose parameters, measurement names and channels are mapped

  • parameter_mapping (Optional[Dict[str, str]]) – if not none, mappings for all parameters must be specified

  • measurement_mapping (Optional[Dict[str, str]]) – mappings for other measurement names are inserted

  • channel_mapping (Optional[Dict[Union[str, int], Union[str, int]]]) – mappings for other channels are auto inserted. Mapping to None drops the channel.

  • parameter_constraints (Optional[List[str]]) –

  • allow_partial_parameter_mapping (Optional[bool]) – If None the value of the class variable ALLOW_PARTIAL_PARAMETER_MAPPING

Return type

None

build_waveform(parameters, channel_mapping)[source]

This gets called if the parent is atomic

Return type

Waveform

property channel_mapping
Return type

Dict[Union[str, int], Union[str, int, None]]

property defined_channels

Implements defined_channels.

Return type

Set[Union[str, int]]

classmethod deserialize(serializer=None, **kwargs)[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 (Optional[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.

Return type

MappingPulseTemplate

property duration

Implements duration.

Return type

Expression

classmethod from_tuple(mapping_tuple)[source]

Construct a MappingPulseTemplate from a tuple of mappings. The mappings are automatically assigned to the mapped elements based on their content. :type mapping_tuple: Union[Tuple[PulseTemplate], Tuple[PulseTemplate, Dict], Tuple[PulseTemplate, Dict, Dict], Tuple[PulseTemplate, Dict, Dict, Dict]] :param mapping_tuple: A tuple of mappings :rtype: MappingPulseTemplate :return: Constructed MappingPulseTemplate

get_measurement_windows(parameters, measurement_mapping)[source]
Return type

List

get_serialization_data(serializer=None)[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.

Return type

Dict[str, Any]

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)[source]
Return type

Dict[Union[str, int], Union[str, int, None]]

get_updated_measurement_mapping(measurement_mapping)[source]
Return type

Dict[str, str]

property integral

Implements integral.

Return type

Dict[Union[str, int], ExpressionScalar]

map_parameter_objects(parameters, volatile=frozenset({}))[source]

Map parameter objects (instances of Parameter class) according to the defined mappings.

Parameters
  • parameters (Dict[str, Parameter]) – Dictionary with parameter objects

  • volatile (Optional) – Forwarded to validate_parameter_constraints

Return type

Dict[str, Parameter]

Returns

A new dictionary with mapped parameter objects

map_parameter_values(parameters, volatile=frozenset({}))[source]

Map parameter values according to the defined mappings.

Parameters
  • parameters (Dict[str, Real]) – Dictionary with numeric values

  • volatile (Optional) – Forwarded to validate_parameter_constraints

Return type

Dict[str, Real]

Returns

A new dictionary with mapped numeric values.

map_parameters(parameters)[source]

Map parameter values according to the defined mappings.

Parameters

parameters (Dict[str, Union[Parameter, Real]]) – A mapping of parameter names to parameter objects/values.

Return type

Dict[str, Union[Parameter, Real]]

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)[source]
Return type

MappedScope

property measurement_mapping
Return type

Dict[str, str]

property measurement_names

Implements measurement_names.

Return type

Set[str]

property parameter_mapping
Return type

Mapping[str, Expression]

property parameter_names

Implements parameter_names.

Return type

Set[str]

property template
Return type

PulseTemplate

exception qupulse.pulses.mapping_pulse_template.MissingMappingException(template, key)[source]

Bases: Exception

Indicates that no mapping was specified for some parameter declaration of a SequencePulseTemplate’s subtemplate.

exception qupulse.pulses.mapping_pulse_template.UnnecessaryMappingException(template, key)[source]

Bases: Exception

Indicates that a mapping was provided that does not correspond to any of a SequencePulseTemplate’s subtemplate’s parameter declarations and is thus obsolete.