示例#1
0
def testMeta(parameters):
    name = "combined"
    label = "Linear Combination"
    unit = "a.u"
    aggregator = linear
    sweep_values = combine(*parameters,
                           name=name,
                           label=label,
                           unit=unit,
                           aggregator=aggregator)
    snap = sweep_values.snapshot()
    out = OrderedDict()
    out['__class__'] = full_class(sweep_values)
    out["unit"] = unit
    out["label"] = label
    out["full_name"] = name
    out["aggregator"] = repr(linear)
    for param in sweep_values.parameters:
        out[param.full_name] = {}
    assert out == snap
示例#2
0
    def snapshot_base(self, update=False):
        """
        State of the instrument as a JSON-compatible dict.

        Args:
            update (bool): If True, update the state by querying the
                instrument. If False, just use the latest values in memory.

        Returns:
            dict: base snapshot
        """
        snap = {'parameters': dict((name, param.snapshot(update=update))
                                   for name, param in self.parameters.items()),
                'functions': dict((name, func.snapshot(update=update))
                                  for name, func in self.functions.items()),
                '__class__': full_class(self),
                }
        for attr in set(self._meta_attrs):
            if hasattr(self, attr):
                snap[attr] = getattr(self, attr)
        return snap
示例#3
0
    def snapshot_base(self, update: Optional[bool] = False,
                      params_to_skip_update: Optional[Sequence[str]] = None):
        """
        State of the loop as a JSON-compatible dict (everything that
        the custom JSON encoder class :class:'qcodes.utils.helpers.NumpyJSONEncoder'
        supports).

        Args:
            update: If True, update the state by querying the underlying
                sweep_values and actions. If None only update state if known
                to be invalid. If False, just use the latest values
                in memory.
            params_to_skip_update: Unused in this implementation.

        Returns:
            dict: base snapshot
        """
        return {
            '__class__': full_class(self),
            'sweep_values': self.sweep_values.snapshot(update=update),
            'delay': self.delay,
            'then_actions': _actions_snapshot(self.then_actions, update)
        }
示例#4
0
 def test_full_class(self):
     self.assertEqual(full_class(self.j), 'json.encoder.JSONEncoder')
示例#5
0
 def snapshot_base(self, update: Optional[bool] = False,
                   params_to_skip_update: Optional[Sequence[str]] = None):
     return {
         '__class__': full_class(self),
         'actions': _actions_snapshot(self._dummyLoop.actions, update)
     }
示例#6
0
 def snapshot_base(self, update=False):
     return {
         '__class__': full_class(self),
         'actions': _actions_snapshot(self._dummyLoop.actions, update)
     }
示例#7
0
    def snapshot_base(
        self,
        update: Optional[bool] = False,
        params_to_skip_update: Optional[Sequence[str]] = None
    ) -> Dict[Any, Any]:
        """
        State of the instrument as a JSON-compatible dict (everything that
        the custom JSON encoder class
        :class:`qcodes.utils.helpers.NumpyJSONEncoder`
        supports).

        Args:
            update: If ``True``, update the state by querying the
                instrument. If None update the state if known to be invalid.
                If ``False``, just use the latest values in memory and never
                update state.
            params_to_skip_update: List of parameter names that will be skipped
                in update even if update is True. This is useful if you have
                parameters that are slow to update but can be updated in a
                different way (as in the qdac). If you want to skip the
                update of certain parameters in all snapshots, use the
                ``snapshot_get`` attribute of those parameters instead.

        Returns:
            dict: base snapshot
        """

        if params_to_skip_update is None:
            params_to_skip_update = []

        snap: Dict[str, Any] = {
            "functions": {
                name: func.snapshot(update=update)
                for name, func in self.functions.items()
            },
            "submodules": {
                name: subm.snapshot(update=update)
                for name, subm in self.submodules.items()
            },
            "__class__": full_class(self)
        }

        snap['parameters'] = {}
        for name, param in self.parameters.items():
            if param.snapshot_exclude:
                continue
            if params_to_skip_update and name in params_to_skip_update:
                update_par: Optional[bool] = False
            else:
                update_par = update
            try:
                snap['parameters'][name] = param.snapshot(update=update_par)
            except:
                # really log this twice. Once verbose for the UI and once
                # at lower level with more info for file based loggers
                self.log.warning(f"Snapshot: Could not update "
                                 f"parameter: {name}")
                self.log.info(f"Details for Snapshot:", exc_info=True)
                snap['parameters'][name] = param.snapshot(update=False)

        for attr in set(self._meta_attrs):
            if hasattr(self, attr):
                snap[attr] = getattr(self, attr)
        return snap
示例#8
0
    def snapshot_base(self, update: bool=False,
                      params_to_skip_update: Sequence[str]=None,
                      skip_parameters: Sequence[str] = (),
                      skip_parameter_nodes: Sequence[str] = ()):
        """
        State of the instrument as a JSON-compatible dict.

        Args:
            update (bool): If True, update the state by querying the
                instrument. If False, just use the latest values in memory.
            params_to_skip_update: List of parameter names that will be skipped
                in update even if update is True. This is useful if you have
                parameters that are slow to update but can be updated in a
                different way (as in the qdac)
            skip_parameters: Names of parameters to skip from snapshot
            skip_parameter_nodes: Names of parameter nodes to skip from snapshot

        Returns:
            dict: base snapshot
        """
        if self.simplify_snapshot:
            snap = {"__class__": full_class(self)}
            if self.functions:
                snap["functions"] = {name: func.snapshot(update=update)
                                     for name, func in self.functions.items()}
            if self.submodules:
                snap["submodules"] = {name: subm.snapshot(update=update)
                                      for name, subm in self.submodules.items()}
            for parameter_name, parameter in self.parameters.items():
                if parameter_name in skip_parameters:
                    continue
                parameter_snapshot = parameter.snapshot()
                if 'unit' in parameter_snapshot:
                    parameter_name = f'{parameter_name} ({parameter_snapshot["unit"]})'
                if parameter._snapshot_value:
                    snap[parameter_name] = parameter_snapshot['value']
                else:
                    snap[parameter_name] = parameter_snapshot
            for parameter_node_name, parameter_node in self.parameter_nodes.items():
                if parameter_node_name in skip_parameter_nodes:
                    continue
                snap[parameter_node_name] = parameter_node.snapshot()
        else:
            snap = {
                "functions": {name: func.snapshot(update=update)
                              for name, func in self.functions.items()},
                "submodules": {name: subm.snapshot(update=update)
                               for name, subm in self.submodules.items()},
                "__class__": full_class(self),
                "parameters": {},
                "parameter_nodes": {
                    name: node.snapshot()
                    for name, node in self.parameter_nodes.items()
                    if name not in skip_parameter_nodes
                }
            }

            for name, param in self.parameters.items():
                if name in skip_parameters:
                    continue
                update = update
                if params_to_skip_update and name in params_to_skip_update:
                    update = False
                try:
                    snap['parameters'][name] = param.snapshot(
                        update=update, simplify=self.simplify_snapshot)
                except:
                    logger.debug(f"Snapshot: Could not update parameter: {name}")
                    snap['parameters'][name] = param.snapshot(
                        update=False, simplify=self.simplify_snapshot)
            for attr in set(self._meta_attrs):
                if hasattr(self, attr):
                    snap[attr] = getattr(self, attr)

        return snap
示例#9
0
def test_full_class():
    j = json.JSONEncoder()
    assert full_class(j) == 'json.encoder.JSONEncoder'