From 091f9a3641da12ba24e623c5d22e06023322cd5b Mon Sep 17 00:00:00 2001 From: FQT Date: Tue, 3 Oct 2017 15:40:38 +1100 Subject: [PATCH 1/5] fix:save scaled value, perform initial get --- qcodes/instrument/parameter.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qcodes/instrument/parameter.py b/qcodes/instrument/parameter.py index 8d4fe186a05..6abd69701f1 100644 --- a/qcodes/instrument/parameter.py +++ b/qcodes/instrument/parameter.py @@ -347,8 +347,13 @@ def set_wrapper(value, **kwargs): set_function(val, **kwargs) self.raw_value = val - self._save_val(val, validate=(self.val_mapping is None and - self.set_parser is None)) + if self.scale is not None: + scaled_val = val / self.scale + else: + scaled_val = val + self._save_val(scaled_val, + validate=(self.val_mapping is None and + self.set_parser is None)) # Update last set time (used for calculating delays) self._t_last_set = time.perf_counter() @@ -379,7 +384,9 @@ def get_ramp_values(self, value, step=None): if step is None: return [value] else: - start_value = self.get_latest() + if self.get_latest() is None: + self.get() + start_value = self.raw_value self.validate(start_value) From 983925f34c8c5cd7019b10d5e53154c37b14e6e9 Mon Sep 17 00:00:00 2001 From: FQT Date: Tue, 3 Oct 2017 17:35:50 +1100 Subject: [PATCH 2/5] fix: self.get return raw_value when possible --- qcodes/instrument/parameter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qcodes/instrument/parameter.py b/qcodes/instrument/parameter.py index 6abd69701f1..be1bed17971 100644 --- a/qcodes/instrument/parameter.py +++ b/qcodes/instrument/parameter.py @@ -654,7 +654,8 @@ def __init__(self, name, instrument=None, label=None, unit=None, if max_val_age is not None: raise SyntaxError('Must have get method or specify get_cmd ' 'when max_val_age is set') - self.get = self.get_latest + self.get = lambda: self.state.get('raw_value', + self.state['value']) else: exec_str = instrument.ask if instrument else None self.get = Command(arg_count=0, cmd=get_cmd, exec_str=exec_str) From f2d0d16c996536e281dcf1e772da8f56f5cf8a26 Mon Sep 17 00:00:00 2001 From: FQT Date: Tue, 3 Oct 2017 17:55:07 +1100 Subject: [PATCH 3/5] fix: the get function when get_cmd=None did not take any scaling into account --- qcodes/instrument/parameter.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qcodes/instrument/parameter.py b/qcodes/instrument/parameter.py index be1bed17971..1d357b4e844 100644 --- a/qcodes/instrument/parameter.py +++ b/qcodes/instrument/parameter.py @@ -178,7 +178,7 @@ def __init__(self, name, instrument, snapshot_get=True, metadata=None, # record of latest value and when it was set or measured # what exactly this means is different for different subclasses # but they all use the same attributes so snapshot is consistent. - self._latest = {'value': None, 'ts': None} + self._latest = {'value': None, 'ts': None, 'raw_value': None} self.get_latest = GetLatest(self, max_val_age=max_val_age) if hasattr(self, 'get'): @@ -267,7 +267,8 @@ def snapshot_base(self, update=False): def _save_val(self, value, validate=False): if validate: self.validate(value) - self._latest = {'value': value, 'ts': datetime.now()} + self._latest = {'value': value, 'ts': datetime.now(), + 'raw_value': self.raw_value} def _wrap_get(self, get_function): @wraps(get_function) @@ -654,8 +655,7 @@ def __init__(self, name, instrument=None, label=None, unit=None, if max_val_age is not None: raise SyntaxError('Must have get method or specify get_cmd ' 'when max_val_age is set') - self.get = lambda: self.state.get('raw_value', - self.state['value']) + self.get = lambda: self._latest.get('raw_value') else: exec_str = instrument.ask if instrument else None self.get = Command(arg_count=0, cmd=get_cmd, exec_str=exec_str) @@ -675,7 +675,7 @@ def __init__(self, name, instrument=None, label=None, unit=None, self.unit = unit if unit is not None else '' if initial_value is not None: - self._save_val(initial_value, validate=True) + self.set(initial_value) # generate default docstring self.__doc__ = os.linesep.join(( From ecf3d17368fc4f8bb243ff63f805e1645c5856be Mon Sep 17 00:00:00 2001 From: FQT Date: Tue, 3 Oct 2017 18:08:19 +1100 Subject: [PATCH 4/5] fix: pop raw_value when snapshot_value=False --- qcodes/instrument/parameter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qcodes/instrument/parameter.py b/qcodes/instrument/parameter.py index 1d357b4e844..6c022e699e8 100644 --- a/qcodes/instrument/parameter.py +++ b/qcodes/instrument/parameter.py @@ -188,7 +188,7 @@ def __init__(self, name, instrument, snapshot_get=True, metadata=None, # subclasses should extend this list with extra attributes they # want automatically included in the snapshot - self._meta_attrs = ['name', 'instrument', 'step', 'scale', 'raw_value', + self._meta_attrs = ['name', 'instrument', 'step', 'scale', 'inter_delay', 'post_delay', 'val_mapping', 'vals'] # Specify time of last set operation, used when comparing to delay to @@ -243,6 +243,7 @@ def snapshot_base(self, update=False): if not self._snapshot_value: state.pop('value') + state.pop('raw_value', None) if isinstance(state['ts'], datetime): state['ts'] = state['ts'].strftime('%Y-%m-%d %H:%M:%S') From b466430695fa47b3eb8a41d676ca9aec5605cd1f Mon Sep 17 00:00:00 2001 From: FQT Date: Tue, 3 Oct 2017 18:22:12 +1100 Subject: [PATCH 5/5] fix: return self._latest['value'] if self.scale is None --- qcodes/instrument/parameter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qcodes/instrument/parameter.py b/qcodes/instrument/parameter.py index 6c022e699e8..cb84e287588 100644 --- a/qcodes/instrument/parameter.py +++ b/qcodes/instrument/parameter.py @@ -656,7 +656,8 @@ def __init__(self, name, instrument=None, label=None, unit=None, if max_val_age is not None: raise SyntaxError('Must have get method or specify get_cmd ' 'when max_val_age is set') - self.get = lambda: self._latest.get('raw_value') + self.get = lambda: self._latest['value' if self.scale is None + else 'raw_value'] else: exec_str = instrument.ask if instrument else None self.get = Command(arg_count=0, cmd=get_cmd, exec_str=exec_str)