Improve error message when using bad `dl_name`
Currently when using deep learning parameters, if the deep_learning_parameters
/dl_name
field has a typo, the error message is hard to understand.
File "/home/trentesauxh/mambaforge/envs/iota2-new/lib/python3.9/site-packages/iota2-0.0.0-py3.9.egg/iota2/learning/pytorch/torch_nn_bank.py", line 122, in _get_nn
return model
UnboundLocalError: local variable 'model' referenced before assignment
What is done is:
# check if instanciable
if nn_name:
Iota2NeuralNetworkFactory().get_nn(
# ...
and then
def _get_nn(self, nn_name, external_nn_module) -> nn.Module:
"""instanciate the right nn model
"""
if nn_name.lower() == "ann":
model = ANN(**self.nn_parameters)
elif nn_name.lower() == "ltaeclassifier":
model = LTAEClassifier(**self.nn_parameters)
elif nn_name.lower() == "mlpclassifier":
model = MLPClassifier(**self.nn_parameters)
elif nn_name.lower() == "simpleselfattentionclassifier":
model = SimpleSelfAttentionClassifier(**self.nn_parameters)
elif external_nn_module:
external_nn_module = verify_import(external_nn_module)
user_nn_class = getattr(external_nn_module, nn_name)
model = user_nn_class(**self.nn_parameters)
return model
- I'm not sure allowing case insensitive model name is a good feature
- This code could be refactored to avoid
elif
/elif
/elif
pattern using something likeif nn_name not in available_nn:
andmodel = available_nn[nn_name]
(for example) - An error message could be added like
"{nn_name} not in {available_nn}"