Beispiel #1
0
def test_load_field():
    """Should fail if the saved fields are not the same as the loaded
    fields.
    """
    lt = Layout()
    gssn_1 = Gaussian(channels=1, width=[5.0])
    field_saver_1 = SaveField()
    gssn_2 = Gaussian(channels=1, width=[10.0])
    field_saver_2 = SaveField()

    lt.add_links((gssn_1[0], field_saver_1[0]), (gssn_2[0], field_saver_2[0]))
    lt.run(gssn_1, gssn_2)

    fields = field_saver_1.fields + field_saver_2.fields

    lt_ = Layout()
    load_field = LoadField(fields=fields)

    lt.run(load_field)

    fields = load_field[0].fields

    assert (fields[0] == gssn_1[0].fields[0])
    assert (fields[1] == gssn_2[0].fields[0])
    assert_array_equal(fields[0].channels, gssn_1[0].fields[0].channels)
    assert_array_equal(fields[1].channels, gssn_2[0].fields[0].channels)
    assert_array_equal(fields[0].noise, gssn_1[0].fields[0].noise)
    assert_array_equal(fields[1].noise, gssn_2[0].fields[0].noise)
    assert_array_equal(fields[0].delays, gssn_1[0].fields[0].delays)
    assert_array_equal(fields[1].delays, gssn_2[0].fields[0].delays)
Beispiel #2
0
    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)
Beispiel #3
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)
Beispiel #4
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)
def test_save_field_to_file():
    """Should fail if the saved fields are not the same as the loaded
    fields.
    """
    file_name = 'temp_file_for_save_field_to_file_test.pk1'
    if (os.path.isfile(file_name)):
        print("Can not perfom test because a file named '{}' already exist."
              .format(file_name))
        assert False
    else:
        lt = Layout()
        gssn_1 = Gaussian(channels=1, width=[5.0], save=True)
        field_saver_1 = SaveFieldToFile(file_name=file_name, add_fields=False)
        gssn_2 = Gaussian(channels=1, width=[10.0], save=True)
        field_saver_2 = SaveFieldToFile(file_name=file_name, add_fields=True)

        lt.add_links((gssn_1[0], field_saver_1[0]),
                     (gssn_2[0], field_saver_2[0]))
        lt.run(gssn_1, gssn_2)

        lt_ = Layout()
        load_field = LoadFieldFromFile(file_name=file_name)

        lt_.run(load_field)
        fields = load_field[0].fields

        # Removing created file
        os.remove(file_name)

        # Tests
        assert (fields[0] == gssn_1[0].fields[0])
        assert (fields[1] == gssn_2[0].fields[0])
        assert_array_equal(fields[0].channels, gssn_1[0].fields[0].channels)
        assert_array_equal(fields[1].channels, gssn_2[0].fields[0].channels)
        assert_array_equal(fields[0].noise, gssn_1[0].fields[0].noise)
        assert_array_equal(fields[1].noise, gssn_2[0].fields[0].noise)
        assert_array_equal(fields[0].delays, gssn_1[0].fields[0].delays)
        assert_array_equal(fields[1].delays, gssn_2[0].fields[0].delays)
Beispiel #6
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]