def test_breakif(self): nan = float('nan') loop = Loop(self.p1[1:6:1]) data = loop.each(self.p1, BreakIf(self.p1 >= 3)).run_temp() self.assertEqual(repr(data.p1.tolist()), repr([1., 2., 3., nan, nan])) data = loop.each(BreakIf(self.p1.get_latest >= 3), self.p1).run_temp() self.assertEqual(repr(data.p1.tolist()), repr([1., 2., nan, nan, nan])) with self.assertRaises(TypeError): BreakIf(True) with self.assertRaises(TypeError): BreakIf(self.p1.set)
def test_basic(self): p1 = AbortingGetter('p1', count=2, vals=Numbers(-10, 10)) sv = p1[1:3:1] loop = Loop(sv) # not sure why you'd do it, but you *can* snapshot a Loop expected = { '__class__': 'qcodes.loops.Loop', 'sweep_values': sv.snapshot(), 'delay': 0, 'then_actions': [] } self.assertEqual(loop.snapshot(), expected) loop = loop.then(Task(p1.set, 0), Wait(0.123)) expected['then_actions'] = [{ 'type': 'Task', 'func': repr(p1.set) }, { 'type': 'Wait', 'delay': 0.123 }] # then test snapshot on an ActiveLoop breaker = BreakIf(p1.get_latest > 3) self.assertEqual(breaker.snapshot()['type'], 'BreakIf') # TODO: once we have reprs for DeferredOperations, test that # the right thing shows up in breaker.snapshot()['condition'] loop = loop.each(p1, breaker) expected['__class__'] = 'qcodes.loops.ActiveLoop' expected['actions'] = [p1.snapshot(), breaker.snapshot()] self.assertEqual(loop.snapshot(), expected)
def test_basic(self): p1 = AbortingGetter('p1', count=2, vals=Numbers(-10, 10), set_cmd=None) sv = p1[1:3:1] loop = Loop(sv) # not sure why you'd do it, but you *can* snapshot a Loop expected = { '__class__': 'qcodes.loops.Loop', 'sweep_values': sv.snapshot(), 'delay': 0, 'then_actions': [] } self.assertEqual(loop.snapshot(), expected) loop = loop.then(Task(p1.set, 0), Wait(0.123)) expected['then_actions'] = [{ 'type': 'Task', 'func': repr(p1.set) }, { 'type': 'Wait', 'delay': 0.123 }] # then test snapshot on an ActiveLoop breaker = BreakIf(lambda: p1.get_latest() > 3) self.assertEqual(breaker.snapshot()['type'], 'BreakIf') loop = loop.each(p1, breaker) expected['__class__'] = 'qcodes.loops.ActiveLoop' expected['actions'] = [p1.snapshot(), breaker.snapshot()] self.assertEqual(loop.snapshot(), expected)
def test_loop_arrayparameter_by_index(dci): loc_fmt = 'data/{date}/#{counter}_{name}_{date}_{time}' rcd = {'name': 'arrayParamByIndex'} loc_provider = FormatLocation(fmt=loc_fmt, record=rcd) loop = Loop(dci.channels[0].temperature.sweep(0, 10, 1), 0.1) data = loop.each(dci.A.dummy_array_parameter)\ .run(location=loc_provider) _verify_array_data(data)
def test_loop_slicing_arrayparameter(dci): loc_fmt = 'data/{date}/#{counter}_{name}_{date}_{time}' rcd = {'name': 'loopSlicing'} loc_provider = FormatLocation(fmt=loc_fmt, record=rcd) loop = Loop(dci.A.temperature.sweep(0, 10, 1), 0.1) data = loop.each(dci.channels[0:2].dummy_array_parameter)\ .run(location=loc_provider) _verify_array_data(data, channels=('A', 'B'))
def test_loop_arrayparameter_by_name(self): loc_fmt = 'data/{date}/#{counter}_{name}_{date}_{time}' rcd = {'name': 'arrayParamByName'} loc_provider = FormatLocation(fmt=loc_fmt, record=rcd) loop = Loop(self.instrument.A.temperature.sweep(0, 10, 1), 0.1) data = loop.each(self.instrument.A.dummy_array_parameter)\ .run(location=loc_provider) self._verify_array_data(data)
def test_loop_multiparameter_by_name(dci): loc_fmt = 'data/{date}/#{counter}_{name}_{date}_{time}' rcd = {'name': 'multiParamByName'} loc_provider = FormatLocation(fmt=loc_fmt, record=rcd) loop = Loop(dci.A.temperature.sweep(0, 10, 1), 0.1) data = loop.each(dci.A.dummy_multi_parameter)\ .run(location=loc_provider) _verify_multiparam_data(data) assert 'multi_setpoint_param_this_setpoint_set' in data.arrays.keys()
def test_loop_multiparameter_by_index(self): loc_fmt = 'data/{date}/#{counter}_{name}_{date}_{time}' rcd = {'name': 'loopByIndex'} loc_provider = FormatLocation(fmt=loc_fmt, record=rcd) loop = Loop(self.instrument.channels[0].temperature.sweep(0, 10, 1), 0.1) data = loop.each(self.instrument.A.dummy_multi_parameter)\ .run(location=loc_provider) self._verify_multiparam_data(data)
def test_nesting(self): loop = Loop(self.p1[1:3:1], 0.001).loop(self.p2[3:5:1], 0.001).loop(self.p3[5:7:1], 0.001) active_loop = loop.each(self.p1, self.p2, self.p3) data = active_loop.run_temp() self.assertEqual(data.p1_set.tolist(), [1, 2]) self.assertEqual(data.p2_set.tolist(), [[3, 4]] * 2) self.assertEqual(data.p3_set.tolist(), [[[5, 6]] * 2] * 2) self.assertEqual(data.p1.tolist(), [[[1, 1]] * 2, [[2, 2]] * 2]) self.assertEqual(data.p2.tolist(), [[[3, 3], [4, 4]]] * 2) self.assertEqual(data.p3.tolist(), [[[5, 6]] * 2] * 2)
def qc_run(name, seq, *params): loop = None for sp in seq.params: if loop is None: loop = Loop(sp[sp.values]) else: loop = loop.loop((sp[sp.values])) play_task = Task(upload_play, seq) if loop is not None: m = loop.each(play_task, *params) else: m = Measure(play_task, *params) ds = m.run(loc_record={'name':name}) return ds
def test_nested_loop_over_channels(self, loop_channels, measure_channel): channel_to_label = {0: 'A', 1: 'B', 2: 'C', 3: "D"} loc_fmt = 'data/{date}/#{counter}_{name}_{date}_{time}' rcd = {'name': 'nestedLoopOverChannels'} loc_provider = FormatLocation(fmt=loc_fmt, record=rcd) loop = Loop( self.instrument.channels[loop_channels[0]].temperature.sweep( 0, 10, 0.5)) loop = loop.loop( self.instrument.channels[loop_channels[1]].temperature.sweep( 50, 51, 0.1)) loop = loop.each(self.instrument.channels[measure_channel].temperature) data = loop.run(location=loc_provider) self.assertEqual( getattr( data, 'testchanneldummy_Chan{}_temperature_set'.format( channel_to_label[loop_channels[0]])).ndarray.shape, (21, )) self.assertEqual( getattr( data, 'testchanneldummy_Chan{}_temperature_set'.format( channel_to_label[loop_channels[1]])).ndarray.shape, ( 21, 11, )) self.assertEqual( getattr( data, 'testchanneldummy_Chan{}_temperature'.format( channel_to_label[measure_channel])).ndarray.shape, (21, 11)) assert_array_equal( getattr( data, 'testchanneldummy_Chan{}_temperature_set'.format( channel_to_label[loop_channels[0]])).ndarray, np.arange(0, 10.1, 0.5)) expected_array = np.repeat(np.arange(50, 51.01, 0.1).reshape(1, 11), 21, axis=0) array = getattr( data, 'testchanneldummy_Chan' '{}_temperature_set'.format( channel_to_label[loop_channels[1]])).ndarray assert_allclose(array, expected_array)
def test_nested_loop_over_channels(self, loop_channels, measure_channel): channel_to_label = {0: 'A', 1: 'B', 2: 'C', 3: "D"} loop = Loop( self.instrument.channels[loop_channels[0]].temperature.sweep( 0, 10, 0.5)) loop = loop.loop( self.instrument.channels[loop_channels[1]].temperature.sweep( 50, 51, 0.1)) loop = loop.each(self.instrument.channels[measure_channel].temperature) data = loop.run() self.assertEqual( getattr( data, 'testchanneldummy_Chan{}_temperature_set'.format( channel_to_label[loop_channels[0]])).ndarray.shape, (21, )) self.assertEqual( getattr( data, 'testchanneldummy_Chan{}_temperature_set'.format( channel_to_label[loop_channels[1]])).ndarray.shape, ( 21, 11, )) self.assertEqual( getattr( data, 'testchanneldummy_Chan{}_temperature'.format( channel_to_label[measure_channel])).ndarray.shape, (21, 11)) assert_array_equal( getattr( data, 'testchanneldummy_Chan{}_temperature_set'.format( channel_to_label[loop_channels[0]])).ndarray, np.arange(0, 10.1, 0.5)) expected_array = np.repeat(np.arange(50, 51.01, 0.1).reshape(1, 11), 21, axis=0) array = getattr( data, 'testchanneldummy_Chan' '{}_temperature_set'.format( channel_to_label[loop_channels[1]])).ndarray assert_allclose(array, expected_array)
def test_loop_multiparameter_by_name(self): loop = Loop(self.instrument.A.temperature.sweep(0, 10, 1), 0.1) data = loop.each(self.instrument.A.dummy_multi_parameter).run() self._verify_multiparam_data(data) self.assertIn('this_setpoint_set', data.arrays.keys())
def test_loop_slicing_multiparameter_raises(self): with self.assertRaises(NotImplementedError): loop = Loop(self.instrument.A.temperature.sweep(0, 10, 1), 0.1) loop.each( self.instrument.channels[0:2].dummy_multi_parameter).run()
def test_loop_slicing_arrayparameter(self): loop = Loop(self.instrument.A.temperature.sweep(0, 10, 1), 0.1) data = loop.each( self.instrument.channels[0:2].dummy_array_parameter).run() self._verify_array_data(data, channels=('A', 'B'))
def test_loop_arrayparameter_by_index(self): loop = Loop(self.instrument.channels[0].temperature.sweep(0, 10, 1), 0.1) data = loop.each(self.instrument.A.dummy_array_parameter).run() self._verify_array_data(data)
def test_loop_slicing_multiparameter_raises(dci): with pytest.raises(NotImplementedError): loop = Loop(dci.A.temperature.sweep(0, 10, 1), 0.1) loop.each(dci.channels[0:2].dummy_multi_parameter).run()