Belle II Software  release-08-01-10
__init__.py
1 
12 """
13 This package encapsulates different PXD background generator models.
14 """
15 
16 from importlib import import_module
17 from typing import Callable, Type
18 
19 
20 
31 def _get_model_cls(model: str) -> Type:
32  cls = None
33  try:
34  cls = import_module(f".{model}", __name__).Model
35  except AttributeError as exc:
36  exc.msg = f"please define a model class for {model!r}"
37  raise
38  except ModuleNotFoundError as exc:
39  exc.msg = f"the selected model {model!r} is not implemented"
40  raise
41  return cls
42 
43 
44 
55 def _get_generate_func(model: str) -> Callable:
56  func = None
57  try:
58  func = import_module(f".{model}", __name__).generate
59  except AttributeError as exc:
60  exc.msg = f"please define the generation function for {model!r}"
61  raise
62  except ModuleNotFoundError as exc:
63  exc.msg = f"the selected model {model!r} is not implemented"
64  raise
65  return func
66 
67 
68 
86 MODELS = (
87  "convnet",
88  "resnet",
89 )
Type _get_model_cls(str model)
Helper function that imports and returns the class Model from the Python module named as model and as...
Definition: __init__.py:31
Callable _get_generate_func(str model)
Helper function that imports and returns the function generate from the Python module named as model ...
Definition: __init__.py:55