Esempio n. 1
0
                                  width=[10., 6.],
                                  center_lambda=[center_lambda],
                                  noise=100 * np.ones(domain.noise_samples))
 filter: oc.GaussianFilter = oc.GaussianFilter(nu_bw=nu_bw,
                                               nu_offset=0.,
                                               order=1,
                                               center_nu=center_nu)
 lt.add_link(pulse[0], filter[0])
 lt.run(pulse)
 plot_titles: List[str] = [
     "Original pulse", r"After Gaussian filter with "
     "frequency bandwidth {} THz.".format(round(nu_bw, 2))
 ]
 plot_titles += plot_titles
 y_datas: List[np.ndarray] = [
     oc.temporal_power(pulse[0][0].channels),
     oc.temporal_power(filter[1][0].channels),
     oc.spectral_power(pulse[0][0].channels),
     oc.spectral_power(filter[1][0].channels), pulse[0][0].noise,
     filter[1][0].noise
 ]
 x_datas: List[np.ndarray] = [
     pulse[0][0].time, filter[1][0].time, pulse[0][0].nu, filter[1][0].nu,
     pulse[0][0].domain.noise_nu, filter[1][0].domain.noise_nu
 ]
 x_labels: List[str] = ['t', 't', 'nu', 'nu', 'nu', 'nu']
 y_labels: List[str] = ['P_t', 'P_t', 'P_nu', 'P_nu', 'P (W)', 'P (W)']
 nu_range = (center_nu - .1, center_nu + .1)
 time_range = (bit_width / 2. + 75., bit_width / 2. - 75.)
 noise_range = (x_datas[-1][0], x_datas[-1][-1])
 x_ranges = [time_range, time_range, nu_range, nu_range, noise_range]
Esempio n. 2
0
import optcom as oc

# Create 2 Gaussian channels
pulse = oc.Gaussian(channels=2,
                    center_lambda=[1030., 1550.],
                    peak_power=[0.5, 1.0])
# Create fiber with a user-defined attenuation coefficient
fiber = oc.Fiber(length=1.0,
                 alpha=[0.4],
                 ATT=True,
                 DISP=True,
                 SPM=True,
                 save_all=True)
# Create an optical layout and link the first port of 'pulse' to the first port of 'fiber'
layout = oc.Layout()
layout.add_link(pulse.get_port(0), fiber.get_port(0))
layout.run_all()
# Extract outputs and plot
time = fiber.storage.time
power = oc.temporal_power(fiber.storage.channels)
space = fiber.storage.space
oc.animation2d(time,
               power,
               space,
               x_label='t',
               y_label='P_t',
               plot_title='My first Optcom example',
               line_labels=['1030. nm channel', '1550. nm channel'])
#filename='example_anim_readme.mp4')
Esempio n. 3
0
    combiner: oc.IdealCombiner = oc.IdealCombiner(arms=3, combine=False)

    lt.add_links((pulse_1[0], combiner[0]), (pulse_2[0], combiner[1]),
                 (pulse_3[0], combiner[2]), (combiner[3], pm[0]))

    lt.run(pulse_1, pulse_2, pulse_3)

    plot_titles: List[str] = ([
        "Original pulses", "Pulses coming out of the "
        "ideal coupler \n without combination"
    ])
    plot_groups: List[int] = [0, 0, 0, 1]
    line_labels: List[Optional[str]] = ['port 0', 'port 1', 'port 2', None]

    out_channels: np.ndarray = oc.temporal_power(pm[1][0].channels)
    for i in range(len(pm[1])):
        out_channels = np.vstack(
            (out_channels, oc.temporal_power(pm[1][i].channels)))
    y_datas: List[np.ndarray] = [
        oc.temporal_power(pulse_1[0][0].channels),
        oc.temporal_power(pulse_2[0][0].channels),
        oc.temporal_power(pulse_3[0][0].channels), out_channels
    ]
    x_datas: List[np.ndarray] = [
        pulse_1[0][0].time, pulse_2[0][0].time, pulse_3[0][0].time,
        pm[1][0].time
    ]

    lt.reset()
    pm = oc.IdealPhaseMod()
