コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
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)
コード例 #4
0
ファイル: test_nlse_solver.py プロジェクト: optcom-org/optcom
    def layout(channels, peak_powers, widths, center_lambdas):
        domain = Domain(bit_width=100.0, samples_per_bit=2048)
        lt = Layout(domain)
        dtime = domain.dtime
        out_temporal_power = []
        out_spectral_power = []
        gssn = Gaussian(channels=channels,
                        peak_power=peak_powers,
                        width=widths,
                        center_lambda=center_lambdas)
        for i in range(2):
            if (i):
                cfg.RK4IP_OPTI_GNLSE = True
            else:
                cfg.RK4IP_OPTI_GNLSE = False
            fiber = Fiber(length=0.2,
                          nlse_method='rk4ip',
                          alpha=[0.5],
                          beta_order=3,
                          nl_approx=False,
                          ATT=True,
                          DISP=True,
                          SPM=True,
                          XPM=True,
                          SS=True,
                          RS=True,
                          steps=1000,
                          save=True)
            lt.add_link(gssn[0], fiber[0])
            lt.run(gssn)
            lt.reset()
            out_temporal_power.append(temporal_power(fiber[1][0].channels))
            out_spectral_power.append(spectral_power(fiber[1][0].channels))

        return (out_temporal_power, out_spectral_power)
コード例 #5
0
def test_constraint_port_valid():
    r"""Should fail if the propagating field can enter the dummy_comp.

    Notes
    -----
    Test case::

        Gaussian_1 ______ Combiner

    """
    # Environment creations
    class DummyPassComp(AbstractPassComp):
        def __init__(self):
            super().__init__('', '', [cst.ELEC_IN, cst.ELEC_OUT], True)
        def __call__(self, domain, ports, fields):

            return ([1 for i in range(len(fields))], fields)

    lt = Layout()
    gssn = Gaussian()
    dummy = DummyPassComp()
    lt.add_link(gssn[0], dummy[0])
    lt.run(gssn)
    # Testing
    pytest.warns(PortValidWarning, lt.run, gssn)
コード例 #6
0
ファイル: test_layout.py プロジェクト: optcom-org/optcom
def test_wrong_start_comp_for_run():
    """Should fail if the layout is start with a wrong component."""
    # Environment creations
    start = Gaussian()
    a = IdealCoupler()
    layout = Layout()
    layout.add_link(a[0], start[0])
    # Testing
    pytest.raises(StartSimError, layout.run, a)
コード例 #7
0
ファイル: test_layout.py プロジェクト: optcom-org/optcom
def test_already_linked():
    """Should fail if component's port is already linked."""
    # Environment creation
    a = IdealCoupler(name='a')
    b = IdealCoupler(name='b')
    c = IdealCoupler(name='c')
    layout = Layout()
    layout.add_link(a[1], b[0])
    # Testing
    pytest.raises(LinkError, layout.add_links, (c[1], b[0]))
    pytest.raises(LinkError, layout.add_links, (b[0], c[2]))
    pytest.raises(LinkError, layout.add_links, (a[1], b[0]))
コード例 #8
0
ファイル: test_layout.py プロジェクト: optcom-org/optcom
def test_wrong_start_comp_ports():
    """Should fail if the right warning is not shown."""

    # Environment creation
    class DummyStartComp(AbstractStartComp):
        def __init__(self):
            super().__init__('', '', [cst.OPTI_ALL], True)

        def __call__(self, domain):

            return ([4], [Field(Domain(), 1)])

    start = DummyStartComp()
    a = IdealCoupler(name='a')
    layout = Layout()
    layout.add_link(start[0], a[0])
    # Testing
    pytest.warns(WrongPortWarning, layout.run, start)
コード例 #9
0
ファイル: test_layout.py プロジェクト: optcom-org/optcom
def test_wrong_start_comp_output():
    """Should fail if the right error is not raised."""

    # Environment creation
    class DummyStartComp(AbstractStartComp):
        def __init__(self):
            super().__init__('', '', [cst.OPTI_ALL], True)

        def __call__(self, domain):

            return ([0, 0], [Field(Domain(), 1)])

    start = DummyStartComp()
    a = IdealCoupler(name='a')
    layout = Layout()
    layout.add_link(start[0], a[0])
    # Testing
    pytest.raises(PropagationError, layout.run, start)
