Ambiguous default value initialized for params.forcing.key_forced
Created originally on Bitbucket by avmo (Ashwin Vishnu)
I had assumed for a long time that the default key_forced
was initialized based on the value set for params.forcing.type
. Apparently that is not the case, since it depends on which class is initialized last.
This can lead to unpredictable behaviour when a new Forcing class is included.
Relevant code.
#!python
class ForcingSW1L(ForcingBasePseudoSpectral):
@staticmethod
def _complete_info_solver(info_solver):
"""Complete the ParamContainer info_solver.
This is a static method!
"""
classes = [Proportional, TimeCorrelatedRandomPseudoSpectral, Waves]
ForcingBasePseudoSpectral._complete_info_solver(info_solver, classes)
I propose another hidden parameter which is like params.forcing.waves._key_forced
from which params.forcing.key_forced
is intialized during runtime.
It should be something like:
#!python
if params.forcing.key_forced is None:
tag = params.forcing.type
params.forcing.key_forced = params.forcing[tag]._key_forced