small formatting

This commit is contained in:
James Powell
2018-10-05 21:12:57 -04:00
parent 23905a90f4
commit 7415744807
3 changed files with 30 additions and 43 deletions

View File

@@ -38,7 +38,7 @@ class NetworksResults(namedtuple('NetworksResult', 'elements connections')):
class ServicesResults(namedtuple('ServicesResult', 'requests synchronizations')):
def _asdict(self):
return {'requests': self.requests.asdict(),
return {'requests': self.requests.asdict(),
'synchronizations': self.synchronizations.asdict()}
def __str__(self):
return '\n'.join([

View File

@@ -4,16 +4,15 @@
# @Date: 2018-02-02 14:06:55
from gnpy.core.elements import Edfa
import numpy as np
from numpy import zeros, array
from json import load, dumps
import pytest
from gnpy.core.elements import Transceiver, Fiber, Edfa
from gnpy.core.utils import lin2db, db2lin
from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power, Pref
from gnpy.core.equipment import load_equipment
from gnpy.core.network import build_network, load_network, set_roadm_loss
from pathlib import Path
import filecmp
import pytest
TEST_DIR = Path(__file__).parent
DATA_DIR = TEST_DIR / 'data'
@@ -41,12 +40,8 @@ def setup_edfa_variable_gain():
network = load_network(test_network, equipment)
build_network(network, equipment,0, 20)
edfa = [n for n in network.nodes() if isinstance(n, Edfa)][0]
#edfa.params.dgt = np.zeros(96)
# edfa.params.gain_ripple = np.zeros(96)
# edfa.params.nf_ripple = np.zeros(96)
edfa.gain_ripple = np.zeros(96)
edfa.interpol_nf_ripple = np.zeros(96)
edfa.gain_ripple = zeros(96)
edfa.interpol_nf_ripple = zeros(96)
yield edfa
@pytest.fixture()
@@ -77,12 +72,12 @@ def si(nch_and_spacing, bw):
def test_variable_gain_nf(gain, nf_expected, setup_edfa_variable_gain, si):
"""=> unitary test for variable gain model Edfa._calc_nf() (and Edfa.interpol_params)"""
edfa = setup_edfa_variable_gain
frequencies = np.array([c.frequency for c in si.carriers])
pin = np.array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
frequencies = array([c.frequency for c in si.carriers])
pin = array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
pin = pin/db2lin(gain)
baud_rates = np.array([c.baud_rate for c in si.carriers])
baud_rates = array([c.baud_rate for c in si.carriers])
edfa.operational.gain_target = gain
pref=Pref(0, -gain)
pref = Pref(0, -gain)
edfa.interpol_params(frequencies, pin, baud_rates, pref)
result = edfa.nf
assert pytest.approx(nf_expected, abs=0.01) == result[0]
@@ -91,12 +86,12 @@ def test_variable_gain_nf(gain, nf_expected, setup_edfa_variable_gain, si):
def test_fixed_gain_nf(gain, nf_expected, setup_edfa_fixed_gain, si):
"""=> unitary test for fixed gain model Edfa._calc_nf() (and Edfa.interpol_params)"""
edfa = setup_edfa_fixed_gain
frequencies = np.array([c.frequency for c in si.carriers])
pin = np.array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
frequencies = array([c.frequency for c in si.carriers])
pin = array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
pin = pin/db2lin(gain)
baud_rates = np.array([c.baud_rate for c in si.carriers])
baud_rates = array([c.baud_rate for c in si.carriers])
edfa.operational.gain_target = gain
pref=Pref(0, -gain)
pref = Pref(0, -gain)
edfa.interpol_params(frequencies, pin, baud_rates, pref)
assert pytest.approx(nf_expected, abs=0.01) == edfa.nf[0]
@@ -104,8 +99,8 @@ def test_fixed_gain_nf(gain, nf_expected, setup_edfa_fixed_gain, si):
def test_si(si, nch_and_spacing):
"""basic total power check of the channel comb generation"""
nb_channel = nch_and_spacing[0]
pin = np.array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
p_tot = np.sum(pin)
pin = array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
p_tot = pin.sum()
expected_p_tot = si.carriers[0].power.signal * nb_channel
assert pytest.approx(expected_p_tot, abs=0.01) == p_tot
@@ -116,17 +111,14 @@ def test_compare_nf_models(gain, setup_edfa_variable_gain, si):
between gain_min and gain_flatmax some discrepancy is expected but target < 0.5dB
=> unitary test for Edfa._calc_nf (and Edfa.interpol_params)"""
edfa = setup_edfa_variable_gain
frequencies = np.array([c.frequency for c in si.carriers])
pin = np.array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
frequencies = array([c.frequency for c in si.carriers])
pin = array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
pin = pin/db2lin(gain)
baud_rates = np.array([c.baud_rate for c in si.carriers])
baud_rates = array([c.baud_rate for c in si.carriers])
edfa.operational.gain_target = gain
# edfa.params.nf_model_enabled = True
pref=Pref(0, -gain)
pref = Pref(0, -gain)
edfa.interpol_params(frequencies, pin, baud_rates, pref)
nf_model = edfa.nf[0]
# edfa.params.nf_model_enabled = False
edfa.interpol_params(frequencies, pin, baud_rates, pref)
nf_poly = edfa.nf[0]
assert pytest.approx(nf_model, abs=0.5) == nf_poly
@@ -139,20 +131,19 @@ def test_ase_noise(gain, si, setup_edfa_variable_gain, setup_trx, bw):
3-Transceiver osnr_ase_01nm
=> unitary test for Edfa.noise_profile (Edfa.interpol_params, Edfa.propagate)"""
edfa = setup_edfa_variable_gain
frequencies = np.array([c.frequency for c in si.carriers])
pin = np.array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
baud_rates = np.array([c.baud_rate for c in si.carriers])
frequencies = array([c.frequency for c in si.carriers])
pin = array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
baud_rates = array([c.baud_rate for c in si.carriers])
edfa.operational.gain_target = gain
# edfa.params.nf_model_enabled = False
pref=Pref(0, 0)
pref = Pref(0, 0)
edfa.interpol_params(frequencies, pin, baud_rates, pref)
nf = edfa.nf
pin = lin2db(pin[0]*1e3)
osnr_expected = pin - nf[0] + 58
si = edfa(si)
pout = np.array([c.power.signal for c in si.carriers])
pase = np.array([c.power.ase for c in si.carriers])
pout = array([c.power.signal for c in si.carriers])
pase = array([c.power.ase for c in si.carriers])
osnr = lin2db(pout[0] / pase[0]) - lin2db(12.5e9/bw)
assert pytest.approx(osnr_expected, abs=0.01) == osnr

View File

@@ -46,7 +46,7 @@ def propagation(input_power, con_in, con_out,dest):
transceivers = {n.uid: n for n in network.nodes() if isinstance(n, Transceiver)}
p = input_power
p=db2lin(p)*1e-3
p = db2lin(p) * 1e-3
spacing = 0.05 # THz
si = SpectralInformation() # SI units: W, Hz
si = si.update(carriers=[
@@ -56,18 +56,15 @@ def propagation(input_power, con_in, con_out,dest):
source = next(transceivers[uid] for uid in transceivers if uid == 'trx A')
sink = next(transceivers[uid] for uid in transceivers if uid == dest)
path = dijkstra_path(network, source, sink)
# print(f'\nPropagating with input power = {lin2db(p*1e3):.2f}dBm :')
for el in path:
si = el(si)
# if isinstance(el, Edfa):
# nf = mean(el.nf)
print(el) #remove this line when sweeping across several powers
# print(f'\nTransmission result for input power = {lin2db(p*1e3):.2f}dBm :')
print(el) # remove this line when sweeping across several powers
edfa_sample = next(el for el in path if isinstance(el, Edfa))
nf = mean(edfa_sample.nf)
print(f'pw: {input_power} conn in: {con_in} con out: {con_out} ' +
f'OSNR@0.1nm: {round(mean(sink.osnr_ase_01nm),2)} SNR@bandwitdth: {round(mean(sink.snr),2)}')
print(f'pw: {input_power} conn in: {con_in} con out: {con_out}',
f'OSNR@0.1nm: {round(mean(sink.osnr_ase_01nm),2)}',
f'SNR@bandwitdth: {round(mean(sink.snr),2)}')
return sink , nf
test = {'a':(-1,1,0),'b':(-1,1,1),'c':(0,1,0),'d':(1,1,1)}
@@ -99,7 +96,6 @@ if __name__ == '__main__':
logger = getLogger(__name__)
basicConfig(level=INFO)
#logger.info(f'Running {test}')
for a in test :
test_snr(a,'trx F')
print('\n')