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.

Module Contents

Functions

lazy_importer(module_name[, class_name, frail])

A simple lazy importer tries to import a module/class but is too lazy to complain

tf_installed()

Checks if TensorFlow is installed.

import_tf([module_name, class_name, frail])

Tries to import TensorFlow and throws custom warning if TensorFlow is not

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:
  • module_name (str) – The python module you want to import (eg. tensorflow.nn).

  • class_name (str) – The python class you want to import from a given python module by default None.

  • frail (bool, optional) – Throw ImportError when module can not be imported. Defaults to False.

Raises:

ImportError – A custom import error that is raised when the module is not installed and frail is True.

Returns:

The imported (class) module. Returns None if the module is not

found.

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:

bool

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 default None.

  • frail (bool, optional) – Throw ImportError when TensorFlow can not be imported. Defaults to True.

Raises:

ImportError – A custom import error if TensorFlow is not installed.

Returns:

The imported (class) module.

Return type:

module