diff --git a/gnpy/core/elements.py b/gnpy/core/elements.py index 1ebab40b6..43cec06e3 100644 --- a/gnpy/core/elements.py +++ b/gnpy/core/elements.py @@ -699,7 +699,7 @@ def __init__(self, *args, params=None, operational=None, **kwargs): self.pin_db = None self.nch = None self.pout_db = None - self.target_pch_out_db = None + self.target_pch_out_dbm = None self.effective_pch_out_db = None self.passive = False self.att_in = None @@ -759,7 +759,8 @@ def __str__(self): f' Power In (dBm): {self.pin_db:.2f}', f' Power Out (dBm): {self.pout_db:.2f}', f' Delta_P (dB): ' + (f'{self.delta_p:.2f}' if self.delta_p is not None else 'None'), - f' target pch (dBm): ' + (f'{self.target_pch_out_db:.2f}' if self.target_pch_out_db is not None else 'None'), + ' target pch (dBm): ' + + (f'{self.target_pch_out_dbm:.2f}' if self.target_pch_out_dbm is not None else 'None'), f' actual pch out (dBm): {total_pch}', f' output VOA (dB): {self.out_voa:.2f}']) @@ -787,16 +788,6 @@ def interpol_params(self, spectral_info): # For now, with homogeneous spectrum, we can calculate it as the difference between neighbouring channels. self.slot_width = self.channel_freq[1] - self.channel_freq[0] - """in power mode: delta_p is defined and can be used to calculate the power target - This power target correspond to the channel used for design""" - pref = spectral_info.pref - if self.delta_p is not None and self.operational.delta_p is not None: - # use the user defined target - self.target_pch_out_db = round(self.operational.delta_p + pref.p_span0, 2) - elif self.delta_p is not None: - # use the design target if no target were set - self.target_pch_out_db = round(self.delta_p + pref.p_span0, 2) - """check power saturation and correct effective gain & power accordingly:""" # Compute the saturation accounting for actual power at the input of the amp self.effective_gain = min( diff --git a/gnpy/core/info.py b/gnpy/core/info.py index 725e5b1cd..e7b11299f 100644 --- a/gnpy/core/info.py +++ b/gnpy/core/info.py @@ -45,10 +45,9 @@ class Channel( """ -class Pref(namedtuple('Pref', 'p_span0, ref_carrier')): - """noiseless reference power in dBm: +class Pref(namedtuple('Pref', 'ref_carrier')): + """reference channel used during design: - p_span0: inital target carrier power for a reference channel defined by user ref_carrier records the baud rate of the reference channel """ @@ -238,9 +237,6 @@ def __add__(self, other: SpectralInformation): try: # Note that pref.p_spanx from "self" and "other" must be identical for a given simulation (correspond to the # the simulation setup): - # - for a given simulation there is only one design (one p_span0), - if (self.pref.p_span0 != other.pref.p_span0): - raise SpectrumError('reference powers of the spectrum are not identical') return SpectralInformation(frequency=append(self.frequency, other.frequency), slot_width=append(self.slot_width, other.slot_width), signal=append(self.signal, other.signal), nli=append(self.nli, other.nli), @@ -255,7 +251,7 @@ def __add__(self, other: SpectralInformation): delta_pdb_per_channel=append(self.delta_pdb_per_channel, other.delta_pdb_per_channel), tx_osnr=append(self.tx_osnr, other.tx_osnr), - ref_power=Pref(self.pref.p_span0, self.pref.ref_carrier), + ref_power=Pref(self.pref.ref_carrier), label=append(self.label, other.label)) except SpectrumError: raise SpectrumError('Spectra cannot be summed: channels overlapping.') @@ -326,13 +322,12 @@ def create_input_spectral_information(f_min, f_max, roll_off, baud_rate, power, all arguments are scalar values""" number_of_channels = automatic_nch(f_min, f_max, spacing) frequency = [(f_min + spacing * i) for i in range(1, number_of_channels + 1)] - p_span0 = watt2dbm(power) delta_pdb_per_channel = delta_pdb * ones(number_of_channels) label = [f'{baud_rate * 1e-9 :.2f}G' for i in range(number_of_channels)] return create_arbitrary_spectral_information(frequency, slot_width=spacing, signal=power, baud_rate=baud_rate, roll_off=roll_off, delta_pdb_per_channel=delta_pdb_per_channel, tx_osnr=tx_osnr, - ref_power=Pref(p_span0=p_span0, ref_carrier=ref_carrier), + ref_power=Pref(ref_carrier=ref_carrier), label=label) @@ -356,7 +351,7 @@ def carriers_to_spectral_information(initial_spectrum: dict[float, Carrier], pow return create_arbitrary_spectral_information(frequency=frequency, signal=signal, baud_rate=baud_rate, slot_width=slot_width, roll_off=roll_off, delta_pdb_per_channel=delta_pdb_per_channel, tx_osnr=tx_osnr, - ref_power=Pref(p_span0=p_span0, ref_carrier=ref_carrier), + ref_power=Pref(ref_carrier=ref_carrier), label=label) diff --git a/gnpy/core/network.py b/gnpy/core/network.py index cc17309c3..222984f04 100644 --- a/gnpy/core/network.py +++ b/gnpy/core/network.py @@ -368,10 +368,23 @@ def set_egress_amplifier(network, this_node, equipment, pref_ch_db, pref_total_d node.delta_p = dp if power_mode else None node.effective_gain = gain_target + # if voa is not set, then set it and possibly optimize it with gain and update delta_p and + # effective_gain values set_amplifier_voa(node, power_target, power_mode) # set_amplifier_voa may change delta_p in power_mode node._delta_p = node.delta_p if power_mode else dp + # target_pch_out_dbm records target power for design: If user defines one, then this is displayed, + # else display the one computed during design + if node.delta_p is not None and node.operational.delta_p is not None: + # use the user defined target + node.target_pch_out_dbm = round(node.operational.delta_p + pref_ch_db, 2) + elif node.delta_p is not None: + # use the design target if no target were set + node.target_pch_out_dbm = round(node.delta_p + pref_ch_db, 2) + elif node.delta_p is None: + node.target_pch_out_dbm = None + prev_dp = dp prev_voa = voa prev_node = node diff --git a/tests/test_amplifier.py b/tests/test_amplifier.py index 8d68ff463..b80b9c10c 100644 --- a/tests/test_amplifier.py +++ b/tests/test_amplifier.py @@ -128,7 +128,6 @@ def test_compare_nf_models(gain, setup_edfa_variable_gain, si): edfa.operational.gain_target = gain edfa.effective_gain = gain # edfa is variable gain type - si.pref = si.pref._replace(p_span0=0) edfa.interpol_params(si) nf_model = edfa.nf[0] @@ -183,7 +182,6 @@ def test_ase_noise(gain, si, setup_trx, bw): si = span(si) print(span) - si.pref = si.pref._replace(p_span0=0) edfa.interpol_params(si) nf = edfa.nf print('nf', nf) @@ -322,7 +320,7 @@ def test_amp_saturation(delta_pdb_per_channel, base_power, delta_p): baud_rate = array([32e9, 42e9, 64e9, 42e9, 32e9]) signal = dbm2watt(array([-20.0, -18.0, -22.0, -25.0, -16.0]) + array(delta_pdb_per_channel) + base_power) ref_carrier = ReferenceCarrier(baud_rate=32e9, slot_width=50e9) - pref = Pref(p_span0=0, ref_carrier=ref_carrier) + pref = Pref(ref_carrier=ref_carrier) si = create_arbitrary_spectral_information(frequency=frequency, slot_width=slot_width, signal=signal, baud_rate=baud_rate, roll_off=0.15, delta_pdb_per_channel=delta_pdb_per_channel, diff --git a/tests/test_equalization.py b/tests/test_equalization.py index 0f51beaee..819f644a6 100644 --- a/tests/test_equalization.py +++ b/tests/test_equalization.py @@ -79,7 +79,7 @@ def test_equalization_combination_degree(delta_pdb_per_channel, degree, equaliza baud_rate = array([32e9, 42e9, 64e9, 42e9, 32e9]) signal = dbm2watt(array([-20.0, -18.0, -22.0, -25.0, -16.0])) ref_carrier = ReferenceCarrier(baud_rate=32e9, slot_width=50e9) - pref = Pref(p_span0=0, ref_carrier=ref_carrier) + pref = Pref(ref_carrier=ref_carrier) si = create_arbitrary_spectral_information(frequency=frequency, slot_width=slot_width, signal=signal, baud_rate=baud_rate, roll_off=0.15, delta_pdb_per_channel=delta_pdb_per_channel, @@ -217,7 +217,7 @@ def test_low_input_power(target_out, delta_pdb_per_channel, correction): signal = dbm2watt(array([-20.0, -18.0, -22.0, -25.0, -16.0])) target = target_out + array(delta_pdb_per_channel) ref_carrier = ReferenceCarrier(baud_rate=32e9, slot_width=50e9) - pref = Pref(p_span0=0, ref_carrier=ref_carrier) + pref = Pref(ref_carrier=ref_carrier) si = create_arbitrary_spectral_information(frequency=frequency, slot_width=slot_width, signal=signal, baud_rate=baud_rate, roll_off=0.15, delta_pdb_per_channel=delta_pdb_per_channel, @@ -270,7 +270,7 @@ def test_2low_input_power(target_out, delta_pdb_per_channel, correction): signal = dbm2watt(array([-20.0, -18.0, -22.0, -25.0, -16.0])) target = psd2powerdbm(target_out, baud_rate) + array(delta_pdb_per_channel) ref_carrier = ReferenceCarrier(baud_rate=32e9, slot_width=50e9) - pref = Pref(p_span0=0, ref_carrier=ref_carrier) + pref = Pref(ref_carrier=ref_carrier) si = create_arbitrary_spectral_information(frequency=frequency, slot_width=slot_width, signal=signal, baud_rate=baud_rate, roll_off=0.15, delta_pdb_per_channel=delta_pdb_per_channel, diff --git a/tests/test_info.py b/tests/test_info.py index 1ad32873b..67cf4f4c3 100644 --- a/tests/test_info.py +++ b/tests/test_info.py @@ -13,7 +13,7 @@ def test_create_arbitrary_spectral_information(): baud_rate=32e9, signal=[1, 1, 1], delta_pdb_per_channel=[1, 1, 1], tx_osnr=40.0, - ref_power=Pref(1, None)) + ref_power=Pref(None)) assert_array_equal(si.baud_rate, array([32e9, 32e9, 32e9])) assert_array_equal(si.slot_width, array([37.5e9, 37.5e9, 37.5e9])) assert_array_equal(si.signal, ones(3)) @@ -35,7 +35,7 @@ def test_create_arbitrary_spectral_information(): slot_width=array([50e9, 50e9, 50e9]), baud_rate=32e9, signal=array([1, 2, 3]), tx_osnr=40.0, - ref_power=Pref(1, None)) + ref_power=Pref(None)) assert_array_equal(si.signal, array([3, 2, 1])) @@ -44,16 +44,16 @@ def test_create_arbitrary_spectral_information(): create_arbitrary_spectral_information(frequency=[193.25e12, 193.3e12, 193.35e12], signal=1, baud_rate=[64e9, 32e9, 64e9], slot_width=50e9, tx_osnr=40.0, - ref_power=Pref(1, None)) + ref_power=Pref(None)) with pytest.raises(SpectrumError, match='Spectrum required slot widths larger than the frequency spectral ' r'distances between channels: \[\(1, 2\), \(3, 4\)\].'): create_arbitrary_spectral_information(frequency=[193.26e12, 193.3e12, 193.35e12, 193.39e12], signal=1, - tx_osnr=40.0, baud_rate=32e9, slot_width=50e9, ref_power=Pref(1, None)) + tx_osnr=40.0, baud_rate=32e9, slot_width=50e9, ref_power=Pref(None)) with pytest.raises(SpectrumError, match='Spectrum required slot widths larger than the frequency spectral ' r'distances between channels: \[\(1, 2\), \(2, 3\)\].'): create_arbitrary_spectral_information(frequency=[193.25e12, 193.3e12, 193.35e12], signal=1, baud_rate=49e9, - tx_osnr=40.0, roll_off=0.1, ref_power=Pref(1, None)) + tx_osnr=40.0, roll_off=0.1, ref_power=Pref(None)) with pytest.raises(SpectrumError, match='Dimension mismatch in input fields.'): create_arbitrary_spectral_information(frequency=[193.25e12, 193.3e12, 193.35e12], signal=[1, 2], baud_rate=49e9, - tx_osnr=40.0, ref_power=Pref(1, None)) + tx_osnr=40.0, ref_power=Pref(None)) diff --git a/tests/test_roadm_restrictions.py b/tests/test_roadm_restrictions.py index 90ca0f688..3c7f29851 100644 --- a/tests/test_roadm_restrictions.py +++ b/tests/test_roadm_restrictions.py @@ -493,12 +493,12 @@ def test_compare_design_propagation_settings(power_dbm, req_power, amp_with_delt else: dp = element.out_voa if element.uid not in amp_with_deltap_one else element.out_voa + 1 # check that target power is correctly set - assert element.target_pch_out_db == req_power + dp + assert element.target_pch_out_dbm == req_power + dp # check that designed gain is exactly applied except if target power exceeds max power, then # gain is slightly less than the one computed during design for the noiseless reference, # because during propagation, noise has accumulated, additing to signal. # check that delta_p is unchanged unless for saturation - if element.target_pch_out_db > pch_max: + if element.target_pch_out_dbm > pch_max: assert element.effective_gain == pytest.approx(element_copy.effective_gain, abs=2e-2) else: assert element.effective_gain == element_copy.effective_gain diff --git a/tests/test_science_utils.py b/tests/test_science_utils.py index b9201debb..9cacd1a88 100644 --- a/tests/test_science_utils.py +++ b/tests/test_science_utils.py @@ -47,7 +47,7 @@ def test_fiber(): baud_rate = array([32e9, 42e9, 64e9, 42e9, 32e9]) signal = 1e-3 + array([0, -1e-4, 3e-4, -2e-4, +2e-4]) delta_pdb_per_channel = [0, 0, 0, 0, 0] - pref = Pref(p_span0=0, ref_carrier=None) + pref = Pref(ref_carrier=None) spectral_info_input = create_arbitrary_spectral_information(frequency=frequency, slot_width=slot_width, signal=signal, baud_rate=baud_rate, roll_off=0.15, delta_pdb_per_channel=delta_pdb_per_channel,