Skip to content

Commit

Permalink
Remove defaul_edfa_config.json dictionnary and use parameters.py
Browse files Browse the repository at this point in the history
But enable the user to still input its own default file with a new
'default_config_from_json' attribute useable in fixed and variable gain
amplifiers.

Signed-off-by: EstherLerouzic <[email protected]>
Change-Id: I773682ae6daa1025007fc051582e779986982838
  • Loading branch information
EstherLerouzic committed Dec 9, 2024
1 parent 4b50ee0 commit 2ad4b78
Show file tree
Hide file tree
Showing 9 changed files with 421 additions and 418 deletions.
7 changes: 5 additions & 2 deletions docs/json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ For all single band amplifier models:
| | | within this range (center frequency and |
| | | spectrum width). |
| | | Default is 191.275e-12 Hz and |
| | | 196.125e-12 (tunable in |
| | | default_edfa_config.json) |
| | | 196.125e-12. |
+------------------------+-----------+-----------------------------------------+

Default values are defined for frequency range but also for noise figure ripple, gain ripple, and dynamic gain tilt.
Users can modify these value by using ``default_config_from_json`` which should be populated with a filename that
contains the desired configuration.


For multi_band amplifier models:

Expand Down
10 changes: 10 additions & 0 deletions docs/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ Release change log
Each release introduces some changes and new features.

(prepare text for next release)
**Important Changes:**

The default values for EDFA configuration, including frequency range, gain ripple, noise figure ripple, or dynamic gain tilt
are now hardcoded in parameters.py and are no longer read from the default_edfa_config.json file (the file has been removed).
However, users may define their own default configuration using 'default_config_from_json' parameter, which should
be populated with a filename that contains the desired configuration. This applies to both variable_gain
or fixed_gain amplifier types.

This change streamlines the configuration process but requires users to explicitly set parameters through the new
model if the default values do not suit their needs.

v2.11
-----
Expand Down
37 changes: 36 additions & 1 deletion gnpy/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ def __init__(self, **params):
else:
self.nf_ripple = asarray(nf_ripple)
if self.nf_ripple.size != self.gain_ripple.size:
raise ParametersError("The noise figure ripple and the gain ripple must have the same size.")
raise ParametersError(
"The noise figure ripple and the gain ripple must have the same size. %s, %s",
self.nf_ripple.size, self.gain_ripple.size)

# VOA
self.out_voa_auto = params['out_voa_auto']
Expand Down Expand Up @@ -626,6 +628,39 @@ def __repr__(self):
f'tilt_target={self.tilt_target!r})')


DEFAULT_EDFA_CONFIG = {
"nf_ripple": [
0.0
],
"gain_ripple": [
0.0
],
"f_min": 191.275e12,
"f_max": 196.125e12,
"dgt": [
1.0, 1.017807767853702, 1.0356155337864215, 1.0534217504465226, 1.0712204022764056, 1.0895983485572227,
1.108555289615659, 1.1280891949729075, 1.1476135933863398, 1.1672278304018044, 1.1869318618366975,
1.2067249615595257, 1.2264996957264114, 1.2428104897182262, 1.2556591482982988, 1.2650555289898042,
1.2744470198196236, 1.2838336236692311, 1.2932153453410835, 1.3040618749785347, 1.316383926863083,
1.3301807335621048, 1.3439818461440451, 1.3598972673004606, 1.3779439775587023, 1.3981208704326855,
1.418273806730323, 1.4340878115214444, 1.445565137158368, 1.45273959485914, 1.4599103316162523,
1.4670307626366115, 1.474100442252211, 1.48111939735681, 1.488134243479226, 1.495145456062699,
1.502153039909686, 1.5097346239790443, 1.5178910621476225, 1.5266220576235803, 1.5353620432989845,
1.545374152761467, 1.5566577309558969, 1.569199764184379, 1.5817353179379183, 1.5986915141218316,
1.6201194134191075, 1.6460167077689267, 1.6719047669939942, 1.6918150918099673, 1.7057507692361864,
1.7137640932265894, 1.7217732861435076, 1.7297783508684146, 1.737780757913635, 1.7459181197626403,
1.7541903672600494, 1.7625959636196327, 1.7709972329654864, 1.7793941781790852, 1.7877868031023945,
1.7961751115773796, 1.8045606557581335, 1.8139629377087627, 1.824381436842932, 1.835814081380705,
1.847275503201129, 1.862235672444246, 1.8806927939516411, 1.9026104247588487, 1.9245345552113182,
1.9482128147680253, 1.9736443063300082, 2.0008103857988204, 2.0279625371819305, 2.055100772005235,
2.082225099873648, 2.1183028432496016, 2.16337565384239, 2.2174389328192197, 2.271520771371253,
2.322373696229342, 2.3699990328716107, 2.414398437185221, 2.4587748041127506, 2.499446286796604,
2.5364027376452056, 2.5696460593920065, 2.602860350286428, 2.630396440815385, 2.6521732021128046,
2.6681935771243177, 2.6841217449620203, 2.6947834587664494, 2.705443819238505, 2.714526681131686
]
}


