def layout(split_noise_option, channels, peak_powers, center_lambdas): gssn = Gaussian(channels=channels, peak_power=peak_powers, center_lambda=center_lambdas, save=True) pump = CW(channels=3, peak_power=[0.01], center_lambda=[976.]) fiber = FiberYb(length=0.01, split_noise_option=split_noise_option, steps=10, REFL_SEED=True, REFL_PUMP=True, BISEED=False, BIPUMP=False, save=True, PROP_REFL=True, PROP_PUMP=True, alpha=[0.05], max_nbr_iter=2, NOISE=True) lt = Layout(Domain(samples_per_bit=64, noise_samples=10)) lt.add_unidir_links((gssn[0], fiber[0]), (pump[0], fiber[2])) lt.run_all() noise_power_input = fiber[0].fields[0].noise noise_power_seed = fiber[1].fields[0].noise noise_power_refl_seed = fiber[0].fields[1].noise noise_power_pump = fiber[1].fields[1].noise noise_power_refl_pump = fiber[0].fields[2].noise return (noise_power_input, noise_power_seed, noise_power_refl_seed, noise_power_pump, noise_power_refl_pump)
def test_output_combiner_no_combine(nbr_channels, ratios): """Should fail if the output temporal power division does not correpsond to the dividing ratios. """ # Environment creation gssns = [] nbr_arms = len(ratios) base_power = 10.0 for i in range(nbr_arms): gssns.append( Gaussian(channels=nbr_channels, save=True, peak_power=[(i + 1) * base_power for i in range(nbr_channels)])) combiner = IdealCombiner(arms=nbr_arms, ratios=ratios, save=True, combine=False) lt = Layout() for i in range(nbr_arms): lt.add_link(gssns[i][0], combiner[i]) lt.run_all() # Testing init_fields = [] for i in range(0, nbr_arms): init_fields.extend(gssns[i][0].fields) output_fields = combiner[nbr_arms].fields assert len(output_fields) == nbr_arms assert len(output_fields) == len(init_fields) for i in range(len(output_fields)): for j in range(len(output_fields[i])): # Taking into account rounding errors power_1 = ratios[i] * temporal_power(init_fields[i][j]) power_2 = temporal_power(output_fields[i][j]) assert_array_almost_equal(power_1, power_2, 10)
def layout(nbr_channels_seed, peak_powers_seed, center_lambdas_seed, nbr_channels_pump, peak_powers_pump, center_lambdas_pump, REFL_SEED, REFL_PUMP, NOISE): nbr_ch_seed = nbr_channels_seed // 2 gssn = Gaussian(channels=nbr_ch_seed, peak_power=peak_powers_seed[:nbr_ch_seed], center_lambda=center_lambdas_seed[:nbr_ch_seed]) gssn_ = Gaussian(channels=(nbr_channels_seed - nbr_ch_seed), peak_power=peak_powers_seed[nbr_ch_seed:], center_lambda=center_lambdas_seed[nbr_ch_seed:]) nbr_ch_pump = nbr_channels_pump // 2 pump = CW(channels=nbr_ch_pump, peak_power=peak_powers_pump[:nbr_ch_pump], center_lambda=center_lambdas_pump[:nbr_ch_pump]) pump_ = CW(channels=(nbr_channels_pump - nbr_ch_pump), peak_power=peak_powers_pump[nbr_ch_pump:], center_lambda=center_lambdas_pump[nbr_ch_pump:]) fiber = FiberYb(length=0.01, steps=10, REFL_SEED=REFL_SEED, REFL_PUMP=REFL_PUMP, BISEED=True, BIPUMP=True, save_all=True, alpha=[0.05], max_nbr_iter=2, NOISE=NOISE) lt = Layout(Domain(samples_per_bit=64, noise_samples=10)) lt.add_unidir_links((gssn[0], fiber[0]), (pump[0], fiber[2]), (gssn_[0], fiber[1]), (pump_[0], fiber[3])) lt.run_all() return fiber.storages[0]
def test_output_divider(nbr_channels, ratios): """Should fail if the output temporal power division does not correpsond to the dividing ratios. """ # Environment creation base_power = 10.0 gssn = Gaussian(channels=nbr_channels, save=True, peak_power=[(i + 1) * base_power for i in range(nbr_channels)]) nbr_arms = len(ratios) divider = IdealDivider(arms=nbr_arms, ratios=ratios, save=True) lt = Layout() lt.add_link(gssn[0], divider[0]) lt.run_all() # Testing init_power = temporal_power(gssn[0][0].channels) for i in range(nbr_arms): assert len(divider[i + 1]) == 1 arm_power = temporal_power(divider[i + 1][0].channels) assert len(arm_power) == len(init_power) for j in range(len(arm_power)): # Taking into account rounding errors assert_array_almost_equal((ratios[i] * init_power[j]), arm_power[j], 10)
def test_constraint_coprop(): r"""Should fail if the copropagating fields are not waiting for each others. Notes ----- Test case:: [0] _________ [1] __________\ [2] ___________\__ Combiner ___ Dummy Comp __ check output [3] ___________/ ... [n-1] _________/ """ lt = Layout() nbr_sig = 5 combiner = IdealCombiner(arms=nbr_sig, combine=False) for i in range(nbr_sig): lt.add_link(Gaussian()[0], combiner[i]) dummy_comp = IdealAmplifier(save=True) lt.add_link(combiner[nbr_sig], dummy_comp[0]) lt.run_all() assert (len(dummy_comp[1]) == nbr_sig)
def test_no_divide_output(): """Should fail if the incoming fields are not the same as the output fields at each arm. """ nbr_channels = 10 arms = 5 gssn = Gaussian(channels=nbr_channels, save=True) divider = IdealDivider(arms=arms, divide=False, save=True) lt = Layout() lt.add_link(gssn[0], divider[0]) lt.run_all() # Testing init_power = temporal_power(gssn[0][0].channels) for i in range(arms): assert len(divider[i + 1]) == 1 arm_power = temporal_power(divider[i + 1][0].channels) assert len(arm_power) == len(init_power) for j in range(len(arm_power)): assert_array_equal(arm_power[j], init_power[j])
def test_combine_output_diff_omega_and_rep_freq(nbr_channels, ratios): """Should fail if the different omega and repetition frequencies are added to each other. """ # Environment creation back_up_flag_omega = cfg.get_field_op_matching_omega() back_up_flag_rep_freq = cfg.get_field_op_matching_rep_freq() cfg.set_field_op_matching_omega(True) cfg.set_field_op_matching_rep_freq(True) gssns = [] nbr_arms = len(ratios) base_power = 10.0 for i in range(nbr_arms): gssns.append( Gaussian(channels=nbr_channels, save=True, peak_power=[(j + 1) * base_power for j in range(nbr_channels)], center_lambda=[(1500. + j) * (i + 1) for j in range(nbr_channels)], rep_freq=[(1e-2 + (j * 1e-4)) * (i + 1) for j in range(nbr_channels)])) combiner = IdealCombiner(arms=nbr_arms, ratios=ratios, save=True, combine=True) lt = Layout() for i in range(nbr_arms): lt.add_link(gssns[i][0], combiner[i]) lt.run_all() lt.reset() # Testing init_fields = [] for i in range(0, nbr_arms): init_fields.extend(gssns[i][0].fields) output_fields = combiner[nbr_arms].fields assert len(output_fields) == 1 assert len(output_fields[0]) == (nbr_channels * nbr_arms) # Reset cfg.set_field_op_matching_omega(back_up_flag_omega) cfg.set_field_op_matching_rep_freq(back_up_flag_rep_freq)
def layout(nbr_channels_seed, peak_powers_seed, center_lambdas_seed, nbr_channels_pump, peak_powers_pump, center_lambdas_pump, REFL_SEED, REFL_PUMP, NOISE): gssn = Gaussian(channels=nbr_channels_seed, peak_power=peak_powers_seed, center_lambda=center_lambdas_seed) pump = CW(channels=nbr_channels_pump, peak_power=peak_powers_pump, center_lambda=center_lambdas_pump) fiber = FiberYb(length=0.01, steps=10, REFL_SEED=REFL_SEED, REFL_PUMP=REFL_PUMP, BISEED=False, BIPUMP=False, save_all=True, alpha=[0.05], max_nbr_iter=2, NOISE=NOISE) lt = Layout(Domain(samples_per_bit=64, noise_samples=10)) lt.add_unidir_links((gssn[0], fiber[0]), (pump[0], fiber[2])) lt.run_all() return fiber.storages[0]
def test_constraint_waiting(): r"""Should fail if the component is not waiting for other fields. Notes ----- Test case:: [0] _________ [1] __________\ [2] ___________\__ Combiner __ check output [3] ___________/ ... [n-1] _________/ """ lt = Layout() nbr_sig = 5 combiner = IdealCombiner(arms=nbr_sig, combine=False, save=True) for i in range(nbr_sig): lt.add_link(Gaussian()[0], combiner[i]) lt.run_all() assert (len(combiner[nbr_sig]) == nbr_sig)