예제 #1
0
    def test_multi_detector_basics(self):
        def dummy_function_1(val_a, val_b):
            return val_a

        def dummy_function_2(val_a, val_b):
            return val_a + val_b

        # Testing input of a simple dict
        x = self.mock_parabola.x
        d0 = det.Function_Detector(dummy_function_1,
                                   value_names=['a'],
                                   value_units=['my_unit'],
                                   msmt_kw={
                                       'val_a': x,
                                       'val_b': 1
                                   })
        d1 = det.Function_Detector(dummy_function_2,
                                   value_names=['b'],
                                   value_units=None,
                                   msmt_kw={
                                       'val_a': x,
                                       'val_b': 1
                                   })

        dm = det.Multi_Detector([d0, d1], det_idx_suffix=False)
        assert dm.value_names == ['a', 'b']
        assert dm.value_units == ['my_unit', 'a.u.']

        dm_suffix = det.Multi_Detector([d0, d1], det_idx_suffix=True)
        assert dm_suffix.value_names == ['a_det0', 'b_det1']
        assert dm_suffix.value_units == ['my_unit', 'a.u.']

        dh = det.Dummy_Detector_Hard()
        with pytest.raises(ValueError):
            dm = det.Multi_Detector([dh, d0])
예제 #2
0
    def test_multi_detector_soft(self):
        def dummy_function_1(val_a, val_b):
            return val_a, val_b

        def dummy_function_2(val_a, val_b):
            return val_a + val_b

        # Testing input of a simple dict
        x = self.mock_parabola.x
        d0 = det.Function_Detector(dummy_function_1, value_names=['a', 'b'],
                                   value_units=['my_unit', 'a.u.'],
                                   msmt_kw={'val_a': x, 'val_b': 1})
        d1 = det.Function_Detector(dummy_function_2, value_names=['b'],
                                   value_units=None,
                                   msmt_kw={'val_a': x, 'val_b': 1})

        dm = det.Multi_Detector([d0, d1], det_idx_prefix=False)
        assert dm.value_names == ['a', 'b', 'b']
        assert dm.value_units == ['my_unit', 'a.u.', 'a.u.']

        dm_suffix = det.Multi_Detector([d0, d1], det_idx_prefix=True)
        assert dm_suffix.value_names == ['det0 a', 'det0 b', 'det1 b']
        assert dm_suffix.value_units == ['my_unit', 'a.u.', 'a.u.']

        xvals = np.linspace(0, 10, 10)
        self.MC.set_sweep_function(self.mock_parabola.x)
        self.MC.set_sweep_points(xvals)
        self.MC.set_detector_function(dm)
        dat = self.MC.run("multi_detector")
        dset = dat["dset"]
        np.testing.assert_array_almost_equal(xvals, dset[:, 1])
        np.testing.assert_array_almost_equal(np.ones(len(xvals)), dset[:, 2])
        np.testing.assert_array_almost_equal(xvals+1, dset[:, 3])
    def test_variable_sized_return_values_hard_sweep_soft_avg(self):
        """
        Tests a detector that acquires data in chunks of varying sizes
        """
        self.MC.soft_avg(10)
        counter_param = ManualParameter('counter', initial_value=0)

        def return_variable_size_values():
            idx = counter_param() % 3
            counter_param(counter_param()+1)

            if idx == 0:
                return np.arange(0, 7)
            elif idx == 1:
                return np.arange(7, 11)
            elif idx == 2:
                return np.arange(11, 30)

        sweep_pts = np.arange(30)

        d = det.Function_Detector(get_function=return_variable_size_values,
                                  value_names=['Variable size counter'],
                                  detector_control='hard')
        self.MC.set_sweep_function(None_Sweep(sweep_control='hard'))
        self.MC.set_sweep_points(sweep_pts)
        self.MC.set_detector_function(d)
        dat = self.MC.run('varying_chunk_size')
        dset = dat["dset"]
        x = dset[:, 0]
        y = dset[:, 1]

        self.assertEqual(np.shape(dset), (len(sweep_pts), 2))
        np.testing.assert_array_almost_equal(x, sweep_pts)
        np.testing.assert_array_almost_equal(y, sweep_pts)
        self.assertEqual(self.MC.total_nr_acquired_values, 10*30)
    def test_soft_sweep_hard_det_1D(self):

        def mock_func():
            # to also test if the values are set correctly in the sweep
            arr = np.zeros([2, 2])
            arr[0, :] = np.array([self.mock_parabola.x()]*2)
            arr[1, :] = np.array([self.mock_parabola.x()+2]*2)
            return arr

        d = det.Function_Detector(get_function=mock_func,
                                  value_names=['x', 'x+2'],
                                  detector_control='hard')
        sweep_pts = np.repeat(np.arange(5), 2)
        self.MC.set_sweep_function(self.mock_parabola.x)
        self.MC.set_sweep_points(sweep_pts)
        self.MC.set_detector_function(d)
        dat = self.MC.run('soft_sweep_hard_det')
        dset = dat["dset"]

        x = dset[:, 0]
        y0 = dset[:, 1]
        y1 = dset[:, 2]
        np.testing.assert_array_almost_equal(x, sweep_pts)
        np.testing.assert_array_almost_equal(y0, sweep_pts)
        np.testing.assert_array_almost_equal(y1, sweep_pts+2)
