factoryutils
factoryutils ¶
Modul for factory utilities
Classes¶
ImportExceptionError ¶
Bases: Exception
Exception if an import is not possible
InitializationParamsError ¶
Bases: Exception
Exception for invalid initialization parameters
NoValidParameterPathError ¶
Bases: Exception
Exception if parameter path is not valid
Functions¶
import_function ¶
Takes a string as input and returns the function object that is referenced by the string. The string must be in the format of 'module_name.class_name'. The import_module function from Python's built-in importlib module is used to import the module, and then getattr() is used to retrieve an attribute from it (the class).
Parameters:
-
function_name
(str
) –str: Specify the type of the parameter
Returns: Function object
Source code in niceml/utilities/factoryutils.py
init_object ¶
Imports a class or function dynamically.
When type
is used the object is initialized with the given params
accordingly.
Otherwise (with function
-keyword), only the imported object is returned.
Parameters:
-
input_dict
(Union[dict, list]
) –Dict with keywords (type and params) or function.
additional_info: Additional information about to use for initialization.
Returns:
-
Any
–Initialized or imported object/class/function.
Source code in niceml/utilities/factoryutils.py
subs_path_and_create_folder ¶
Takes a filepath, and replaces the keys 'short_id' and 'run_id' with the corresponding values. It then creates any necessary folders in order to make the path valid.
Parameters:
-
filepath
(str
) –Pass the filepath to the function
-
short_id
(str
) –Replace the short_id key in the filepath string
-
run_id
(str
) –Create a unique folder for each run
Returns: filepath with replaced short id and run id