コード例 #10
0
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])
コード例 #11
0
    def layout(starter, ATT, DISP, SPM, SS, RS, approx):
        domain = Domain()
        lt = Layout(domain)
        dtime = domain.dtime
        domega = domain.domega
        out_temporal_power = []
        out_spectral_power = []
        out_temporal_fwhm = []
        out_spectral_fwhm = []
        nlse_method = "ssfm_symmetric"
        flag = True
        till_nbr = 4 if approx else 5
        for i in range(1, till_nbr):
            if (i == 4):
                flag = False
            fiber = Fiber(length=1.0,
                          nlse_method=nlse_method,
                          alpha=[0.046],
                          nl_approx=flag,
                          ATT=ATT,
                          DISP=DISP,
                          SPM=SPM,
                          SS=SS,
                          RS=RS,
                          steps=1000,
                          save=True,
                          approx_type=i)
            lt.add_link(starter[0], fiber[0])
            lt.run(starter)
            lt.reset()
            out_temporal_power.append(temporal_power(fiber[1][0].channels))
            out_spectral_power.append(spectral_power(fiber[1][0].channels))
            out_temporal_fwhm.append(fwhm(out_temporal_power[-1], dtime))
            out_spectral_fwhm.append(fwhm(out_spectral_power[-1], domega))
        in_temporal_power = temporal_power(starter[0][0].channels)
        in_spectral_power = spectral_power(starter[0][0].channels)
        in_temporal_fwhm = fwhm(in_temporal_power, dtime)
        in_spectral_fwhm = fwhm(in_spectral_power, domega)

        return (in_temporal_power, in_spectral_power, in_temporal_fwhm,
                in_spectral_fwhm, out_temporal_power, out_spectral_power,
                out_temporal_fwhm, out_spectral_fwhm)
コード例 #12
0
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)
コード例 #13
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)
コード例 #14
0
def test_interplay_dispersion_and_spm():
    """Should fail if (i) fwhm of temporal output powers for small
    N square number is greater than fwhm of initial pulse or (ii)
    fwhm of temporal output powers for big N square number is
    greater than initial fwhm in case of positive GVD and smaller
    than initial fwhm in case of negative GVD.

    Notes
    -----
    Test case::

    gssn ___ fiber

    """
    # Environment creation
    domain = Domain()
    lt = Layout(domain)
    dtime = domain.dtime
    fwhms_pos_gvd = []
    fwhms_neg_gvd = []
    time_pos_gvd = []
    time_neg_gvd = []
    nlse_method = "ssfm_symmetric"
    # Make sure to have a positive GVD to pass the test
    gssn = Gaussian(channels=1, peak_power=[1.0], center_lambda=[1030.])
    flag = True
    for i in range(1, 5):
        if (i == 4):
            flag = False
        fiber = Fiber(length=1.0,
                      nlse_method=nlse_method,
                      alpha=[0.46],
                      gamma=2.0,
                      nl_approx=flag,
                      ATT=False,
                      DISP=True,
                      SPM=True,
                      SS=False,
                      RS=False,
                      steps=1000,
                      save=True,
                      approx_type=i,
                      beta=[1e5, 1e3, 20.0])
        lt.add_link(gssn[0], fiber[0])
        lt.run(gssn)
        lt.reset()
        time_pos_gvd.append(fiber[1][0].time)
        fwhms_pos_gvd.append(fwhm(temporal_power(fiber[1][0].channels), dtime))
    flag = True
    for i in range(1, 5):
        if (i == 4):
            flag = False
        fiber = Fiber(length=1.0,
                      nlse_method=nlse_method,
                      alpha=[0.46],
                      gamma=2.0,
                      nl_approx=flag,
                      ATT=False,
                      DISP=True,
                      SPM=True,
                      SS=False,
                      RS=False,
                      steps=1000,
                      save=True,
                      approx_type=i,
                      beta=[1e5, 1e3, -20.0])
        lt.add_link(gssn[0], fiber[0])
        lt.run(gssn)
        lt.reset()
        time_neg_gvd.append(fiber[1][0].time)
        fwhms_neg_gvd.append(fwhm(temporal_power(fiber[1][0].channels), dtime))
    fwhm_temporal_gssn = fwhm(temporal_power(gssn[0][0].channels), dtime)
    time_gssn = gssn[0][0].time
    # Testing
    for i in range(len(fwhms_neg_gvd)):
        assert_array_less(time_gssn, time_pos_gvd[i])
        assert_array_less(time_gssn, time_neg_gvd[i])
        assert fwhm_temporal_gssn[0] < fwhms_pos_gvd[i][0]
        assert fwhms_neg_gvd[i][0] < fwhm_temporal_gssn[0]