Esempio n. 4
0
    gssn_1: oc.Gaussian = oc.Gaussian(channels=1, width=[5.0],
                                      field_name='field 1 to be saved in file')
    field_saver_1: oc.SaveField = oc.SaveField()
    gssn_2: oc.Gaussian = oc.Gaussian(channels=1, width=[10.0],
                                      field_name='field 2 to be saved in file')
    field_saver_2: oc.SaveField = oc.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: List[oc.Field] = field_saver_1.fields + field_saver_2.fields

    lt_: oc.Layout = oc.Layout()
    load_field: oc.LoadField = oc.LoadField(fields=fields)

    lt.run(load_field)

    fields = load_field[0].fields

    x_datas: List[np.ndarray] = [fields[0].time, fields[1].time,
                                 fields[0].nu, fields[1].nu]
    y_datas: List[np.ndarray] = [oc.temporal_power(fields[0].channels),
                                 oc.temporal_power(fields[1].channels),
                                 oc.spectral_power(fields[0].channels),
                                 oc.spectral_power(fields[1].channels)]

    oc.plot2d(x_datas, y_datas, x_labels=["t", "t", "nu","nu"],
              y_labels=["P_t", "P_t", "P_nu", "P_nu"],
              plot_titles=["Gaussian pulse which has been saved and loaded"],
              plot_groups=[0,0,1,1])
Esempio n. 5
0
    gssn_1: oc.Gaussian = oc.Gaussian(channels=1,
                                      width=[5.0],
                                      field_name='field 1 to be saved in file')
    field_saver_1: oc.SaveField = oc.SaveField()
    gssn_2: oc.Gaussian = oc.Gaussian(channels=1,
                                      width=[10.0],
                                      field_name='field 2 to be saved in file')
    field_saver_2: oc.SaveField = oc.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: List[oc.Field] = field_saver_1.fields + field_saver_2.fields

    x_datas: List[np.ndarray] = [
        fields[0].time, fields[1].time, fields[0].nu, fields[1].nu
    ]
    y_datas: List[np.ndarray] = [
        oc.temporal_power(fields[0].channels),
        oc.temporal_power(fields[1].channels),
        oc.spectral_power(fields[0].channels),
        oc.spectral_power(fields[1].channels)
    ]

    oc.plot2d(x_datas,
              y_datas,
              x_labels=["t", "t", "nu", "nu"],
              y_labels=["P_t", "P_t", "P_nu", "P_nu"],
              plot_titles=["Gaussian pulse which has been saved"],
              plot_groups=[0, 0, 1, 1])
Esempio n. 6
0
 random_phase: float = random.random() * math.pi
 random_phase_bis: float = random.random() * math.pi
 phase_shifts: List[List[float]] = [[random_phase, random_phase],
                                    [math.pi / 2, 0.0],
                                    [random_phase, random_phase_bis]]
 y_datas: List[np.ndarray] = []
 plot_titles: List[str] = ["Original pulse"]
 mz: oc.IdealMZM
 for i, phase_shift in enumerate(phase_shifts):
     # Propagation
     mz = oc.IdealMZM(phase_shift=phase_shift, loss=loss)
     lt.add_link(pulse[0], mz[0])
     lt.run(pulse)
     lt.reset()
     # Plot parameters and get waves
     y_datas.append(oc.temporal_power(mz[1][0].channels))
     if (isinstance(phase_shift[0], float)):
         temp_phase = phase_shift
     else:
         temp_phase = [phase_shift[0](0), phase_shift[1](0)]
     plot_titles += [
         "Pulses coming out of the Ideal MZM with phase "
         "shift {} and {}".format(str(round(temp_phase[0], 2)),
                                  str(round(temp_phase[1], 2)))
     ]
 v_pi: List[float] = [1.0]
 v_mod: List[Callable] = [
     lambda t: math.sin(math.pi * t), lambda t: math.sin(math.pi / 2.0 * t)
 ]
 v_bias: List[float] = [1.2, 2.1]
 mz = oc.IdealMZM(v_pi=v_pi, v_mod=v_mod, v_bias=v_bias)
Esempio n. 7
0
    rep_freq: List[float] = [0.03, 0.04]
    offset_nu: List[float] = [1.56, -1.6]
    chirp: List[float] = [0.5, 0.1]
    init_phi: List[float] = [1.0, 0.0]

    sech = oc.Sech(channels=channels,
                   center_lambda=center_lambda,
                   position=position,
                   fwhm=width,
                   peak_power=peak_power,
                   rep_freq=rep_freq,
                   offset_nu=offset_nu,
                   chirp=chirp,
                   init_phi=init_phi,
                   save=True)

    lt.run(sech)

    x_datas: List[np.ndarray] = [sech[0][0].time, sech[0][0].nu]
    y_datas: List[np.ndarray] = [
        oc.temporal_power(sech[0][0].channels),
        oc.spectral_power(sech[0][0].channels)
    ]

    oc.plot2d(x_datas,
              y_datas,
              x_labels=["t", "nu"],
              y_labels=["P_t", "P_nu"],
              plot_titles=["Sech pulse"],
              split=True)
Esempio n. 8
0
    import numpy as np

    import optcom as oc

    lt: oc.Layout = oc.Layout()

    pulse: oc.Gaussian = oc.Gaussian(channels=1, peak_power=[10.0])
    isolator_1: oc.IdealIsolator = oc.IdealIsolator(blocked_port=1, save=True)

    lt.add_link(pulse[0], isolator_1[0])

    lt.run(pulse)

    plot_titles: List[str] = ([
        'Initial Pulse', 'Output of first isolator (pass)'
    ])

    y_datas: List[np.ndarray] = [
        oc.temporal_power(pulse[0][0].channels),
        oc.temporal_power(isolator_1[1][0].channels)
    ]
    x_datas: List[np.ndarray] = [pulse[0][0].time, isolator_1[1][0].time]

    oc.plot2d(x_datas,
              y_datas,
              split=True,
              plot_titles=plot_titles,
              x_labels=['t'],
              y_labels=['P_t'],
              line_opacities=[0.3])
Esempio n. 9
0
    lt: oc.Layout = oc.Layout(domain)
    lambda_bw = 0.05 # nm
    nu_bw = oc.lambda_bw_to_nu_bw(lambda_bw, center_lambda)
    pulse: oc.Gaussian = oc.Gaussian(channels=2, peak_power=[10.0, 19.0],
                                     width=[10., 6.],
                                     center_lambda=[center_lambda],
                                     noise=100*np.ones(domain.noise_samples))
    filter: oc.FlatTopFilter = oc.FlatTopFilter(nu_bw=nu_bw, nu_offset=0.,
                                                center_nu=center_nu)
    lt.add_link(pulse[0], filter[0])
    lt.run(pulse)
    plot_titles: List[str] = ["Original pulse", r"After flat top filter with "
                              "frequency bandwidth {} THz."
                              .format(round(nu_bw,2))]
    plot_titles += plot_titles
    y_datas: List[np.ndarray] = [oc.temporal_power(pulse[0][0].channels),
                                 oc.temporal_power(filter[1][0].channels),
                                 oc.spectral_power(pulse[0][0].channels),
                                 oc.spectral_power(filter[1][0].channels),
                                 pulse[0][0].noise, filter[1][0].noise]
    x_datas: List[np.ndarray] = [pulse[0][0].time, filter[1][0].time,
                                 pulse[0][0].nu, filter[1][0].nu,
                                 pulse[0][0].domain.noise_nu,
                                 filter[1][0].domain.noise_nu]
    x_labels: List[str] = ['t', 't', 'nu', 'nu', 'nu', 'nu']
    y_labels: List[str] = ['P_t', 'P_t', 'P_nu', 'P_nu', 'P (W)', 'P (W)']
    nu_range = (center_nu-.1, center_nu+.1)
    time_range = (bit_width/2.+75., bit_width/2.-75.)
    noise_range = (x_datas[-1][0], x_datas[-1][-1])
    x_ranges = [time_range, time_range, nu_range, nu_range, noise_range]
Esempio n. 10
0
    cw: oc.CW = oc.CW(channels=channels,
                      center_lambda=center_lambda,
                      peak_power=peak_power,
                      offset_nu=offset_nu,
                      init_phi=init_phi,
                      save=True)

    lt.run(cw)

    plot_titles: List[str] = [
        "CW pulse temporal power", "CW pulse spectral power",
        "CW pulse temporal phase", "CW pulse spectral phase"
    ]
    x_datas: List[np.ndarray] = [
        cw[0][0].time, cw[0][0].nu, cw[0][0].time, cw[0][0].nu
    ]
    y_datas: List[np.ndarray] = [
        oc.temporal_power(cw[0][0].channels),
        oc.spectral_power(cw[0][0].channels),
        oc.temporal_phase(cw[0][0].channels),
        oc.spectral_phase(cw[0][0].channels)
    ]

    oc.plot2d(x_datas,
              y_datas,
              x_labels=["t", "nu", "t", "nu"],
              y_labels=["P_t", "P_nu", "phi_t", "phi_nu"],
              plot_titles=plot_titles,
              split=True,
              line_opacities=[0.2])
Esempio n. 11
0
    init_phi: List[float] = [1.0, 0.0]
    beta_2: List[float] = [-19.0, -17.0]
    gamma: List[float] = [4.3, 4.6]

    soli = oc.Soliton(channels=channels,
                      center_lambda=center_lambda,
                      position=position,
                      width=width,
                      rep_freq=rep_freq,
                      offset_nu=offset_nu,
                      order=order,
                      init_phi=init_phi,
                      beta_2=beta_2,
                      gamma=gamma,
                      save=True)

    lt.run(soli)

    x_datas: List[np.ndarray] = [soli[0][0].time, soli[0][0].nu]
    y_datas: List[np.ndarray] = [
        oc.temporal_power(soli[0][0].channels),
        oc.spectral_power(soli[0][0].channels)
    ]

    oc.plot2d(x_datas,
              y_datas,
              x_labels=["t", "nu"],
              y_labels=["P_t", "P_nu"],
              plot_titles=["Soliton pulse"],
              split=True)
Esempio n. 12
0
    import numpy as np

    import optcom as oc

    # with division
    pulse: oc.Gaussian = oc.Gaussian(channels=1, peak_power=[10.0])
    lt: oc.Layout = oc.Layout()
    arms: int = 3
    ratios: List[float] = [round(random.uniform(0, 1), 2) for i in range(arms)]
    divider: oc.IdealDivider = oc.IdealDivider(arms=arms,
                                               divide=True,
                                               ratios=ratios,
                                               save=True)
    lt.add_link(pulse[0], divider[0])
    lt.run(pulse)
    y_datas: List[np.ndarray] = [oc.temporal_power(pulse[0][0].channels)]
    x_datas: List[np.ndarray] = [pulse[0][0].time]

    plot_titles: List[str] = ([
        "Original pulse", "Pulses coming out of the "
        "ideal divider (3 ports) \n with ratios {}".format(str(ratios))
    ])
    plot_groups: List[int] = [0] + [1 for i in range(arms)]
    line_labels: List[Optional[str]] = [None]
    line_labels.extend(["port {}".format(str(i)) for i in range(arms)])

    for i in range(1, arms + 1):
        y_datas.append(oc.temporal_power(divider[i][0].channels))
        x_datas.append(divider[i][0].time)
    # Without division
    arms = 3
