def read_eqpt_library(filename): """build global dictionnary eqpt_library that stores all eqpt characteristics: edfa type type_variety, fiber type_variety from the eqpt_config.json (filename parameter) also read advanced_config_from_json file parameters for edfa if they are available: typically nf_ripple, dfg gain ripple, dgt and nf polynomial nf_fit_coeff if advanced_config_from_json file parameter is not present: use nf_model: requires nf_min and nf_max values boundaries of the edfa gain range """ global eqpt_library eqpt_library = load_json(filename) for i, el in enumerate(eqpt_library['Edfa']): dict_nf_model = {} if 'advanced_config_from_json' in el: #use advanced amplifier model with full ripple characterization config_json_filename = el.pop(ADVANCED_CONFIG_JSON_FILENAME) dict_nf_model['nf_model'] = {'enabled': False} else: #use a default ripple model (only default dgt is defined) config_json_filename = DEFAULT_CONFIG_JSON_FILENAME (nf1, nf2, delta_p) = nf_model(el) #remove nf_min and nf_max field and replace by nf1, nf2 & delta_p nf_min = el.pop('nf_min','') nf_max = el.pop('nf_max','') dict_nf_model['nf_model'] = {"enabled": True, "nf1": nf1, "nf2": nf2, "delta_p": delta_p} json_data = load_json(Path(filename).parent / config_json_filename) eqpt_library['Edfa'][i] = {**el, **json_data, **dict_nf_model}
def load_network(filename, equipment, name_matching = False): json_filename = '' if filename.suffix.lower() == '.xls': logger.info('Automatically generating topology JSON file') json_filename = convert_file(filename, name_matching) elif filename.suffix.lower() == '.json': json_filename = filename else: raise ValueError(f'unsuported topology filename extension {filename.suffix.lower()}') json_data = load_json(json_filename) return network_from_json(json_data, equipment)
def main(args): input_filename = str(args.filename) split_filename = input_filename.split(".") json_filename = split_filename[0] + '.json' try: assert split_filename[1] in ('json', 'xls', 'csv', 'xlsm') except AssertionError as e: print(f'invalid file extension .{split_filename[1]}') raise e if split_filename[1] != 'json': print(f'parse excel input to {json_filename}') convert_file(input_filename) json_data = load_json(json_filename) read_eqpt_library(EQPT_LIBRARY_FILENAME) network = network_from_json(json_data) build_network(network) spacing = 0.05 #THz si = SpectralInformation() # !! SI units W, Hz si = si.update(carriers=tuple( Channel(f, (191.3 + spacing * f) * 1e12, 32e9, 0.15, Power(1e-3, 0, 0)) for f in range(1, 97))) trx = [n for n in network.nodes() if isinstance(n, Transceiver)] if args.list >= 1: print(*[el.uid for el in trx], sep='\n') else: try: source = next(el for el in trx if el.uid == args.source) except StopIteration as e: source = trx[0] print( f'invalid souce node specified: {args.source!r}, replaced with {source}' ) try: sink = next(el for el in trx if el.uid == args.sink) except StopIteration as e: sink = trx[1] print( f'invalid destination node specified: {args.sink!r}, replaced with {sink}' ) path = dijkstra_path(network, source, sink) print( f'There are {len(path)} network elements between {source} and {sink}' ) for el in path: si = el(si) print(el)
def test_no_amp_feature(node_uid): ''' Check that booster is not placed on a roadm if fused is specified test_parser covers partly this behaviour. This test should guaranty that the feature is preserved even if convert is changed ''' equipment = load_equipment(EQPT_LIBRARY_NAME) json_network = load_json(NETWORK_FILE_NAME) for elem in json_network['elements']: if elem['uid'] == node_uid: #replace edfa node by a fused node in the topology elem['type'] = 'Fused' elem.pop('type_variety') elem.pop('operational') elem['params'] = {'loss': 0} next_node_uid = next(conn['to_node'] for conn in json_network['connections'] \ if conn['from_node'] == node_uid) previous_node_uid = next(conn['from_node'] for conn in json_network['connections'] \ if conn['to_node'] == node_uid) network = network_from_json(json_network, equipment) # Build the network once using the default power defined in SI in eqpt config # power density : db2linp(ower_dbm": 0)/power_dbm": 0 * nb channels as defined by # spacing, f_min and f_max p_db = equipment['SI']['default'].power_dbm p_total_db = p_db + lin2db(automatic_nch(equipment['SI']['default'].f_min,\ equipment['SI']['default'].f_max, equipment['SI']['default'].spacing)) build_network(network, equipment, p_db, p_total_db) node = next(nd for nd in network.nodes() if nd.uid == node_uid) next_node = next(network.successors(node)) previous_node = next(network.predecessors(node)) if not isinstance(node, Fused): raise AssertionError() if not node.params.loss == 0.0: raise AssertionError() if not next_node_uid == next_node.uid: raise AssertionError() if not previous_node_uid == previous_node.uid: raise AssertionError()
def post(self): data = request.get_json() equipment = load_equipment('examples/2019-demo-equipment.json') topo_json = load_json('examples/2019-demo-topology.json') network = network_from_json(topo_json, equipment) try: propagatedpths, reversed_propagatedpths, rqs = compute_requests( network, data, equipment) # Generate the output result = [] #assumes that list of rqs and list of propgatedpths have same order for i, pth in enumerate(propagatedpths): result.append( Result_element(rqs[i], pth, reversed_propagatedpths[i])) return {"result": path_result_json(result)}, 201 except ServiceError as this_e: msg = f'Service error: {this_e}' return {"result": msg}, 400
def load_equipment(filename): json_data = load_json(filename) return equipment_from_json(json_data, filename)
def test_restrictions(restrictions, equipment): ''' test that restriction is correctly applied if provided in eqpt_config and if no Edfa type were provided in the network json ''' # add restrictions equipment['Roadm']['default'].restrictions = restrictions # build network json_network = load_json(NETWORK_FILE_NAME) network = network_from_json(json_network, equipment) amp_nodes_nobuild_uid = [nd.uid for nd in network.nodes() \ if isinstance(nd, Edfa) and isinstance(next(network.predecessors(nd)), Roadm)] preamp_nodes_nobuild_uid = [nd.uid for nd in network.nodes() \ if isinstance(nd, Edfa) and isinstance(next(network.successors(nd)), Roadm)] amp_nodes_nobuild = {nd.uid : nd for nd in network.nodes() \ if isinstance(nd, Edfa) and isinstance(next(network.predecessors(nd)), Roadm)} preamp_nodes_nobuild = {nd.uid : nd for nd in network.nodes() \ if isinstance(nd, Edfa) and isinstance(next(network.successors(nd)), Roadm)} # roadm dict with restrictions before build roadms = {nd.uid: nd for nd in network.nodes() if isinstance(nd, Roadm)} # Build the network once using the default power defined in SI in eqpt config # power density : db2linp(ower_dbm": 0)/power_dbm": 0 * nb channels as defined by # spacing, f_min and f_max p_db = equipment['SI']['default'].power_dbm p_total_db = p_db + lin2db(automatic_nch(equipment['SI']['default'].f_min,\ equipment['SI']['default'].f_max, equipment['SI']['default'].spacing)) build_network(network, equipment, p_db, p_total_db) amp_nodes = [nd for nd in network.nodes() \ if isinstance(nd, Edfa) and isinstance(next(network.predecessors(nd)), Roadm)\ and next(network.predecessors(nd)).restrictions['booster_variety_list']] preamp_nodes = [nd for nd in network.nodes() \ if isinstance(nd, Edfa) and isinstance(next(network.successors(nd)), Roadm)\ and next(network.successors(nd)).restrictions['preamp_variety_list']] # check that previously existing amp are not changed for amp in amp_nodes: if amp.uid in amp_nodes_nobuild_uid: print(amp.uid, amp.params.type_variety) if not amp.params.type_variety == amp_nodes_nobuild[ amp.uid].params.type_variety: raise AssertionError() for amp in preamp_nodes: if amp.uid in preamp_nodes_nobuild_uid: if not amp.params.type_variety == preamp_nodes_nobuild[ amp.uid].params.type_variety: raise AssertionError() # check that restrictions are correctly applied for amp in amp_nodes: if amp.uid not in amp_nodes_nobuild_uid: # and if roadm had no restrictions before build: if restrictions['booster_variety_list'] and \ not roadms[next(network.predecessors(amp)).uid]\ .restrictions['booster_variety_list']: if not amp.params.type_variety in restrictions[ 'booster_variety_list']: raise AssertionError() for amp in preamp_nodes: if amp.uid not in preamp_nodes_nobuild_uid: if restrictions['preamp_variety_list'] and\ not roadms[next(network.successors(amp)).uid].restrictions['preamp_variety_list']: if not amp.params.type_variety in restrictions[ 'preamp_variety_list']: raise AssertionError()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import numpy as np from gnpy.core.utils import (load_json, itufs, freq2wavelength, lin2db, db2lin) from gnpy.core import network topology = load_json('edfa_example_network.json') nw = network.network_from_json(topology) pch2d_legend_data = np.loadtxt('Pchan2DLegend.txt') pch2d = np.loadtxt('Pchan2D.txt') ch_spacing = 0.05 fc = itufs(ch_spacing) lc = freq2wavelength(fc) / 1000 nchan = np.arange(len(lc)) df = np.ones(len(lc)) * ch_spacing edfa1 = [n for n in nw.nodes() if n.uid == 'Edfa1'][0] edfa1.gain_target = 20.0 edfa1.tilt_target = -0.7 edfa1.calc_nf() results = [] for Pin in pch2d:
def load_sim_params(filename): sim_params = load_json(filename) return SimParams(params=sim_params)