class MultiBandParams:
default_values = {
'bands': [],
Expand Down
108 changes: 0 additions & 108 deletions gnpy/example-data/default_edfa_config.json

This file was deleted.

25 changes: 16 additions & 9 deletions gnpy/tools/json_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from gnpy.core.science_utils import estimate_nf_model
from gnpy.core.info import Carrier
from gnpy.core.utils import automatic_nch, automatic_fmax, merge_amplifier_restrictions, dbm2watt
from gnpy.core.parameters import DEFAULT_RAMAN_COEFFICIENT, EdfaParams, MultiBandParams
from gnpy.core.parameters import DEFAULT_RAMAN_COEFFICIENT, EdfaParams, MultiBandParams, DEFAULT_EDFA_CONFIG
from gnpy.topology.request import PathRequest, Disjunction, compute_spectrum_slot_vs_bandwidth
from gnpy.topology.spectrum_assignment import mvalue_to_slots
from gnpy.tools.convert import xls_to_json_data
Expand Down Expand Up @@ -215,15 +215,19 @@ def __init__(self, **kwargs):
def from_json(cls, filename, **kwargs):
"""
"""
config = Path(filename).parent / 'default_edfa_config.json'
# default_edfa_config.json assumes a DGT profile independantly from fmin/fmax, that's a generic profile
# default EDFA DGT and ripples are defined in parameters DEFAULT_EDFA_CONFIG. copy these values when
# creating a new amplifier
config = {k: v for k, v in DEFAULT_EDFA_CONFIG.items()}
type_variety = kwargs['type_variety']
type_def = kwargs.get('type_def', 'variable_gain') # default compatibility with older json eqpt files
nf_def = None
dual_stage_def = None
amplifiers = None

if type_def == 'fixed_gain':
if 'default_config_from_json' in kwargs:
# use user defined default instead of DEFAULT_EDFA_CONFIG
config = load_json(Path(filename).parent / kwargs.pop('default_config_from_json'))
try:
nf0 = kwargs.pop('nf0')
except KeyError as exc: # nf0 is expected for a fixed gain amp
Expand All @@ -236,8 +240,12 @@ def from_json(cls, filename, **kwargs):
pass
nf_def = Model_fg(nf0)
elif type_def == 'advanced_model':
config = Path(filename).parent / kwargs.pop('advanced_config_from_json')
# use the user file name define in library instead of default config
config = load_json(Path(filename).parent / kwargs.pop('advanced_config_from_json'))
elif type_def == 'variable_gain':
if 'default_config_from_json' in kwargs:
# use user defined default instead of DEFAULT_EDFA_CONFIG
config = load_json(Path(filename).parent / kwargs.pop('default_config_from_json'))
gain_min, gain_max = kwargs['gain_min'], kwargs['gain_flatmax']
try: # nf_min and nf_max are expected for a variable gain amp
nf_min = kwargs.pop('nf_min')
Expand Down Expand Up @@ -274,16 +282,15 @@ def from_json(cls, filename, **kwargs):
else:
raise EquipmentConfigError(f'Edfa type_def {type_def} does not exist')

json_data = load_json(config)
# raise an error if config does not contain f_min, f_max
if 'f_min' not in json_data or 'f_max' not in json_data:
if 'f_min' not in config or 'f_max' not in config:
raise EquipmentConfigError('default Edfa config does not contain f_min and f_max values.'
+ ' Please correct file.')
# use f_min, f_max from kwargs
if 'f_min' in kwargs:
json_data.pop('f_min', None)
json_data.pop('f_max', None)
return cls(**{**kwargs, **json_data,
config.pop('f_min', None)
config.pop('f_max', None)
return cls(**{**kwargs, **config,
'nf_model': nf_def, 'dual_stage_model': dual_stage_def, 'multi_band': amplifiers})


Expand Down
31 changes: 31 additions & 0 deletions tests/data/copy_default_edfa_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"nf_ripple": [
0.0
],
"gain_ripple": [
0.0
],
"f_min": 191.275e12,
"f_max": 196.125e12,
"dgt": [
1.0, 1.017807767853702, 1.0356155337864215, 1.0534217504465226, 1.0712204022764056, 1.0895983485572227,
1.108555289615659, 1.1280891949729075, 1.1476135933863398, 1.1672278304018044, 1.1869318618366975,
1.2067249615595257, 1.2264996957264114, 1.2428104897182262, 1.2556591482982988, 1.2650555289898042,
1.2744470198196236, 1.2838336236692311, 1.2932153453410835, 1.3040618749785347, 1.316383926863083,
1.3301807335621048, 1.3439818461440451, 1.3598972673004606, 1.3779439775587023, 1.3981208704326855,
1.418273806730323, 1.4340878115214444, 1.445565137158368, 1.45273959485914, 1.4599103316162523,
1.4670307626366115, 1.474100442252211, 1.48111939735681, 1.488134243479226, 1.495145456062699,
1.502153039909686, 1.5097346239790443, 1.5178910621476225, 1.5266220576235803, 1.5353620432989845,
1.545374152761467, 1.5566577309558969, 1.569199764184379, 1.5817353179379183, 1.5986915141218316,
1.6201194134191075, 1.6460167077689267, 1.6719047669939942, 1.6918150918099673, 1.7057507692361864,
1.7137640932265894, 1.7217732861435076, 1.7297783508684146, 1.737780757913635, 1.7459181197626403,
1.7541903672600494, 1.7625959636196327, 1.7709972329654864, 1.7793941781790852, 1.7877868031023945,
1.7961751115773796, 1.8045606557581335, 1.8139629377087627, 1.824381436842932, 1.835814081380705,
1.847275503201129, 1.862235672444246, 1.8806927939516411, 1.9026104247588487, 1.9245345552113182,
1.9482128147680253, 1.9736443063300082, 2.0008103857988204, 2.0279625371819305, 2.055100772005235,
2.082225099873648, 2.1183028432496016, 2.16337565384239, 2.2174389328192197, 2.271520771371253,
2.322373696229342, 2.3699990328716107, 2.414398437185221, 2.4587748041127506, 2.499446286796604,
2.5364027376452056, 2.5696460593920065, 2.602860350286428, 2.630396440815385, 2.6521732021128046,
2.6681935771243177, 2.6841217449620203, 2.6947834587664494, 2.705443819238505, 2.714526681131686
]
}
Loading

0 comments on commit 2ad4b78

Please sign in to comment.