4.1.8 pde.backends.registry module

Defines the registry for managing backends.

BackendRegistry

Class handling all backends and their configurations.

class BackendRegistry[source]

Bases: object

Class 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 BackendBase classes

get_backend(name, *, config=None, **kwargs)[source]

Return backend object, potentially loading the respective package.

Parameters:
  • name (str) – Name of the backend to be loaded.

  • config (dict) – Configuration options for this specific backend

  • **kwargs – Additional options of the backend

Returns:

An instance of the backend with the particular configuration

Return type:

BackendBase

get_config(name)[source]

Get configuration of a particular backend.

An empty configuration is returned if nothing was found.

Parameters:

name (str) – Name of the backend

Returns:

the configuration

Return type:

Config

register_backend(backend, *, link_config=False)[source]

Register a loaded backend object.

Parameters:
  • backend (BackendBase) – Implementation of the backend

  • link_config (bool) – If True, the configuration of backend is linked with the global configuration, so that both show consistent values.

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)

Parameters:
  • name (str) – Name of the backend

  • package_path (str) – Import path for the package

  • config (list) – Configuration options for the package

Return type:

None

values()[source]

Iterate over all backends that can be imported.

Return type:

Iterator[BackendBase]

get_backend(backend)[source]

Return backend specified by string of instance.

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:cuda may load a torch backend an 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.

Return type:

BackendBase

load_default_config(module_path)[source]

Load a default configuration from a module.

Parameters:

module_path (str) – String to the module to be loaded

Return type:

list[Parameter] | None

registered_backends()[source]

Returns all registered backends.

Return type:

list[str]