"Transfer function centered at " "{} nm with bandwidth {} nm".format(round(center_lambda, 2), round(lambda_bw)) ]) # Apply on pulse and plot bit_width = 1000. domain = oc.Domain(samples_per_bit=2**13, bit_width=bit_width, noise_samples=int(1e3), noise_range=(center_lambda - 1.0, center_lambda + 1.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.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),
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')
return self.output_ports(ports), output_fields if __name__ == "__main__": """Give an example of IdealCombiner usage. This piece of code is standalone, i.e. can be used in a separate file as an example. """ from typing import Callable, List, Optional import numpy as np import optcom as oc pulse_1: oc.Gaussian = oc.Gaussian(peak_power=[1.0], center_lambda=[1550.0]) pulse_2: oc.Gaussian = oc.Gaussian(peak_power=[5.0], center_lambda=[1030.0]) pulse_3: oc.Gaussian = oc.Gaussian(peak_power=[10.0], center_lambda=[976.0]) # Dummy component to be able to test the not combining case pm: oc.IdealPhaseMod = oc.IdealPhaseMod() lt: oc.Layout = oc.Layout() 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)
if __name__ == "__main__": """Give an example of LoadField usage. This piece of code is standalone, i.e. can be used in a separate file as an example. """ from typing import List import numpy as np import optcom as oc lt: oc.Layout = oc.Layout() 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)
if __name__ == "__main__": """Give an example of IdealIsolator usage. This piece of code is standalone, i.e. can be used in a separate file as an example. """ from typing import List, Optional 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]
if __name__ == "__main__": """Give an example of IdealIsolator usage. This piece of code is standalone, i.e. can be used in a separate file as an example. """ import random import math from typing import Callable, List, Optional import numpy as np import optcom as oc pulse: oc.Gaussian = oc.Gaussian(peak_power=[30.0]) lt: oc.Layout = oc.Layout() loss: float = 0.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)
chirps: List[float] = [0.0, 1.0] phase_shifts: List[Union[float, Callable]] = [oc.PI, lambda t: oc.PI / 2] y_datas_t: List[np.ndarray] = [] y_datas_nu: List[np.ndarray] = [] plot_groups: List[int] = [] plot_titles: List[str] = [] line_labels: List[Optional[str]] = [] pulse: oc.Gaussian mod: oc.IdealPhaseMod count: int = 0 for i, chirp in enumerate(chirps): for j, phase_shift in enumerate(phase_shifts): # Propagation pulse = oc.Gaussian(peak_power=[10.0], chirp=[chirp]) mod = oc.IdealPhaseMod(phase_shift=phase_shift) lt.add_link(pulse[0], mod[0]) lt.run(pulse) lt.reset() # Plot parameters and get waves y_datas_t.append(oc.temporal_phase(pulse[0][0].channels)) y_datas_t.append(oc.temporal_phase(mod[1][0].channels)) y_datas_nu.append(oc.spectral_phase(pulse[0][0].channels)) y_datas_nu.append(oc.spectral_phase(mod[1][0].channels)) plot_groups += [count, count] count += 1 line_labels += ["Original pulse", "Exit pulse"] if (isinstance(phase_shift, float)): temp_phase = phase_shift else:
from typing import Callable, List, Optional, Union import numpy as np import optcom as oc noise_samples: int = 100 lt: oc.Layout = oc.Layout( oc.Domain(bit_width=20.0, samples_per_bit=1024, noise_samples=noise_samples)) Lambda: float = 1030.0 pulse_1: oc.Gaussian = oc.Gaussian(channels=1, peak_power=[38.5, 0.5], fwhm=[1.], center_lambda=[Lambda], noise=np.ones(noise_samples) * 12) pulse_2: oc.Gaussian = oc.Gaussian(channels=1, peak_power=[23.5, 0.3], fwhm=[1.], center_lambda=[1050.0], noise=np.ones(noise_samples) * 5) steps: int = int(100) alpha: List[Union[List[float], Callable, None]] = [[0.046], [0.046]] beta_01: float = 1e5 beta_02: float = 1e5 beta: List[Union[List[float], Callable, None]] =\ [[beta_01,10.0,-0.0],[beta_02,10.0,-0.0]] gamma: List[Union[float, Callable, None]] = [4.3, 4.3]
center_lambda: List[float] = [1552.0, 1549.0, 1596.0] position: List[float] = [0.5, 0.3, 0.5] width: List[float] = [10.0, 5.3, 6] peak_power: List[float] = [1e-3, 2e-3, 6e-3] rep_freq: List[float] = [0.0, 0.03, 0.04] offset_nu: List[float] = [0.0, 0.56, -0.6] 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,
import optcom as oc plot_groups: List[int] = [] line_labels: List[Optional[str]] = [] plot_titles: List[str] = [] x_datas: List[np.ndarray] = [] y_datas: List[np.ndarray] = [] nlse_methods: List[str] = ["ssfm", "ssfm_reduced", "ssfm_symmetric", "ssfm_opti_reduced", "ssfm_super_sym", "ssfm_opti_super_sym", "rk4ip", "rk4ip"] # ---------------- NLSE solvers test ------------------------------- 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)
from typing import Callable, List, Optional import numpy as np import optcom as oc noise_samples = 200 domain: oc.Domain = oc.Domain(samples_per_bit=2048, bit_width=70.0, noise_samples=noise_samples) lt: oc.Layout = oc.Layout(domain) pulse: oc.Gaussian pulse = oc.Gaussian(channels=4, peak_power=[10.0, 10e-1, 5.0, 7.0], width=[0.1, 5.0, 3.0, 4.0], center_lambda=[1050.0, 1048.0, 1049.0, 1051.0], noise=np.ones(noise_samples) * 4) fiber = oc.Fiber(length=0.05, nlse_method="ssfm", alpha=[.46], nl_approx=False, ATT=True, DISP=True, gamma=10., SPM=True, XPM=False, SS=True, RS=True, XNL=False, approx_type=1,