def test_channels_count(dci): names = ("A", "B", "C", "D", "E", "F", "G", "H") channels = tuple(DummyChannel(dci, name, name) for name in names) chlist = ChannelList(dci, "channels", DummyChannel, channels) for channel in channels: assert chlist.count(channel) == 1
def __init__( self, name: str = 'mdac', num_channels: int = 10, **kwargs): """ Create a dummy instrument that can be used for testing Args: name: name for the instrument gates: list of names that is used to create parameters for the instrument """ super().__init__(name, **kwargs) # make gates channels = ChannelList(self, "channels", MockDACChannel) for n in range(num_channels): num = str(n + 1).zfill(2) chan_name = f"ch{num}" channel = MockDACChannel(parent=self, name=chan_name, num=num) channels.append(channel) self.add_submodule(chan_name, channel) self.add_submodule("channels", channels)
def test_access_channels_by_name(dci, myindexs): names = ("A", "B", "C", "D", "E", "F", "G", "H") channels = tuple(DummyChannel(dci, "Chan" + name, name) for name in names) chlist = ChannelList(dci, "channels", DummyChannel, channels) channel_names = (f"Chan{names[i]}" for i in myindexs) mychans = chlist.get_channel_by_name(*channel_names) for chan, chanindex in zip(mychans, myindexs): assert chan.name == f'dci_Chan{names[chanindex]}'
def __init__(self, name, **kwargs): super().__init__(name, **kwargs) channels = ChannelList(self, "TempSensors", DummyChannel, snapshotable=False) for chan_name in ('A', 'B', 'C', 'D', 'E', 'F'): channel = DummyChannel(self, f'Chan{chan_name}', chan_name) channels.append(channel) self.add_submodule(chan_name, channel) self.add_submodule("channels", channels)
def test_remove_tupled_channel(self): channel_tuple = tuple( DummyChannel(self.instrument, f'Chan{C}', C) for C in ('A', 'B', 'C', 'D', 'E', 'F')) channels = ChannelList(self.instrument, "TempSensorsTuple", DummyChannel, channel_tuple, snapshotable=False) chanA = channels.ChanA with self.assertRaises(AttributeError): channels.remove(chanA)
def test_remove_tupled_channel(dci): channel_tuple = tuple( DummyChannel(dci, f'Chan{C}', C) for C in ('A', 'B', 'C', 'D', 'E', 'F')) channels = ChannelList(dci, "TempSensorsTuple", DummyChannel, channel_tuple, snapshotable=False) chan_a = channels.ChanA with pytest.raises(AttributeError): channels.remove(chan_a)
def test_remove_tupled_channel(dci_with_list): channel_tuple = tuple( DummyChannel(dci_with_list, f"Chan{C}", C) for C in ("A", "B", "C", "D", "E", "F")) channels = ChannelList( dci_with_list, "TempSensorsTuple", DummyChannel, channel_tuple, snapshotable=False, ) chan_a = channels.ChanA with pytest.raises(AttributeError): channels.remove(chan_a)
def __init__(self, name, DACChannelClass: Type[DACChannelInterface]): assert issubclass(DACChannelClass, DACChannelInterface) super().__init__(name) channels = ChannelList(self, "Channels", DACChannelClass, snapshotable=False) for chan_id in range(0, 64): chan_name = f"nt channel {chan_id}" channel = DACChannelClass(self, chan_name, chan_id) channels.append(channel) self.add_submodule(chan_name, channel) self.add_submodule("nt_channels", channels)
def test_channel_tuple_snapshot_enabled(empty_instrument): channels = ChannelList(empty_instrument, "ListElem", DummyChannel, snapshotable=True) for chan_name in ("A", "B", "C", "D", "E", "F"): channel = DummyChannel(empty_instrument, f"Chan{chan_name}", chan_name) channels.append(channel) empty_instrument.add_submodule("channels", channels) snapshot = empty_instrument.channels.snapshot() assert snapshot["snapshotable"] is True assert len(snapshot.keys()) == 3 assert "channels" in snapshot.keys()
def test_channels_reverse(dci): names = ("A", "B", "C", "D", "E", "F", "G", "H") channels = tuple(DummyChannel(dci, name, name) for name in names) chlist = ChannelList(dci, "channels", DummyChannel, channels) reverse_names = reversed(names) for name, chan in zip(reverse_names, reversed(chlist)): assert chan.short_name == name
def _make_dci_with_list(): for i in range(10): pass dci = Instrument(name="dciwl") channels = ChannelList(dci, "ListElem", DummyChannel, snapshotable=False) for chan_name in ("A", "B", "C", "D", "E", "F"): channel = DummyChannel(dci, f"Chan{chan_name}", chan_name) channels.append(channel) dci.add_submodule(chan_name, channel) dci.add_submodule("channels", channels) try: yield dci finally: dci.close()
def test_channels_is_sequence(dci): names = ("A", "B", "C", "D", "E", "F", "G", "H") channels = tuple(DummyChannel(dci, name, name) for name in names) chlist = ChannelList(dci, "channels", DummyChannel, channels) assert isinstance(chlist, Sequence) assert issubclass(ChannelList, Sequence)
def test_invalid_channel_type_raises(empty_instrument): with pytest.raises( ValueError, match= "ChannelTuple can only hold instances of type InstrumentChannel", ): ChannelList(parent=empty_instrument, name="empty", chan_type=int)
def test_access_channels_by_tuple(dci, myindexs): names = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H') mytuple = tuple(myindexs) channels = tuple(DummyChannel(dci, 'Chan' + name, name) for name in names) chlist = ChannelList(dci, 'channels', DummyChannel, channels) mychans = chlist[mytuple] for chan, chanindex in zip(mychans, mytuple): assert chan.name == f'dci_Chan{names[chanindex]}'
def test_invalid_multichan_type_raises(empty_instrument): with pytest.raises(ValueError, match="multichan_paramclass must be a"): ChannelList( parent=empty_instrument, name="empty", chan_type=DummyChannel, multichan_paramclass=int, )
def __init__(self, name, channel_names=None, **kwargs): super().__init__(name, **kwargs) channels = ChannelList(self, "TempSensors", DummyChannel, snapshotable=False) if channel_names is None: channel_ids = ("A", "B", "C", "D", "E", "F") channel_names = tuple(f"Chan{chan_name}" for chan_name in channel_ids) else: channel_ids = channel_names for chan_name, chan_id in zip(channel_names, channel_ids): channel = DummyChannel(self, chan_name, chan_id) channels.append(channel) self.add_submodule(chan_id, channel) self.add_submodule("channels", channels.to_channel_tuple())
def test_access_channels_by_slice(dci, start, stop, step): names = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H') channels = tuple(DummyChannel(dci, 'Chan' + name, name) for name in names) chlist = ChannelList(dci, 'channels', DummyChannel, channels) if stop < start: step = -step myslice = slice(start, stop, step) mychans = chlist[myslice] expected_channels = names[myslice] for chan, exp_chan in zip(mychans, expected_channels): assert chan.name == f'dci_Chan{exp_chan}'
def __init__(self, name: str, address: str, port: int = 23): super().__init__(name, address, port) self.flush_connection() channels = ChannelList(self, "Channels", MC_channel, snapshotable=False) _chanlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] _max_channel_number = int(self.IDN()['model'][3]) _chanlist = _chanlist[0:_max_channel_number] for c in _chanlist: channel = MC_channel(self, f'channel_{c}', c) channels.append(channel) self.add_submodule(f"channel_{c}", channel) self.add_submodule("channels", channels.to_channel_tuple()) self.connect_message()
def test_wrong_chan_type_raises(empty_instrument): with pytest.raises(TypeError, match="All items in this ChannelTuple must be of"): ChannelList( parent=empty_instrument, name="empty", chan_type=DummyChannel, chan_list=[ EmptyChannel(parent=empty_instrument, name="empty_channel") ], )
def _init_readout_channels(self): # init submodules for ReadoutChannels channel_list = ChannelList(self, "channels", Channel) for i in range(10): channel_list.append(Channel(f"ch-{i}", i, self, self._controller)) channel_list.lock() self.add_submodule("channels", channel_list)
def _connect(self) -> None: """Connects the device to the data server. Instantiates the device controller from :mod:`zhinst-toolkit`, sets up the data server and connects the device the data server. This method is called from `__init__` of the :class:`BaseInstrument` class. """ self._controller = tk.HDAWG( self._name, self._serial, interface=self._interface, host=self._host, port=self._port, api=self._api, ) self._controller.setup() self._controller.connect_device(nodetree=False) self.connect_message() self._get_nodetree_dict() # initialize ChannelList of AWGs channel_list = ChannelList(self, "awgs", AWG) for i in range(4): channel_list.append(AWG(f"awg-{i}", i, self, self._controller)) channel_list.lock() self.add_submodule("awgs", channel_list)
def _init_awg_channels(self): # initialize ChannelList of AWGs channel_list = ChannelList(self, "awgs", AWG) for i in range(4): channel_list.append(AWG(f"awg-{i}", i, self, self._controller)) channel_list.lock() self.add_submodule("awgs", channel_list)
def add_channels(self) -> None: channels = ChannelList(self, "Channels", self.CHANNEL_CLASS, snapshotable=False) _chanlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] self._deprecated_attributes: Dict[str, str] = { f'channel_{k}': k for k in _chanlist } _max_channel_number = self.get_number_of_channels() _chanlist = _chanlist[0:_max_channel_number] for c in _chanlist: channel = self.CHANNEL_CLASS(self, f'channel_{c}', c) channels.append(channel) attribute_name = f'channel_{c}' self.add_submodule(attribute_name, channel) self.add_submodule(c, channel) self._deprecated_attributes[attribute_name] = c self.add_submodule("channels", channels.to_channel_tuple())
def test_add_channel_tuples_of_different_types_raises(dci): extra_channels = [EmptyChannel(dci, f"chan{i}") for i in range(10)] extra_channel_list = ChannelList( parent=dci, name="extra_channels", chan_type=EmptyChannel, chan_list=extra_channels, ) dci.add_submodule("extra_channels", extra_channel_list) with pytest.raises(TypeError, match="Both l and r arguments to add must contain"): _ = dci.channels + extra_channel_list
def _init_qachannels(self): # init submodules for QAChannels num_qachannels = self._controller.num_qachannels() channel_list = ChannelList(self, "qachannels", QAChannel) for i in range(num_qachannels): channel_list.append( QAChannel(f"qachannel-{i}", i, self, self._controller)) channel_list.lock() self.add_submodule("qachannels", channel_list)
def __init__(self, name: str, FPGA, channels: int = None, **kwargs): """ Constructor for the pulse generation modules """ super().__init__(name, **kwargs) self.fpga = FPGA if channels is None: channels = model_channels[self.fpga.model] self.n_channels = channels channels = ChannelList(self, name='channels', chan_type=PCDDSChannel) for ch in range(self.n_channels): channel = PCDDSChannel(self, name=f'ch{ch}', id=ch) setattr(self, f'ch{ch}', channel) channels.append(channel) self.add_submodule('channels', channels)
def _init_integrations(self): # init submodules for Integration Units num_integrations = self._readout.device.num_integrations_per_qachannel( ) channel_list = ChannelList(self, "integrations", Integration) for i in range(num_integrations): channel_list.append( Integration(f"integration-{i}", i, self, self._readout)) channel_list.lock() self.add_submodule("integrations", channel_list) self._readout._init_integrations()
def __init__(self, name, address, silent=False, **kwargs): """ Args: name (string): The name of the instrument used internally by QCoDeS. Must be unique. address (string): The VISA resource name. silent (Optional[bool]): If True, no connect message is printed. """ warnings.warn( "This driver is old and will be removed " "from QCoDeS soon. Please use the " "WaveformGenerator_33XXX from the file " "instrument_drivers/Keysight/KeysightAgilent_33XXX" " instead.", UserWarning) super().__init__(name, address, **kwargs) channels = ChannelList(self, "Channels", KeysightChannel, snapshotable=False) for i in range(1, 3): channel = KeysightChannel(self, 'ch{}'.format(i), i) channels.append(channel) channels.lock() self.add_submodule('channels', channels) self.add_parameter('sync_source', label='Source of sync function', set_cmd='OUTPut:SYNC:SOURce {}', get_cmd='OUTPut:SYNC:SOURce?', val_mapping={ 1: 'CH1', 2: 'CH2' }, vals=vals.Enum(1, 2)) self.add_parameter('sync_output', label='Sync output state', set_cmd='OUTPut:SYNC {}', get_cmd='OUTPut:SYNC?', val_mapping={ 'ON': 1, 'OFF': 0 }, vals=vals.Enum('ON', 'OFF')) self.add_function('force_trigger', call_cmd='*TRG') self.add_function('sync_channel_phases', call_cmd='PHAS:SYNC') if not silent: self.connect_message()
def _add_submodules_recursively(self, parent, treedict: Dict) -> None: """ Recursively add submodules (ZINodes) for each node in the ZI node tree. At the leaves create a parameter. Create a ChannelList as submodules whenever a node is enumerated, e.g. 'dev8030/sigouts/*/on'. Arguments: parent (InstrumentChannel): parent QCoDeS object, either Instrument(-Channel) or ZINode treedict (dict): dictionary specifying the (sub-)tree of the ZI node hirarchy """ for key, value in treedict.items(): if all(isinstance(k, int) for k in value.keys()): # if enumerated node if "Node" in list(value.values())[0].keys(): # if at leave, don't create ChannelList but parameter with "{key}{i}" for k in value.keys(): self._add_parameter_from_dict(parent, f"{key}{k}", value[k]) else: # else, create ChannelList to hold all enumerated ZINodes channel_list = ChannelList(parent, key, ZINode) for k in value.keys(): ch_name = f"{key}{k}" ch = ZINode(parent, ch_name) channel_list.append(ch) self._add_submodules_recursively(ch, treedict[key][k]) channel_list.lock() parent.add_submodule(key, channel_list) else: # if not enumerated ZINode if "Node" in value.keys(): # if at leave add a parameter to the node self._add_parameter_from_dict(parent, key, value) else: # if not at leave, create ZINode as submodule module = ZINode(parent, key) parent.add_submodule(key, module) self._add_submodules_recursively(module, treedict[key])
def __init__(self, name, address, port=23): super().__init__(name, address, port) self.flush_connection() channels = ChannelList(self, "Channels", MC_channel, snapshotable=False) _chanlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] _max_channel_number = int(self.IDN()['model'][3]) _chanlist = _chanlist[0:_max_channel_number] for c in _chanlist: channel = MC_channel(self, 'channel_{}'.format(c), c) channels.append(channel) self.add_submodule('channel_{}'.format(c), channel) channels.lock() self.add_submodule('channels', channels) self.connect_message()