Exemple #1
0
    def add_parameter(self,
                      name: str,
                      parameter_class: type = Parameter,
                      **kwargs: Any) -> None:

        existing_parameter = self.parameters.get(name, None)

        if isinstance(existing_parameter, AbstractParameter):
            # For abstract parameters, we define special behavior.
            existing_unit = getattr(existing_parameter, "unit", None)
            new_unit = kwargs.get("unit", None)

            if existing_unit and existing_unit != new_unit:
                raise AbstractParameterException(
                    f"The unit of the parameter '{name}' is '{new_unit}', "
                    f"which is inconsistent with the unit '{existing_unit}' "
                    f"specified earlier. This is usually because a driver "
                    f"is a subclass of a baseclass which defines a parameter "
                    f"of the same name but with different units")

            param = parameter_class(name=name, instrument=self, **kwargs)
            self.parameters[name] = param

        else:
            # If it is a usual parameter, call the super class
            InstrumentBase.add_parameter(self, name, parameter_class, **kwargs)
Exemple #2
0
 def add_parameter_from_dict(instr: InstrumentBase, name: str,
                             options: Dict[str, Any]) -> None:
     # keep the original dictionray intact for snapshot
     options = copy(options)
     param_type: type = _BaseParameter
     kwargs = {}
     if 'source' in options:
         param_type = DelegateParameter
         kwargs['source'] = resolve_parameter_identifier(
             instr.root_instrument, options['source'])
         options.pop('source')
     instr.add_parameter(name, param_type, **kwargs)
     setup_parameter_from_dict(instr.parameters[name], options)