Esempio n. 13
0
                              save=True,
                              wait=True,
                              UNI_OMEGA=True,
                              STEP_UPDATE=False,
                              INTRA_COMP_DELAY=True,
                              INTRA_PORT_DELAY=False,
                              INTER_PORT_DELAY=False,
                              noise_ode_method='rk4',
                              NOISE=True)
    lt.add_link(pulse_1[0], coupler[0])
    lt.add_link(pulse_2[0], coupler[1])

    lt.run(pulse_1, pulse_2)

    y_datas: List[np.ndarray] = [
        oc.temporal_power(pulse_1[0][0].channels),
        oc.temporal_power(pulse_2[0][0].channels),
        oc.temporal_power(coupler[2][0].channels),
        oc.temporal_power(coupler[3][0].channels), pulse_1[0][0].noise,
        coupler[2][0].noise, pulse_2[0][0].noise, coupler[3][0].noise
    ]
    x_datas: List[np.ndarray] = [
        pulse_1[0][0].time, pulse_2[0][0].time, coupler[2][0].time,
        coupler[3][0].time, pulse_1[0][0].domain.noise_omega,
        coupler[2][0].domain.noise_omega, pulse_2[0][0].domain.noise_omega,
        coupler[3][0].domain.noise_omega
    ]
    plot_groups: List[int] = [0, 1, 2, 3, 4, 4, 5, 5]
    plot_titles: List[str] = [
        "Original pulse", "Original pulse", "Pulse coming out of the "
        "coupler with Lk = {}".format(str(round(length * kappa_, 2)))
Esempio n. 14
0
    order: List[int] = [1, 2, 1]
    chirp: List[float] = [0.0, 0.5, 0.1]
    init_phi: List[float] = [0.0, 1.0, 0.0]

    gssn = oc.Gaussian(channels=channels,
                       center_lambda=center_lambda,
                       position=position,
                       width=width,
                       peak_power=peak_power,
                       rep_freq=rep_freq,
                       offset_nu=offset_nu,
                       order=order,
                       chirp=chirp,
                       init_phi=init_phi,
                       save=True)

    lt.run(gssn)

    x_datas: List[np.ndarray] = [gssn[0][0].time, gssn[0][0].nu]
    y_datas: List[np.ndarray] = [
        oc.temporal_power(gssn[0][0].channels),
        oc.spectral_power(gssn[0][0].channels)
    ]

    oc.plot2d(x_datas,
              y_datas,
              x_labels=["t", "nu"],
              y_labels=["P_t", "P_nu"],
              plot_titles=["Gaussian pulse"],
              split=True)
Esempio n. 15
0
    lt: oc.Layout = oc.Layout(oc.Domain(bit_width=100.0, samples_per_bit=4096))

    pulse: oc.Gaussian = oc.Gaussian(channels=2, peak_power=[0.5, 1.0], width=[0.5, 0.8])

    steps: int = int(5e3)
    fiber: oc.Fiber
    SS: bool = True
    for j, nlse_method in enumerate(nlse_methods):
        if (j == len(nlse_methods)-2):  # To compute rk4ip and rk4ip_gnlse
            oc.set_rk4ip_opti_gnlse(False)   # Can make slighty diff. output
        else:
            oc.set_rk4ip_opti_gnlse(True)
        # Propagation
        fiber = oc.Fiber(length=0.2, nlse_method=nlse_method, alpha=[0.5],
                      beta_order=3, gamma=4.0, nl_approx=False, SPM=True,
                      XPM=True, SS=True, RS=True, steps=steps, save=True)
        lt.add_link(pulse[0], fiber[0])
        lt.run(pulse)
        lt.reset()
        # Plot parameters and get waves
        x_datas.append(fiber[1][0].time)
        y_datas.append(oc.temporal_power(fiber[1][0].channels))
        plot_groups.append(0)

    line_labels.extend(nlse_methods[:-1] + ["rk4ip_gnlse"])
    plot_titles.extend(["NLSE solvers test with n={}".format(str(steps))])
    # -------------------- Plotting results ------------------------
    oc.plot2d(x_datas, y_datas, plot_groups=plot_groups,
              plot_titles=plot_titles, x_labels=['t'], y_labels=['P_t'],
              line_labels=line_labels, line_opacities=[0.3])