def test_old_loop_1D_2D(self): self.p_sweep2 = Parameter("p_sweep2", set_cmd=None) loop = Loop(self.p_sweep.sweep(0, 5, 1)).each( self.p_measure, Loop(self.p_sweep2.sweep(0, 5, 1)).each(self.p_measure) ) loop.run(name="old_loop_1D_2D", thread=False)
def testLoopCombinedParameterTwice(self, npoints, x_start_stop, y_start_stop, z_start_stop): x_set = np.linspace(x_start_stop[0], x_start_stop[1], npoints) y_set = np.linspace(y_start_stop[0], y_start_stop[1], npoints) z_set = np.linspace(z_start_stop[0], z_start_stop[1], npoints) setpoints = np.hstack((x_set.reshape(npoints, 1), y_set.reshape(npoints, 1), z_set.reshape(npoints, 1))) parameters = [Parameter(name, get_cmd=None, set_cmd=None) for name in ["X", "Y", "Z"]] sweep_values = combine(*parameters, name="combined").sweep(setpoints) def wrapper(): counter = 0 def inner(): nonlocal counter counter += 1 return counter return inner self.dmm.voltage.get = wrapper() loop = Loop(sweep_values).each(self.dmm.voltage, self.dmm.voltage) data = loop.run(quiet=True) np.testing.assert_array_equal(data.arrays['X'].ndarray, x_set) np.testing.assert_array_equal(data.arrays['Y'].ndarray, y_set) np.testing.assert_array_equal(data.arrays['Z'].ndarray, z_set) np.testing.assert_array_equal(data.arrays['dmm_voltage_0'].ndarray, np.arange(1, npoints*2, 2)) np.testing.assert_array_equal(data.arrays['dmm_voltage_1'].ndarray, np.arange(2, npoints*2+1, 2))
def testLoopCombinedParameterPrintTask(self, npoints, x_start_stop, y_start_stop, z_start_stop): x_set = np.linspace(x_start_stop[0], x_start_stop[1], npoints) y_set = np.linspace(y_start_stop[0], y_start_stop[1], npoints) z_set = np.linspace(z_start_stop[0], z_start_stop[1], npoints) setpoints = np.hstack((x_set.reshape(npoints, 1), y_set.reshape(npoints, 1), z_set.reshape(npoints, 1))) parameters = [Parameter(name, get_cmd=None, set_cmd=None) for name in ["X", "Y", "Z"]] sweep_values = combine(*parameters, name="combined").sweep(setpoints) def ataskfunc(): a = 1+1 def btaskfunc(): b = 1+2 atask = Task(ataskfunc) btask = Task(btaskfunc) loop = Loop(sweep_values).each(atask, btask) data = loop.run(quiet=True) np.testing.assert_array_equal(data.arrays['X'].ndarray, x_set) np.testing.assert_array_equal(data.arrays['Y'].ndarray, y_set) np.testing.assert_array_equal(data.arrays['Z'].ndarray, z_set)
def testLoopCombinedParameterInside(self, npoints, npoints_outer, x_start_stop, y_start_stop, z_start_stop): x_set = np.linspace(x_start_stop[0], x_start_stop[1], npoints_outer) y_set = np.linspace(y_start_stop[0], y_start_stop[1], npoints) z_set = np.linspace(z_start_stop[0], z_start_stop[1], npoints) setpoints = np.hstack((y_set.reshape(npoints, 1), z_set.reshape(npoints, 1))) parameters = [ManualParameter(name) for name in ["X", "Y", "Z"]] sweep_values = combine(parameters[1], parameters[2], name="combined").sweep(setpoints) def ataskfunc(): a = 1 + 1 def btaskfunc(): b = 1 + 2 atask = Task(ataskfunc) btask = Task(btaskfunc) def wrapper(): counter = 0 def inner(): nonlocal counter counter += 1 return counter return inner self.dmm.voltage.get = wrapper() loop = Loop( parameters[0].sweep(x_start_stop[0], x_start_stop[1], num=npoints_outer)).loop(sweep_values).each( self.dmm.voltage, atask, self.dmm.somethingelse, self.dmm.voltage, btask) data = loop.run(quiet=True) np.testing.assert_array_equal(data.arrays['X_set'].ndarray, x_set) np.testing.assert_array_equal( data.arrays['Y'].ndarray, np.repeat(y_set.reshape(1, npoints), npoints_outer, axis=0)) np.testing.assert_array_equal( data.arrays['Z'].ndarray, np.repeat(z_set.reshape(1, npoints), npoints_outer, axis=0)) np.testing.assert_array_equal( data.arrays['dmm_voltage_0'].ndarray, np.arange(1, npoints * npoints_outer * 2, 2).reshape(npoints_outer, npoints)) np.testing.assert_array_equal( data.arrays['dmm_voltage_3'].ndarray, np.arange(2, npoints * npoints_outer * 2 + 1, 2).reshape(npoints_outer, npoints)) np.testing.assert_array_equal(data.arrays['dmm_somethingelse'].ndarray, np.ones((npoints_outer, npoints)))
def test_old_loop_1D(self): loop = Loop(self.p_sweep.sweep(0, 10, 1)).each(self.p_measure, self.p_measure) data = loop.run(name="old_loop_1D", thread=False) self.assertEqual(data.metadata.get("measurement_type"), "Loop") # Verify that the measurement dataset records the correct measurement type loaded_data = load_data(data.location) self.assertEqual(loaded_data.metadata.get("measurement_type"), "Loop")
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, )