Module utilities.backend_managementο
Utility functionality for managing backends
To check a standard backend, use backend_available()
. To check a non-standard backend specification, use check_backend()
.
To build a shim class that raises an error on instantiation, for when a required backend is not available, use missing_backend_shim()
.
Functions overview
|
Report if a backend is available for use |
|
Check if a backend is available, and register it in a list of available backends |
check_samna_available controls if samna package is "installed" and "usable" The default |
|
Print a list of computational backends available in this session |
|
|
Raise a |
|
Make a class constructor that raises an error about a missing backend |
|
Check if the installed version of torch satisfies a minimum version requirement |
Functions
- utilities.backend_management.backend_available(*backend_names) bool [source]ο
Report if a backend is available for use
This function returns immediately if the named backend has already been checked previously. Otherwise, if the backend is βstandardβ, then it will be checked for availability. If the backend is non-standard, it cannot be checked automatically. In that case you must use
check_backend()
directly.- Parameters:
backend_name0 (str) β A backend to check
backend_name1 (str) β A backend to check
... (str) β A backend to check
- Returns:
True
iff the backend is available for use- Return type:
bool
- utilities.backend_management.check_backend(backend_name: str, required_modules: Tuple[str] | List[str] | None = None, check_flag: bool = True) bool [source]ο
Check if a backend is available, and register it in a list of available backends
- Parameters:
backend_name (str) β The name of this backend to check for and register
required_modules (Optional[List[str]]) β A list of required modules to search for. If
None
(default), check the backend namecheck_flag (bool) β A manual check that can be performed externally, to see if the backend is available
- Returns:
The backend is available
- Return type:
bool
- utilities.backend_management.check_samna_available() bool [source]ο
check_samna_available controls if samna package is βinstalledβ and βusableβ The default
backend_available()
operation cannot correctly identifies the samna availability. In the case that one installed samna and then uninstalled via pip *pip install samna
thenpip uninstall samna
samna leaves a trace andimport samna
does not raise an error even though the package is not usable.- Returns:
true if samna package available
- Return type:
bool
- utilities.backend_management.list_backends()[source]ο
Print a list of computational backends available in this session
- utilities.backend_management.missing_backend_error(class_name: str, backend_name: str)[source]ο
Raise a
ModuleNotFoundError
exception, with information about a missing backend- Parameters:
class_name (str) β Name of a class which is unavailable
backend_name (str) β βUser-facingβ of the backend which is unavailable
- Raises:
ModuleNotFoundError β Describe the missing backend
- utilities.backend_management.missing_backend_shim(class_name: str, backend_name: str)[source]ο
Make a class constructor that raises an error about a missing backend
Examples
Generate a
LIFTorch
class shim, that will raise an error on instantiation.>>> LIFTorch = missing_backend_shim('LIFTorch', 'torch') >>> LIFTorch((3,), tau_syn = 10e-3) ModuleNotFoundError: Missing the `torch` backend. `LIFTorch` objects, and others relying on `torch` are not available.
- Parameters:
class_name (str) β The intended class name
backend_name (str) β The required backend that is missing
- Returns:
A class that raises an error on construction
- Return type:
Class
- utilities.backend_management.torch_version_satisfied(req_major: int = 0, req_minor: int = 0, req_patch: int = 0) bool [source]ο
Check if the installed version of torch satisfies a minimum version requirement
- i.e.
torch 2.0.0 >= 1.12.0 : True torch 1.12.0 >= 1.12.0 : True torch 1.11.0 >= 1.12.0 : False
- Parameters:
req_major (int) β The minimum major version required
req_minor (int) β The minimum minor version required
req_patch (int) β The minimum patch version required
- Returns:
The installed version of torch satisfies the minimum version requirement
- Return type:
bool