def setUp(self): gate_map = { 'T': (0, 15), 'P1': (0, 3), 'P2': (0, 4), 'L': (0, 5), 'D1': (0, 6), 'R': (0, 7)} self.ivvi = VirtualIVVI(instrumentName('ivvi'), model=None) self.gates = VirtualDAC(instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map)
class TestVirtualDAC(TestCase): def setUp(self): gate_map = { 'T': (0, 15), 'P1': (0, 3), 'P2': (0, 4), 'L': (0, 5), 'D1': (0, 6), 'R': (0, 7)} self.ivvi = VirtualIVVI(qtt.measurements.scans.instrumentName('ivvi'), model=None) self.gates = VirtualDAC(qtt.measurements.scans.instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map) def tearDown(self): self.gates.close() self.ivvi.close() def test_gates_get_set(self): expected_value = 100. self.gates.R.set(expected_value) self.assertEqual(self.gates.R.get(), expected_value) def test_named_instruments(self): gate_map = {'P1': (0, 1), 'P2': (0, 2), 'P1named': (self.ivvi.name, 1)} gates = VirtualDAC(qtt.measurements.scans.instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map) expected_value = 20. gates.P1.set(expected_value) self.assertEqual(gates.P1named.get(), expected_value) gates.close()
class VirtualDACInstrumentAdapter(InstrumentAdapter): """ Adapter for the qtt VirtualDAC.""" def __init__(self, address: str, instrument_name: Optional[str] = None) -> None: super().__init__(address, instrument_name) self._instrument = VirtualDAC(self._instrument_name, instruments=[], gate_map={}) self._dac_adapters: Dict[str, VirtualDAC] = {} def _filter_parameters(self, parameters: PythonJsonStructure) -> PythonJsonStructure: return parameters def read(self, update: bool = False) -> PythonJsonStructure: """ Additionally reads the gate_map, boundaries and configs of the nested dacs.""" config = PythonJsonStructure() config[CONFIG] = super().read(update) config[BOUNDARIES] = self._instrument.get_boundaries() config[GATE_MAP] = self._instrument.gate_map config[INSTRUMENTS] = PythonJsonStructure() for adapter_name, adapter in self._dac_adapters.items(): config[INSTRUMENTS][adapter_name] = PythonJsonStructure() config[INSTRUMENTS][adapter_name][CONFIG] = adapter.read(update) config[INSTRUMENTS][adapter_name][ADDRESS] = adapter.address config[INSTRUMENTS][adapter_name][ADAPTER_CLASS_NAME] = adapter.__class__.__name__ return config def apply(self, config: PythonJsonStructure) -> None: """ Apply config to the virtual dac and all nested dacs.""" self._instrument.instruments = [] self._dac_adapters = {} instruments = config[INSTRUMENTS] for instrument in instruments: adapter_class_name = instruments[instrument][ADAPTER_CLASS_NAME] address = instruments[instrument][ADDRESS] adapter_config = instruments[instrument][CONFIG] self.add_adapter_to_instrument_adapter(adapter_class_name, address) self._dac_adapters[instrument].apply(adapter_config) self._instrument.set_boundaries(config[BOUNDARIES]) self._instrument.gate_map = config[GATE_MAP] super().apply(config[CONFIG]) def add_adapter_to_instrument_adapter(self, instrument_adapter_class_name: str, address: str, instrument_name: Optional[str] = None) -> None: """ Adds a DAC to the virtual DAC and cache a corresponding instrument adapter. Args: instrument_adapter_class_name: Name of the InstrumentAdapter subclass. address: Address of the physical instrument. instrument_name: An optional name for the underlying instrument. """ adapter = InstrumentAdapterFactory.get_instrument_adapter(instrument_adapter_class_name, address, instrument_name) if adapter.name not in self._dac_adapters: self._dac_adapters[adapter.name] = adapter if adapter.instrument not in self.instrument.instruments: self.instrument.add_instruments([adapter.instrument])
def test_named_instruments(self): gate_map = {'P1': (0, 1), 'P2': (0, 2), 'P1named': (self.ivvi.name, 1)} gates = VirtualDAC(qtt.measurements.scans.instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map) expected_value = 20. gates.P1.set(expected_value) self.assertEqual(gates.P1named.get(), expected_value) gates.close()
def test_restrict_boundaries(self): gate_map = {'P1': (0, 1), 'P2': (0, 2), 'P3': (0, 3)} virtual_dac = VirtualDAC(instrumentName('test'), instruments=[self.ivvi], gate_map=gate_map) gate_boundaries = {'P1': (0, 100), 'P2': (0, 100)} virtual_dac.set_boundaries(gate_boundaries) virtual_dac.restrict_boundaries({'P1': (-50, 50), 'P3': (0, 1)}) self.assertEqual(virtual_dac.get_boundaries(), {'P1': (0, 50), 'P2': (0, 100), 'P3': (0, 1)}) self.assertEqual(self.ivvi.dac1.vals.valid_values, (0, 50)) virtual_dac.close()
def test_set_gate_map(self): gate_map = {'P1': (0, 1), 'P2': (0, 2), 'P3': (0, 3)} virtual_dac = VirtualDAC(instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map) self.assertDictEqual(gate_map, virtual_dac.gate_map) self.assertTrue(hasattr(virtual_dac, 'P1')) self.assertTrue(hasattr(virtual_dac, 'P2')) self.assertTrue(hasattr(virtual_dac, 'P3')) new_gate_map = {'C1': (0, 11), 'C2': (0, 12), 'C3': (0, 13)} virtual_dac.gate_map = new_gate_map self.assertFalse(hasattr(virtual_dac, 'P1')) self.assertFalse(hasattr(virtual_dac, 'P2')) self.assertFalse(hasattr(virtual_dac, 'P3')) self.assertTrue(hasattr(virtual_dac, 'C1')) self.assertTrue(hasattr(virtual_dac, 'C2')) self.assertTrue(hasattr(virtual_dac, 'C3')) self.assertDictEqual(new_gate_map, virtual_dac.gate_map) virtual_dac.close()
def test_get_boundaries(self): gate_map = {'P1': (0, 1), 'P2': (0, 2), 'P3': (0, 3)} virtual_dac = VirtualDAC(instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map) gate_boundaries = {'P1': (0, 1), 'P2': (-42, 42), 'P3': (-100, 100)} virtual_dac.set_boundaries(gate_boundaries) boundaries = virtual_dac.get_boundaries() self.assertDictEqual(gate_boundaries, boundaries) virtual_dac.close()
def test_set_dacs(self): virtual_dac = VirtualDAC(instrumentName('gates'), instruments=[], gate_map={}) virtual_dac.add_instruments([self.ivvi]) self.assertIs(self.ivvi, virtual_dac.instruments[0]) virtual_dac.close()
def test_add_instruments(self): ivvi1 = VirtualIVVI(instrumentName('ivvi'), model=None) ivvi2 = VirtualIVVI(instrumentName('ivv2'), model=None) instruments = [ivvi1, ivvi2] virtual_dac = VirtualDAC(instrumentName('gates'), instruments=[], gate_map={}) virtual_dac.add_instruments(instruments) self.assertEqual(2, len(virtual_dac.instruments)) self.assertEqual(instruments, virtual_dac.instruments) virtual_dac.add_instruments(instruments) self.assertEqual(2, len(virtual_dac.instruments)) self.assertEqual(instruments, virtual_dac.instruments) virtual_dac.close() ivvi1.close() ivvi2.close()
def initialize(reinit=False, nr_dots=2, maxelectrons=2, verbose=2, start_manager=False): global station, _initialized, model logger.info('virtualDot: start') if verbose >= 2: print('initialize: create virtual dot system') if _initialized: if reinit: close(verbose=verbose) else: return station logger.info('virtualDot: make DotModel') model = DotModel(name=qtt.measurements.scans.instrumentName('dotmodel'), verbose=verbose >= 3, nr_dots=nr_dots, maxelectrons=maxelectrons, sdplunger='SD1b') gate_map = model.gate_map if verbose >= 2: logger.info('initialize: DotModel created') ivvis = [] for ii in range(model.nr_ivvi): ivvis.append(VirtualIVVI(name='ivvi%d' % (ii + 1), model=model)) gates = VirtualDAC(name='gates', gate_map=gate_map, instruments=ivvis) gates.set_boundaries(gate_boundaries(gate_map)) logger.info('initialize: set values on gates') gates.set('D0', 101) for g in model.gates: gates.set(g, np.random.rand() - .5) # take into account the voltage divider on the ohmics for g in gates.parameters.keys(): if g.startswith('O'): gg = getattr(gates, g) gg.unit = 'uV' vawg = SimulationAWG(qtt.measurements.scans.instrumentName('vawg')) logger.info('initialize: create virtual keithley instruments') keithley1 = VirtualMeter('keithley1', model=model) keithley3 = VirtualMeter('keithley3', model=model) keithley4 = VirtualMeter('keithley4', model=model) digitizer = SimulationDigitizer(qtt.measurements.scans.instrumentName('sdigitizer'), model=model) logger.info('initialize: create station') station = qcodes.Station(gates, keithley1, keithley3, keithley4, *ivvis, vawg, digitizer, model, update_snapshot=False) station.awg = station.vawg station.metadata['sample'] = 'virtual_dot' station.model = model station.gate_settle = gate_settle station.depletiongate_name = 'D0' station.bottomchannel_current = station.keithley3.amplitude station.jobmanager = None station.calib_master = None _initialized = True if verbose: print('initialized virtual dot system (%d dots)' % nr_dots) return station
class TestVirtualDAC(TestCase): def setUp(self): gate_map = { 'T': (0, 15), 'P1': (0, 3), 'P2': (0, 4), 'L': (0, 5), 'D1': (0, 6), 'R': (0, 7) } self.ivvi = VirtualIVVI(instrumentName('ivvi'), model=None) self.gates = VirtualDAC(instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map) def tearDown(self): self.gates.close() self.ivvi.close() def test_gates_get_set(self): expected_value = 100. self.gates.R.set(expected_value) self.assertEqual(self.gates.R.get(), expected_value) def test_named_instruments(self): gate_map = {'P1': (0, 1), 'P2': (0, 2), 'P1named': (self.ivvi.name, 1)} gates = VirtualDAC(instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map) expected_value = 20. gates.P1.set(expected_value) self.assertEqual(gates.P1named.get(), expected_value) gates.close() def test_set_gate_map(self): gate_map = {'P1': (0, 1), 'P2': (0, 2), 'P3': (0, 3)} virtual_dac = VirtualDAC(instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map) self.assertDictEqual(gate_map, virtual_dac.gate_map) self.assertTrue(hasattr(virtual_dac, 'P1')) self.assertTrue(hasattr(virtual_dac, 'P2')) self.assertTrue(hasattr(virtual_dac, 'P3')) new_gate_map = {'C1': (0, 11), 'C2': (0, 12), 'C3': (0, 13)} virtual_dac.gate_map = new_gate_map self.assertFalse(hasattr(virtual_dac, 'P1')) self.assertFalse(hasattr(virtual_dac, 'P2')) self.assertFalse(hasattr(virtual_dac, 'P3')) self.assertTrue(hasattr(virtual_dac, 'C1')) self.assertTrue(hasattr(virtual_dac, 'C2')) self.assertTrue(hasattr(virtual_dac, 'C3')) self.assertDictEqual(new_gate_map, virtual_dac.gate_map) virtual_dac.close() def test_get_boundaries(self): gate_map = {'P1': (0, 1), 'P2': (0, 2), 'P3': (0, 3)} virtual_dac = VirtualDAC(instrumentName('gates'), instruments=[self.ivvi], gate_map=gate_map) gate_boundaries = {'P1': (0, 1), 'P2': (-42, 42), 'P3': (-100, 100)} virtual_dac.set_boundaries(gate_boundaries) boundaries = virtual_dac.get_boundaries() self.assertDictEqual(gate_boundaries, boundaries) virtual_dac.close() def test_restrict_boundaries(self): gate_map = {'P1': (0, 1), 'P2': (0, 2), 'P3': (0, 3)} virtual_dac = VirtualDAC(instrumentName('test'), instruments=[self.ivvi], gate_map=gate_map) gate_boundaries = {'P1': (0, 100), 'P2': (0, 100)} virtual_dac.set_boundaries(gate_boundaries) virtual_dac.restrict_boundaries({'P1': (-50, 50), 'P3': (0, 1)}) self.assertEqual(virtual_dac.get_boundaries(), { 'P1': (0, 50), 'P2': (0, 100), 'P3': (0, 1) }) self.assertEqual(self.ivvi.dac1.vals.valid_values, (0, 50)) virtual_dac.close() def test_invalid_boundary(self): with self.assertRaises(ValueError): self.gates.set_boundaries({'P1': [2, 1]}) def test_invalid_gate(self): with self.assertWarnsRegex(UserWarning, 'has no gate'): self.gates.set_boundaries({'no_gate': [0, 1]}) def test_set_dacs(self): virtual_dac = VirtualDAC(instrumentName('gates'), instruments=[], gate_map={}) virtual_dac.add_instruments([self.ivvi]) self.assertIs(self.ivvi, virtual_dac.instruments[0]) virtual_dac.close() def test_add_instruments(self): ivvi1 = VirtualIVVI(instrumentName('ivvi'), model=None) ivvi2 = VirtualIVVI(instrumentName('ivv2'), model=None) instruments = [ivvi1, ivvi2] virtual_dac = VirtualDAC(instrumentName('gates'), instruments=[], gate_map={}) virtual_dac.add_instruments(instruments) self.assertEqual(2, len(virtual_dac.instruments)) self.assertEqual(instruments, virtual_dac.instruments) virtual_dac.add_instruments(instruments) self.assertEqual(2, len(virtual_dac.instruments)) self.assertEqual(instruments, virtual_dac.instruments) virtual_dac.close() ivvi1.close() ivvi2.close() def test_restore_at_exit(self): gates = self.gates starting_value = self.gates.P1() with self.gates.restore_at_exit(): gates.P1.increment(10) self.assertEqual(gates.P1(), starting_value) def test_restore_at_exit_with_exception(self): gates = self.gates starting_value = self.gates.P1() with self.assertRaises(AttributeError): with gates.restore_at_exit(): gates.P1.increment(10) gates.non_existing_gate.increment(10) self.assertEqual(gates.P1(), starting_value)
for ii in range(digitizer_data.shape[0]): plt.plot(digitizer_data[ii,:],'.', label='%d' % ii) plt.show() plt.legend() plot_data_1d_x(data, 'Digitizer Data Points [a.u.]', 'Amplitude [V]') #%% from qtt.instrument_drivers.gates import VirtualDAC from qtt.instrument_drivers.virtual_instruments import VirtualIVVI from qcodes.station import Station ivvi = VirtualIVVI(name='ivvi', model=None) gates = VirtualDAC('gates', [ivvi], {'C1': (0, 1), 'C2': (0, 2)}) station = Station(ivvi, gates, virtual_awg, awg_1, digitizer) #%% from qtt.measurements.scans import scan1Dfast, scanjob_t scanjob = scanjob_t({'minstrument': [1],'Naverage':100,'wait_time_start_scan':2, 'sweepdata': {'param': 'C2','start': 100,'end': 250, 'step': 1,'wait_time': 0.28}}) dataset_measurement_fast = scan1Dfast(station, scanjob) logviewer = DataViewer() logviewer.show()
def __init__(self, address: str, instrument_name: Optional[str] = None) -> None: super().__init__(address, instrument_name) self._instrument = VirtualDAC(self._instrument_name, instruments=[], gate_map={}) self._dac_adapters: Dict[str, VirtualDAC] = {}