deepmd.utils.plugin#

Base of plugin systems.

Classes#

Plugin

A class to register and restore plugins.

VariantMeta

VariantABCMeta

Metaclass for defining Abstract Base Classes (ABCs).

PluginVariant

A class to remove type from input arguments.

Functions#

make_plugin_registry(→ type[object])

Make a plugin registry.

Module Contents#

class deepmd.utils.plugin.Plugin[source]#

A class to register and restore plugins.

Attributes:
pluginsdict[str, object]

plugins

Examples

>>> plugin = Plugin()
>>> @plugin.register("xx")
    def xxx():
        pass
>>> print(plugin.plugins["xx"])
plugins[source]#
__add__(other) Plugin[source]#
register(key: str) Callable[[object], object][source]#

Register a plugin.

Parameters:
keystr

key of the plugin

Returns:
Callable[[object], object]

decorator

get_plugin(key) object[source]#

Visit a plugin by key.

Parameters:
keystr

key of the plugin

Returns:
object

the plugin

class deepmd.utils.plugin.VariantMeta[source]#
__call__(*args, **kwargs)[source]#

Remove type and keys that starts with underline.

class deepmd.utils.plugin.VariantABCMeta[source]#

Bases: VariantMeta, abc.ABCMeta

Metaclass for defining Abstract Base Classes (ABCs).

Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as ‘virtual subclasses’ – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).

class deepmd.utils.plugin.PluginVariant[source]#

A class to remove type from input arguments.

deepmd.utils.plugin.make_plugin_registry(name: str | None = None) type[object][source]#

Make a plugin registry.

Parameters:
nameOptional[str]

the name of the registry for the error message, e.g. descriptor, backend, etc.

Examples

>>> class BaseClass(make_plugin_registry()):
        pass