diff --git a/docs/examples/toymodel.py b/docs/examples/toymodel.py index 1e117150ff6..fb28c353b4a 100644 --- a/docs/examples/toymodel.py +++ b/docs/examples/toymodel.py @@ -4,7 +4,7 @@ from qcodes import MockInstrument, MockModel, Parameter, Loop, DataArray from qcodes.utils.validators import Numbers - +from qcodes.instrument.mock import ArrayGetter class AModel(MockModel): def __init__(self): @@ -147,36 +147,3 @@ def get(self): array = data.arrays[self.measured_param.full_name] return (array, array.mean()) - -class ArrayGetter(Parameter): - """ - Example parameter that just returns a single array - - TODO: in theory you can make this same Parameter with - name, label & shape (instead of names, labels & shapes) and altered - setpoints (not wrapped in an extra tuple) and this mostly works, - but when run in a loop it doesn't propagate setpoints to the - DataSet. We could track down this bug, but perhaps a better solution - would be to only support the simplest and the most complex Parameter - forms (ie cases 1 and 5 in the Parameter docstring) and do away with - the intermediate forms that make everything more confusing. - """ - def __init__(self, measured_param, sweep_values, delay): - name = measured_param.name - super().__init__(names=(name,)) - self._instrument = getattr(measured_param, '_instrument', None) - self.measured_param = measured_param - self.sweep_values = sweep_values - self.delay = delay - self.shapes = ((len(sweep_values),),) - set_array = DataArray(parameter=sweep_values.parameter, - preset_data=sweep_values) - self.setpoints = ((set_array,),) - if hasattr(measured_param, 'label'): - self.labels = (measured_param.label,) - - def get(self): - loop = Loop(self.sweep_values, self.delay).each(self.measured_param) - data = loop.run_temp() - array = data.arrays[self.measured_param.full_name] - return (array,) diff --git a/qcodes/instrument/mock.py b/qcodes/instrument/mock.py index 5bf8df500a5..9d29d66925f 100644 --- a/qcodes/instrument/mock.py +++ b/qcodes/instrument/mock.py @@ -3,6 +3,9 @@ from datetime import datetime from .base import Instrument +from .parameter import Parameter +from qcodes import Loop +from qcodes.data.data_array import DataArray from qcodes.process.server import ServerManager, BaseServer from qcodes.utils.nested_attrs import _NoDefault @@ -279,3 +282,36 @@ def _delattr(self, attr): See NestedAttrAccess for details. """ self.ask('method_call', 'delattr', attr) + +class ArrayGetter(Parameter): + """ + Example parameter that just returns a single array + + TODO: in theory you can make this same Parameter with + name, label & shape (instead of names, labels & shapes) and altered + setpoints (not wrapped in an extra tuple) and this mostly works, + but when run in a loop it doesn't propagate setpoints to the + DataSet. We could track down this bug, but perhaps a better solution + would be to only support the simplest and the most complex Parameter + forms (ie cases 1 and 5 in the Parameter docstring) and do away with + the intermediate forms that make everything more confusing. + """ + def __init__(self, measured_param, sweep_values, delay): + name = measured_param.name + super().__init__(names=(name,)) + self._instrument = getattr(measured_param, '_instrument', None) + self.measured_param = measured_param + self.sweep_values = sweep_values + self.delay = delay + self.shapes = ((len(sweep_values),),) + set_array = DataArray(parameter=sweep_values.parameter, + preset_data=sweep_values) + self.setpoints = ((set_array,),) + if hasattr(measured_param, 'label'): + self.labels = (measured_param.label,) + + def get(self): + loop = Loop(self.sweep_values, self.delay).each(self.measured_param) + data = loop.run_temp() + array = data.arrays[self.measured_param.full_name] + return (array,) \ No newline at end of file