4.1.8 pde.backends.registry module
Defines the registry for managing backends.
Class handling all backends and their configurations. |
|
Load a default configuration from a module. |
|
Return backend specified by string of instance. |
|
Returns all registered backends. |
- class BackendRegistry[source]
Bases:
objectClass handling all backends and their configurations.
Backends can exist in three different states in registry: * Registered meta-information on how to load a backend package * Loaded backend module, so the class is available * Fully instantiated
BackendBaseclasses- get_backend(name, *, config=None, **kwargs)[source]
Return backend object, potentially loading the respective package.
The returned backend is cached if config is not specified. Consequently, the same object will be returned for repeated calls to get_backend, which allows sharing configuration parameters. Moreover, if name only specifies a backend, i.e., does not contain a colon :, the configuration of this backend is linked with the global configuration
pde.config, such that changes to the config are reflected globally.- Parameters:
- Returns:
An instance of the backend with the particular configuration
- Return type:
- register_backend(backend)[source]
Register a loaded backend object.
- Parameters:
backend (
BackendBase) – Implementation of the backend- Return type:
None
- register_class(name, cls)[source]
Register a backend class.
- Parameters:
name (str) – Name of the backend
cls (subclass of
BackendBase) – The class for creating a backend
- register_package(name, package_path, *, config=None)[source]
Register a backend python package (without loading it yet)
- values()[source]
Iterate over all backends that can be imported.
- Return type:
Iterator[BackendBase]
- get_backend(backend, config=None)[source]
Return backend specified by string of instance.
The returned backend is cached if config is not specified. Consequently, the same object will be returned for repeated calls to get_backend, which allows sharing configuration parameters. Moreover, if name only specifies a backend, i.e., does not contain a colon :, the configuration of this backend is linked with the global configuration
pde.config, such that changes to the config are reflected globally.- Parameters:
backend (str or
BackendBase) – Backend specified by name given as a string. If the string contains a colon, the first part determines the backend, whereas the second part can be used to convey additional information. For example,torch:cudamay load a torch backend and use a cuda device. As a special case, we also allow full backend objects, which are simply returned. This is a simple way to allow providing full backend objects in places where we otherwise would expect a backend name.config (dict) – Additional configuration options for this specific backend. The full configuration will be taken from the global configuration and merged with the given options here. This option is only permitted if backend is a string since there otherwise might be unintended side effects of modifying an existing backend.
- Returns:
An initialized backend
- Return type: