stable_learning_control.utils.import_utils
Contains functions that can be used to import modules and classes while repressing the :class`ImportError` when a module is not found.
Functions
|
A simple lazy importer tries to import a module/class but is too lazy to complain |
Checks if TensorFlow is installed. |
|
|
Tries to import TensorFlow and throws custom warning if TensorFlow is not |
Module Contents
- stable_learning_control.utils.import_utils.lazy_importer(module_name, class_name=None, frail=False)[source]
A simple lazy importer tries to import a module/class but is too lazy to complain when it is not found. This function can be used to (lazily) load modules and classes, meaning only loading them if available.
- Parameters:
- Raises:
ImportError – A custom import error that is raised when the module is not installed and
frail
isTrue
.- Returns:
- The imported (class) module. Returns
None
if the module is not found.
- The imported (class) module. Returns
- Return type:
module
- stable_learning_control.utils.import_utils.tf_installed()[source]
Checks if TensorFlow is installed.
- Returns:
Returns
True
if TensorFlow is installed.- Return type:
- stable_learning_control.utils.import_utils.import_tf(module_name=None, class_name=None, frail=True)[source]
Tries to import TensorFlow and throws custom warning if TensorFlow is not installed.
- Parameters:
module_name (str, optional) – The tensorflow python module you want to import (eg. tensorflow.nn). By default
None
, meaning the TensorFlow package is imported.class_name (str) – The python class you want to import from the tensorflow python module (eg. Adam from
tf.keras.optimizers
). By defaultNone
.frail (bool, optional) – Throw
ImportError
when TensorFlow can not be imported. Defaults toTrue
.
- Raises:
ImportError – A custom import error if TensorFlow is not installed.
- Returns:
The imported (class) module.
- Return type:
module