def build_number_density(self, interaction_strengths, num_density_z_func=None, num_density_z_args=None): """ Builds the number density function and interaction strengths. Args: interaction_strengths: A list of interaction strengths, `g`. These map 1-to-1 to the fields, and so must have the same number of values as there are fields. num_density_z_func: An optioanl function provided just like the time funcs (from t_funcs.py). num_density_z_args: A dict providing the args to be passed to num_density_z_func. Notes: - A factor of 2pi is applied to the interaction_strengths. - By default the num_density function will be square, with density 1.0, starting at z=0.0 and ending at z=1.0. """ self.interaction_strengths = interaction_strengths self.g = np.zeros(len(interaction_strengths)) for i, g in enumerate(interaction_strengths): self.g[i] = 2*np.pi*g # Set the num_density function if num_density_z_func: self.num_density_z_func = getattr(t_funcs, num_density_z_func)(0) else: self.num_density_z_func = t_funcs.square(0) # Set the num_density args if num_density_z_args: self.num_density_z_args = {} for key, value in num_density_z_args.items(): self.num_density_z_args[key + '_0'] = value else: self.num_density_z_args = {'on_0': 0.0, 'off_0': 1.0, 'ampl_0':1.0}
def test_square(self): self.field_00.build_rabi_freq_t_func('square') self.field_00.build_rabi_freq_t_args({ 'on': 0.3, 'off': 0.7, 'ampl': 1.0 }) self.assertEqual(self.field_00.rabi_freq_t_func.__name__, 'square_0') args = self.field_00.rabi_freq_t_args for t in [0.1, 0.3, 0.5, 0.7, 0.9]: self.assertEqual(self.field_00.rabi_freq_t_func(t, args), t_funcs.square(0)(t, args))
def test_null(self): self.field_00.build_rabi_freq_t_func(None) self.field_00.build_rabi_freq_t_args(None) self.assertEqual(self.field_00.rabi_freq_t_func.__name__, 'square_0') args = self.field_00.rabi_freq_t_args for t in [0.1, 0.3, 0.5, 0.7, 0.9]: self.assertEqual(self.field_00.rabi_freq_t_func(t, args), t_funcs.square(0)(t, args)) self.assertEqual(self.field_00.rabi_freq_t_args, { 'ampl_0': 1.0, 'on_0': 0.0, 'off_0': 1.0 })
def test_from_json_str(self): self.assertEqual(self.field_02.coupled_levels, [[1, 2]]) self.assertEqual(self.field_02.detuning, 0.0) self.assertEqual(self.field_02.detuning_positive, True) self.assertEqual(self.field_02.label, 'coupling') self.assertEqual(self.field_02.rabi_freq, 10.0) self.assertEqual(self.field_02.rabi_freq_t_args, { "ampl_0": 1.0, "off_0": 0.7, "on_0": 0.3 }) t_func = t_funcs.square(0) args = self.field_02.rabi_freq_t_args for t in [0.1, 0.3, 0.5, 0.7, 0.9]: self.assertEqual(self.field_02.rabi_freq_t_func(t, args), t_func(t, args))
def build_number_density(self, num_density_z_func, num_density_z_args, interaction_strengths): self.interaction_strengths = interaction_strengths self.g = np.zeros(len(interaction_strengths)) for i, g in enumerate(interaction_strengths): self.g[i] = 2*np.pi*g if num_density_z_func: self.num_density_z_func = getattr(t_funcs, num_density_z_func)(0) else: self.num_density_z_func = t_funcs.square(0) if num_density_z_args: self.num_density_z_args = {} for key, value in num_density_z_args.items(): self.num_density_z_args[key + '_0'] = value else: self.num_density_z_args = {'on_0': 0.0, 'off_0': 1.0, 'ampl_0':1.0}
def test_init_default(self): """ Test Default Initialise """ field_00 = field.Field() self.assertEqual(field_00.coupled_levels, []) self.assertEqual(field_00.detuning, 0.0) self.assertEqual(field_00.detuning_positive, True) self.assertEqual(field_00.label, '') self.assertEqual(field_00.rabi_freq, 0.0) self.assertEqual(field_00.rabi_freq_t_args, { 'ampl_0': 1.0, 'on_0': 0.0, 'off_0': 1.0 }) self.assertEqual(field_00.rabi_freq_t_func.__name__, 'square_0') t_func = t_funcs.square(0) args = field_00.rabi_freq_t_args for t in [0.1, 0.3, 0.5, 0.7, 0.9]: self.assertEqual(field_00.rabi_freq_t_func(t, args), t_func(t, args))