Skip to content

Commit

Permalink
Fix: move ArrayGetter into qcodes so it can be used in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen authored and giulioungaretti committed Jan 17, 2017
1 parent 0edc9ac commit 33cfab0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
35 changes: 1 addition & 34 deletions docs/examples/toymodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,)
36 changes: 36 additions & 0 deletions qcodes/instrument/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,)

0 comments on commit 33cfab0

Please sign in to comment.