예제 #5
0
    def test_function_detector_simple(self):

        def dummy_function(val_a, val_b):
            return val_a
        # Testing input of a simple dict
        d = det.Function_Detector(dummy_function, value_names=['a'],
                                  value_units=None,
                                  msmt_kw={'val_a': 5.5, 'val_b': 1})
        assert d.value_names == ['a']
        assert d.value_units == ['a.u.']

        self.MC.set_sweep_function(None_Sweep(sweep_control='soft'))
        self.MC.set_sweep_points(np.linspace(0, 10, 10))
        self.MC.set_detector_function(d)
        np.seterr()
        dat = self.MC.run()
예제 #6
0
    def test_function_detector_dict_single_key(self):
        def dummy_function(val_a, val_b):
            return {'a': val_a, 'b': val_b}
        # Testing input of a simple dict
        d = det.Function_Detector(dummy_function, value_names=['aa'],
                                  result_keys=['a'],
                                  value_units=['s'],
                                  msmt_kw={'val_a': 5.5, 'val_b': 1})

        xvals = np.linspace(0, 10, 10)
        self.MC.set_sweep_function(self.mock_parabola.x)
        self.MC.set_sweep_points(xvals)
        self.MC.set_detector_function(d)
        dat = self.MC.run()
        dset = dat["dset"]
        np.testing.assert_array_almost_equal(np.ones(10)*5.5, dset[:, 1])
        assert np.shape(dset) == (10, 2)
예제 #7
0
    def test_function_detector_parameter(self):

        def dummy_function(val_a, val_b):
            return val_a+val_b
        # Testing input of a simple dict

        x = self.mock_parabola.x
        d = det.Function_Detector(dummy_function, value_names=['xvals+1'],
                                  value_units=['s'],
                                  msmt_kw={'val_a': x, 'val_b': 1})
        assert d.value_names == ['xvals+1']
        assert d.value_units == ['s']

        xvals = np.linspace(0, 10, 10)
        self.MC.set_sweep_function(self.mock_parabola.x)
        self.MC.set_sweep_points(xvals)
        self.MC.set_detector_function(d)
        dat = self.MC.run()
        dset = dat["dset"]
        np.testing.assert_array_almost_equal(xvals+1, dset[:, 1])
예제 #8
0
    def test_function_detector_simple(self):
        def dummy_function(val_a, val_b):
            return val_a

        # Testing input of a simple dict
        d = det.Function_Detector(dummy_function,
                                  value_names=['a'],
                                  value_units=None,
                                  msmt_kw={
                                      'val_a': 5.5,
                                      'val_b': 1
                                  })
        self.assertEqual(d.value_names, ['a'])
        self.assertEqual(d.value_units, ['a.u.'])

        self.MC.set_sweep_function(None_Sweep(sweep_control='soft'))
        self.MC.set_sweep_points(np.linspace(0, 10, 10))
        self.MC.set_detector_function(d)
        dat = self.MC.run()
        dset = dat["dset"]
        np.testing.assert_array_almost_equal(np.ones(10) * 5.5, dset[:, 1])