3.7.7. qupulse.pulses.mapping_pulse_template

Classes

MappingPulseTemplate(template, *[, ...])

This class can be used to remap parameters, the names of measurement windows and the names of channels.

Exceptions

AmbiguousMappingException(template, mapping)

Indicates that a mapping may apply to multiple objects

AutoMappingMatchingException(template)

Indicates that the auto match of mappings to mapped objects by the keys failed

MappingCollisionException(template, ...)

Indicates that multiple mappings are fitting for the same parameter type

MissingMappingException(template, key)

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

UnnecessaryMappingException(template, key)

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 qupulse.pulses.mapping_pulse_template.MappingPulseTemplate(template: qupulse.pulses.pulse_template.PulseTemplate, *, identifier: Optional[str] = None, parameter_mapping: Optional[Dict[str, str]] = None, measurement_mapping: Optional[Dict[str, str]] = None, channel_mapping: Optional[Dict[Union[str, int], Union[str, int]]] = None, parameter_constraints: Optional[List[str]] = None, allow_partial_parameter_mapping: bool = None, registry: Optional[MutableMapping[str, Serializable]] = 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 – 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

  • allow_partial_parameter_mapping – 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: qupulse.pulses.pulse_template.PulseTemplate, *, identifier: Optional[str] = None, parameter_mapping: Optional[Dict[str, str]] = None, measurement_mapping: Optional[Dict[str, str]] = None, channel_mapping: Optional[Dict[Union[str, int], Union[str, int]]] = None, parameter_constraints: Optional[List[str]] = None, allow_partial_parameter_mapping: bool = None, registry: Optional[MutableMapping[str, Serializable]] = None) 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 – 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

  • allow_partial_parameter_mapping – If None the value of the class variable ALLOW_PARTIAL_PARAMETER_MAPPING

build_waveform(parameters: Dict[str, numbers.Real], channel_mapping: Dict[Union[str, int], Union[str, int]]) qupulse.program.waveforms.Waveform[source]

This gets called if the parent is atomic

property channel_mapping: Dict[Union[str, int], Optional[Union[str, int]]]
property defined_channels: Set[Union[str, int]]

Implements defined_channels.

classmethod deserialize(serializer: Optional[qupulse.serialization.Serializer] = None, **kwargs) qupulse.pulses.mapping_pulse_template.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: qupulse.expressions.sympy.Expression

Implements duration.

property final_values: Dict[Union[str, int], qupulse.expressions.sympy.ExpressionScalar]

Values of defined channels at t == self.duration

classmethod from_tuple(mapping_tuple: Union[Tuple[qupulse.pulses.pulse_template.PulseTemplate], Tuple[qupulse.pulses.pulse_template.PulseTemplate, Dict], Tuple[qupulse.pulses.pulse_template.PulseTemplate, Dict, Dict], Tuple[qupulse.pulses.pulse_template.PulseTemplate, Dict, Dict, Dict]]) qupulse.pulses.mapping_pulse_template.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, numbers.Real], measurement_mapping: Dict[str, Optional[str]]) List[source]
get_serialization_data(serializer: Optional[qupulse.serialization.Serializer] = 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[Union[str, int], Optional[Union[str, int]]]) Dict[Union[str, int], Optional[Union[str, int]]][source]
get_updated_measurement_mapping(measurement_mapping: Dict[str, str]) Dict[str, str][source]
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.

map_parameter_values(parameters: Dict[str, numbers.Real], volatile: Set[str] = frozenset({})) Dict[str, numbers.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, numbers.Real]) Dict[str, numbers.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: qupulse.parameter_scope.Scope) qupulse.parameter_scope.MappedScope[source]
property measurement_mapping: Dict[str, str]
property measurement_names: Set[str]

Implements measurement_names.

property parameter_mapping: Mapping[str, qupulse.expressions.sympy.Expression]
property parameter_names: Set[str]

Implements parameter_names.

property template: qupulse.pulses.pulse_template.PulseTemplate
exception qupulse.pulses.mapping_pulse_template.MissingMappingException(template: qupulse.pulses.pulse_template.PulseTemplate, key: Union[str, Set[str]])[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: qupulse.pulses.pulse_template.PulseTemplate, key: Union[str, Set[str]])[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.