def _initiate_noise_managament(self) -> None:
     """Initiate noise manangement. Link each noise array to the
     appropriate noise effects.
     """
     crt_noise_effects: List[Callable]
     crt_noise_effects_mul_cst: List[float]
     for i in range(self._nbr_eqs):
         crt_noise_effects = self._noise_effects[i]
         crt_noise_effects_mul_cst = self._noise_effects_mul_cst[i]
         for eq in self.__eqs[i]:
             for j in range(len(eq._noise_effects)):
                 crt_noise_effects.extend(eq._noise_effects[j])
                 crt_noise_effects_mul_cst.extend(
                     eq._noise_effects_mul_cst[j])
         if (crt_noise_effects):
             effects_to_add = []
             for k in range(len(crt_noise_effects)):
                 effects_to_add.append(CallableLittExpr(
                     [crt_noise_effects[k], crt_noise_effects_mul_cst[k]],
                     ['*']))
             crt_ops = ['+' for _ in range(len(crt_noise_effects)-1)]
             noise_fct = CallableLittExpr(effects_to_add, crt_ops)
         else:
             noise_fct = CallableLittExpr([lambda noises, z, h, ind:
                                           noises[ind]])
         self._noise_func_per_field.append(noise_fct)
Example #2
0
def test_multi_var_func_and_float():
    """Should fail if the result is not the one expected."""
    a = lambda x, y: x**2 + y**2
    b = lambda x, y: 1 / (y - x)
    d = lambda x, y: x - y
    CLE = CallableLittExpr([a, 3.1, a, 6., b], ['+', '/', '-', '*'])
    assert CLE(3., 4.) == 19.124
Example #3
0
def test_multi_var_only_func():
    """Should fail if the result is not the one expected."""
    a = lambda x, y: x**2 * y**2
    b = lambda x, y: 1 / (y - x)
    d = lambda x, y: x - y
    CLE = CallableLittExpr([a, b, a, d, b], ['+', '//', '%', '**'])
    assert CLE(3., 4.) == 144.0
Example #4
0
def test_one_var_func_and_float():
    """Should fail if the result is not the one expected."""
    a = lambda x: x**2
    b = lambda y: 1 / y
    d = lambda x: x
    CLE = CallableLittExpr([a, 3., a, 4., b], ['+', '/', '-', '*'])
    assert CLE(3.) == 8.0
Example #5
0
def test_one_var_only_func():
    """Should fail if the result is not the one expected."""
    a = lambda x: x**2
    b = lambda y: 1 / y
    d = lambda x: x
    CLE = CallableLittExpr([a, b, a, d, b], ['+', '/', '-', '*'])
    assert CLE(3.) == (8. + (1. / 27.))
Example #6
0
def test_unity_func():
    """Should fail if the result is not the one expected."""
    CLE = CallableLittExpr([lambda identity: identity], [])
    assert CLE(70) == 70
Example #7
0
    def open(self, domain: Domain, *fields: List[Field]) -> None:
        super().open(domain, *fields)
        # Noise --------------------------------------------------------
        # Init splitting ratios depending on requirement
        split_ratios: List[float] = []
        split_ratio: float = 0.
        if (self._split_noise_option == SEED_SPLIT):
            split_ratio = (self._id_tracker.nbr_fields_in_eq(0)
                           + self._id_tracker.nbr_fields_in_eq(1))
            split_ratio = 1./split_ratio if split_ratio else 0.
            split_ratios = [split_ratio, split_ratio, 0., 0.]
        elif (self._split_noise_option == PUMP_SPLIT):
            split_ratio = (self._id_tracker.nbr_fields_in_eq(2)
                           + self._id_tracker.nbr_fields_in_eq(3))
            split_ratio = 1./split_ratio if split_ratio else 0.
            split_ratios = [0., 0., split_ratio, split_ratio]
        elif (self._split_noise_option == ALL_SPLIT):
            split_ratio = self._id_tracker.nbr_fields
            split_ratio = 1./split_ratio if split_ratio else 0.
            split_ratios = [split_ratio for i in range(self._nbr_eqs)]
        elif (self._split_noise_option == NO_SPLIT):
            split_ratios = [1. for i in range(self._nbr_eqs)]
        else:

            raise UnknownNoiseSplitOptionError("Unknown splitting noise "
                "option '{}'.".format(self._split_noise_option))
        # Split Spontaneous Emission power
        ase_noise_: ASENoise
        se_power = SEPower(self._noise_domega)
        for i in range(self._nbr_eqs):
            se_power_ = CallableLittExpr([se_power, split_ratios[i]], ['*'])
            ase_noise_ = ASENoise(se_power_, self._gain_coeff[0],
                                  self._absorp_coeff[0], self._noise_omega)
            self._add_noise_effect(ase_noise_, i)
        # Reflection coeffs --------------------------------------------
        if (callable(self._R_0)):
            if (self._UNI_OMEGA):
                self._R_0_waves = self._R_0(self._center_omega).reshape((-1,1))
            else:
                self._R_0_coeff = np.zeros_like(self._abs_omega)
                for i in range(len(self._center_omega)):
                    self._R_0_coeff[i] = self._R_0(self._abs_omega[i])
            self._R_0_noises = self._R_0(self._noise_omega)
        else:
            if (self._UNI_OMEGA):
                self._R_0_waves = np.ones((len(self._center_omega), 1))
            else:
                self._R_0_waves = np.ones_like(self._abs_omega)
            self._R_0_waves *= self._R_0
            self._R_0_noises = self._R_0 * np.ones_like(self._noise_omega)
        if (callable(self._R_L)):
            if (self._UNI_OMEGA):
                self._R_L_waves = self._R_L(self._center_omega).reshape((-1,1))
            else:
                self._R_L_coeff = np.zeros_like(self._abs_omega)
                for i in range(len(self._center_omega)):
                    self._R_L_coeff[i] = self._R_L(self._abs_omega[i])
            self._R_L_noises = self._R_L(self._noise_omega)
        else:
            if (self._UNI_OMEGA):
                self._R_L_waves = np.ones((len(self._center_omega), 1))
            else:
                self._R_L_waves = np.ones_like(self._abs_omega)
            self._R_L_waves *= self._R_L
            self._R_L_noises = self._R_L * np.ones_like(self._noise_omega)