Skip to content

Commit

Permalink
Add missing functions and parameters to channellist
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed Jun 6, 2017
1 parent 945edd3 commit 347c0b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 23 additions & 7 deletions qcodes/instrument/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ class ChannelList(Metadatable):
Attributes:
parameters (Dict[Parameter]): All the parameters supported by this group of channels.
This is implemented as a reference to the parameters in the first channel so if you
dynamically modify one or more channels this will not be accurate.
functions (Dict[Function]): All the functions supported by this group of channels
"""

def __init__(self, parent, name, chan_type, chan_list=None, snapshotable=True):
def __init__(self, parent, name, chan_type: type, chan_list=None, snapshotable=True):
super().__init__()

self._parent = parent
Expand All @@ -124,6 +126,8 @@ def __init__(self, parent, name, chan_type, chan_list=None, snapshotable=True):
self._chan_type = chan_type
self._snapshotable = snapshotable

self.parameters = {}
self.functions = {}
# If a list of channels is not provided, define a list to store channels.
# This will eventually become a locked tuple.
if chan_list is None:
Expand All @@ -132,11 +136,11 @@ def __init__(self, parent, name, chan_type, chan_list=None, snapshotable=True):
else:
self._locked = True
self._channels = tuple(chan_list)
self.parameters = self._channels[0].parameters
self.functions = self._channels[0].functions
if not all(isinstance(chan, chan_type) for chan in self._channels):
raise TypeError("All items in this channel list must be of type {}.".format(chan_type.__name__))



def __getitem__(self, i):
"""
Return either a single channel, or a new ChannelList containing only the specified channels
Expand Down Expand Up @@ -178,7 +182,7 @@ def __add__(self, other):

return ChannelList(self._parent, self._name, self._chan_type, self._channels + other._channels)

def append(self, obj):
def append(self, obj: InstrumentChannel):
"""
When initially constructing the channel list, a new channel to add to the end of the list
Expand All @@ -191,9 +195,13 @@ def append(self, obj):
raise TypeError("All items in a channel list must be of the same type."
" Adding {} to a list of {}.".format(type(obj).__name__,
self._chan_type.__name__))
if not self.parameters:
self.parameters = obj.parameters
if not self.functions:
self.functions = obj.functions
return self._channels.append(obj)

def extend(self, objects):
def extend(self, objects: InstrumentChannel):
"""
Insert an iterable of objects into the list of channels.
Expand All @@ -207,9 +215,13 @@ def extend(self, objects):
raise AttributeError("Cannot extend a locked channel list")
if not all(isinstance(obj, self._chan_type) for obj in objects):
raise TypeError("All items in a channel list must be of the same type.")
if not self.parameters:
self.parameters = objects[0].parameters
if not self.functions:
self.functions = objects[0].functions
return self._channels.extend(objects)

def index(self, obj):
def index(self, obj: InstrumentChannel):
"""
Return the index of the given object
Expand All @@ -218,7 +230,7 @@ def index(self, obj):
"""
return self._channels.index(obj)

def insert(self, index, obj):
def insert(self, index, obj: InstrumentChannel):
"""
Insert an object into the channel list at a specific index.
Expand All @@ -233,6 +245,10 @@ def insert(self, index, obj):
raise TypeError("All items in a channel list must be of the same type."
" Adding {} to a list of {}.".format(type(obj).__name__,
self._chan_type.__name__))
if not self.parameters:
self.parameters = obj.parameters
if not self.functions:
self.functions = obj.functions
return self._channels.insert(index, obj)

def lock(self):
Expand Down
4 changes: 3 additions & 1 deletion qcodes/tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ def test_combine_channels(self, setpoints):
expected = tuple(setpoints[0:2] + [0, 0] + setpoints[2:])
self.assertEquals(self.instrument.channels.temperature(), expected)

def test_channel_parameters(self):
self.assertTrue('temperature' in self.instrument.channels.parameters)
self.assertEqual(len(self.instrument.channels.parameters), 1)

class TestChannelsLoop(TestCase):
pass

def setUp(self):
self.instrument = DummyChannelInstrument(name='testchanneldummy')
Expand Down

0 comments on commit 347c0b2

Please sign in to comment.