예제 #1
0
    def test_set_field_rabi_t_func_1(self):
        """ Test that a custom double pulse Rabi freq time functions can be
            set.
        """

        ob_solve_02 = ob_solve.OBSolve().from_json_str(JSON_STR_02)

        two_pulse_t_func = lambda t, args: (t_funcs.gaussian(0)
                                            (t, args) + t_funcs.gaussian(1)
                                            (t, args))

        two_pulse_t_args = {
            "ampl_0": 1.0,
            "centre_0": 0.0,
            "fwhm_0": 0.1,
            "ampl_1": 2.0,
            "centre_1": 0.5,
            "fwhm_1": 0.1,
        }

        ob_solve_02.set_field_rabi_freq_t_func(0, two_pulse_t_func)
        ob_solve_02.set_field_rabi_freq_t_args(0, two_pulse_t_args)

        field_0 = ob_solve_02.atom.fields[0]

        self.assertAlmostEqual(
            field_0.rabi_freq_t_func(0.0, field_0.rabi_freq_t_args), 1.0)
        self.assertAlmostEqual(
            field_0.rabi_freq_t_func(0.5, field_0.rabi_freq_t_args), 2.0)
        self.assertAlmostEqual(
            field_0.rabi_freq_t_func(1.0, field_0.rabi_freq_t_args), 0.0)
예제 #2
0
 def test_ampl_and_n_pi(self):
     """Test that KeyError is raised if both ampl and n_pi args set.
     """
     tlist = np.linspace(0., 1., 201)
     t_args = {'n_pi_1': 2.0, 'ampl_1': 1.0, 'fwhm_1': 0.1, 'centre_1': 0.5}
     t_func = t_funcs.gaussian(1)
     with self.assertRaises(KeyError):
         t_func(tlist, t_args)
예제 #3
0
 def test_gaussian(self):
     """ Tests a Gaussian pulse for the correct FWHM. """
     t_list = tlist = np.linspace(0., 1., 101)
     y_list = t_funcs.gaussian(1)(tlist,
                                  args={
                                      'ampl_1': 1.0,
                                      'fwhm_1': 0.1,
                                      'centre_1': 0.5
                                  })
     self.assertAlmostEqual(utility.full_width_at_half_max(t_list, y_list),
                            0.1)
예제 #4
0
 def test_areas_pi_n_pi(self):
     """Test Gaussian areas as multiples of pi given n_pi arg.
     """
     FWHM = 0.1
     tlist = np.linspace(0., 1., 201)
     t_func = t_funcs.gaussian(1)
     for n_pi in np.linspace(1.0, 10.0, 10):
         t_args = {'n_pi_1': n_pi, 'fwhm_1': FWHM, 'centre_1': 0.5}
         area = np.trapz(t_func(tlist, t_args), tlist) * 2 * np.pi
         fwhm_test = utility.full_width_at_half_max(tlist,
                                                    t_func(tlist, t_args))
         self.assertAlmostEqual(area, n_pi * np.pi, places=3)
         self.assertAlmostEqual(fwhm_test, FWHM)
예제 #5
0
 def test_gaussian(self):
     """ Tests a Gaussian pulse for the correct half max and width. """
     t_list = tlist = np.linspace(0., 1., 101)
     y_list = t_funcs.gaussian(1)(tlist,
                                  args={
                                      'ampl_1': 1.0,
                                      'fwhm_1': 0.1,
                                      'centre_1': 0.5
                                  })
     half_max, r1, r2 = utility.half_max_roots(t_list, y_list)
     self.assertAlmostEqual(half_max, 0.5)
     self.assertAlmostEqual(r1, 0.45)
     self.assertAlmostEqual(r2, 0.55)
예제 #6
0
 def test_areas_pi(self):
     """Test Gaussian areas as multiples of pi.
     """
     FWHM = 0.1
     tlist = np.linspace(0., 1., 201)
     t_func = t_funcs.gaussian(1)
     for n in np.linspace(1.0, 10.0, 10):
         ampl = n * np.sqrt(4. * np.pi * np.log(2) / FWHM**2) / (
             2 * np.pi)  # nπ area
         t_args = {'ampl_1': ampl, 'fwhm_1': FWHM, 'centre_1': 0.5}
         area = np.trapz(t_func(tlist, t_args), tlist) * 2 * np.pi
         fwhm_test = utility.full_width_at_half_max(tlist,
                                                    t_func(tlist, t_args))
         self.assertAlmostEqual(area, n * np.pi, places=3)
         self.assertAlmostEqual(fwhm_test, FWHM)
예제 #7
0
 def test_no_ampl_nor_n_pi(self):
     tlist = np.linspace(0., 1., 201)
     t_args = {'fwhm_1': 0.1, 'centre_1': 0.5}
     t_func = t_funcs.gaussian(1)
     with self.assertRaises(KeyError):
         t_func(tlist, t_args)