deepmd.backend package

Backends.

Avoid directly importing third-party libraries in this module for performance.

Submodules

deepmd.backend.backend module

class deepmd.backend.backend.Backend(*args, **kwargs)[source]

Bases: PluginVariant, PR

General backend class.

Examples

>>> @Backend.register("tf")
>>> @Backend.register("tensorflow")
>>> class TensorFlowBackend(Backend):
...     pass
Attributes
deep_eval

The Deep Eval backend of the backend.

deserialize_hook

The deserialize hook to convert the dictionary to a model file.

entry_point_hook

The entry point hook of the backend.

neighbor_stat

The neighbor statistics of the backend.

serialize_hook

The serialize hook to convert the model file to a dictionary.

Methods

Feature(value)

Feature flag to indicate whether the backend supports certain features.

detect_backend_by_model(filename)

Detect the backend of the given model file.

get_backend(key)

Get the backend by key.

get_backends()

Get all the registered backend names.

get_backends_by_feature(feature)

Get all the registered backend names with a specific feature.

get_class_by_type(class_type)

Get the class by the plugin type.

get_plugins()

Get all the registered plugins.

is_available()

Check if the backend is available.

register(key)

Register a descriptor plugin.

class Feature(value)[source]

Bases: Flag

Feature flag to indicate whether the backend supports certain features.

DEEP_EVAL = 2

Support Deep Eval backend.

ENTRY_POINT = 1

Support entry point hook.

IO = 8

Support IO hook.

NEIGHBOR_STAT = 4

Support neighbor statistics.

abstract property deep_eval: Type[DeepEvalBackend]

The Deep Eval backend of the backend.

Returns
type[DeepEvalBackend]

The Deep Eval backend of the backend.

abstract property deserialize_hook: Callable[[str, dict], None]

The deserialize hook to convert the dictionary to a model file.

Returns
Callable[[str, dict], None]

The deserialize hook of the backend.

static detect_backend_by_model(filename: str) Type[Backend][source]

Detect the backend of the given model file.

Parameters
filenamestr

The model file name

abstract property entry_point_hook: Callable[[Namespace], None]

The entry point hook of the backend.

Returns
Callable[[Namespace], None]

The entry point hook of the backend.

features: ClassVar[Feature] = 0

The features of the backend.

static get_backend(key: str) Type[Backend][source]

Get the backend by key.

Parameters
keystr

the key of a backend

Returns
Backend

the backend

static get_backends() Dict[str, Type[Backend]][source]

Get all the registered backend names.

Returns
list

all the registered backends

static get_backends_by_feature(feature: Feature) Dict[str, Type[Backend]][source]

Get all the registered backend names with a specific feature.

Parameters
featureBackend.Feature

the feature flag

Returns
list

all the registered backends with the feature

abstract is_available() bool[source]

Check if the backend is available.

Returns
bool

Whether the backend is available.

name: ClassVar[str] = 'Unknown'

The formal name of the backend.

To be consistent, this name should be also registered in the plugin system.

abstract property neighbor_stat: Type[NeighborStat]

The neighbor statistics of the backend.

Returns
type[NeighborStat]

The neighbor statistics of the backend.

abstract property serialize_hook: Callable[[str], dict]

The serialize hook to convert the model file to a dictionary.

Returns
Callable[[str], dict]

The serialize hook of the backend.

suffixes: ClassVar[List[str]] = []

The supported suffixes of the saved model.

The first element is considered as the default suffix.

deepmd.backend.dpmodel module

class deepmd.backend.dpmodel.DPModelBackend(*args, **kwargs)[source]

Bases: Backend

DPModel backend that uses NumPy as the reference implementation.

Attributes
deep_eval

The Deep Eval backend of the backend.

deserialize_hook

The deserialize hook to convert the dictionary to a model file.

entry_point_hook

The entry point hook of the backend.

neighbor_stat

The neighbor statistics of the backend.

serialize_hook

The serialize hook to convert the model file to a dictionary.

Methods

Feature(value)

Feature flag to indicate whether the backend supports certain features.

detect_backend_by_model(filename)

Detect the backend of the given model file.

get_backend(key)

Get the backend by key.

get_backends()

Get all the registered backend names.

get_backends_by_feature(feature)

Get all the registered backend names with a specific feature.

get_class_by_type(class_type)

Get the class by the plugin type.

get_plugins()

Get all the registered plugins.

is_available()

Check if the backend is available.

register(key)

Register a descriptor plugin.

property deep_eval: Type[DeepEvalBackend]

The Deep Eval backend of the backend.

Returns
type[DeepEvalBackend]

The Deep Eval backend of the backend.

property deserialize_hook: Callable[[str, dict], None]

The deserialize hook to convert the dictionary to a model file.

Returns
Callable[[str, dict], None]

The deserialize hook of the backend.

property entry_point_hook: Callable[[Namespace], None]

The entry point hook of the backend.

Returns
Callable[[Namespace], None]

The entry point hook of the backend.

features: ClassVar[Feature] = 14

The features of the backend.

is_available() bool[source]

Check if the backend is available.

Returns
bool

Whether the backend is available.

name: ClassVar[str] = 'DPModel'

The formal name of the backend.

property neighbor_stat: Type[NeighborStat]

The neighbor statistics of the backend.

Returns
type[NeighborStat]

The neighbor statistics of the backend.

property serialize_hook: Callable[[str], dict]

The serialize hook to convert the model file to a dictionary.

Returns
Callable[[str], dict]

The serialize hook of the backend.

suffixes: ClassVar[List[str]] = ['.dp']

The suffixes of the backend.

deepmd.backend.pytorch module

class deepmd.backend.pytorch.TensorFlowBackend(*args, **kwargs)[source]

Bases: Backend

TensorFlow backend.

Attributes
deep_eval

The Deep Eval backend of the backend.

deserialize_hook

The deserialize hook to convert the dictionary to a model file.

entry_point_hook

The entry point hook of the backend.

neighbor_stat

The neighbor statistics of the backend.

serialize_hook

The serialize hook to convert the model file to a dictionary.

Methods

Feature(value)

Feature flag to indicate whether the backend supports certain features.

detect_backend_by_model(filename)

Detect the backend of the given model file.

get_backend(key)

Get the backend by key.

get_backends()

Get all the registered backend names.

get_backends_by_feature(feature)

Get all the registered backend names with a specific feature.

get_class_by_type(class_type)

Get the class by the plugin type.

get_plugins()

Get all the registered plugins.

is_available()

Check if the backend is available.

register(key)

Register a descriptor plugin.

property deep_eval: Type[DeepEvalBackend]

The Deep Eval backend of the backend.

Returns
type[DeepEvalBackend]

The Deep Eval backend of the backend.

property deserialize_hook: Callable[[str, dict], None]

The deserialize hook to convert the dictionary to a model file.

Returns
Callable[[str, dict], None]

The deserialize hook of the backend.

property entry_point_hook: Callable[[Namespace], None]

The entry point hook of the backend.

Returns
Callable[[Namespace], None]

The entry point hook of the backend.

features: ClassVar[Feature] = 15

The features of the backend.

is_available() bool[source]

Check if the backend is available.

Returns
bool

Whether the backend is available.

name: ClassVar[str] = 'PyTorch'

The formal name of the backend.

property neighbor_stat: Type[NeighborStat]

The neighbor statistics of the backend.

Returns
type[NeighborStat]

The neighbor statistics of the backend.

property serialize_hook: Callable[[str], dict]

The serialize hook to convert the model file to a dictionary.

Returns
Callable[[str], dict]

The serialize hook of the backend.

suffixes: ClassVar[List[str]] = ['.pth', '.pt']

The suffixes of the backend.

deepmd.backend.suffix module

deepmd.backend.suffix.format_model_suffix(filename: str, feature: Optional[Feature] = None, preferred_backend: Optional[Union[str, Type[Backend]]] = None, strict_prefer: Optional[bool] = None) str[source]

Check and format the suffixes of a filename.

When preferred_backend is not given, this method checks the suffix of the filename is within the suffixes of the any backends (with the given feature) and doesn’t do formating. When preferred_backend is given, strict_prefer must be given. If strict_prefer is True and the suffix is not within the suffixes of the preferred backend, or strict_prefer is False and the suffix is not within the suffixes of the any backend with the given feature, the filename will be formatted with the preferred suffix of the preferred backend.

Parameters
filenamestr

The filename to be formatted.

featureBackend.Feature, optional

The feature of the backend, by default None

preferred_backendstr or type of Backend, optional

The preferred backend, by default None

strict_preferbool, optional

Whether to strictly prefer the preferred backend, by default None

Returns
str

The formatted filename with the correct suffix.

Raises
ValueError

When preferred_backend is not given and the filename is not supported by any backend.

deepmd.backend.tensorflow module

class deepmd.backend.tensorflow.TensorFlowBackend(*args, **kwargs)[source]

Bases: Backend

TensorFlow backend.

Attributes
deep_eval

The Deep Eval backend of the backend.

deserialize_hook

The deserialize hook to convert the dictionary to a model file.

entry_point_hook

The entry point hook of the backend.

neighbor_stat

The neighbor statistics of the backend.

serialize_hook

The serialize hook to convert the model file to a dictionary.

Methods

Feature(value)

Feature flag to indicate whether the backend supports certain features.

detect_backend_by_model(filename)

Detect the backend of the given model file.

get_backend(key)

Get the backend by key.

get_backends()

Get all the registered backend names.

get_backends_by_feature(feature)

Get all the registered backend names with a specific feature.

get_class_by_type(class_type)

Get the class by the plugin type.

get_plugins()

Get all the registered plugins.

is_available()

Check if the backend is available.

register(key)

Register a descriptor plugin.

property deep_eval: Type[DeepEvalBackend]

The Deep Eval backend of the backend.

Returns
type[DeepEvalBackend]

The Deep Eval backend of the backend.

property deserialize_hook: Callable[[str, dict], None]

The deserialize hook to convert the dictionary to a model file.

Returns
Callable[[str, dict], None]

The deserialize hook of the backend.

property entry_point_hook: Callable[[Namespace], None]

The entry point hook of the backend.

Returns
Callable[[Namespace], None]

The entry point hook of the backend.

features: ClassVar[Feature] = 15

The features of the backend.

is_available() bool[source]

Check if the backend is available.

Returns
bool

Whether the backend is available.

name: ClassVar[str] = 'TensorFlow'

The formal name of the backend.

property neighbor_stat: Type[NeighborStat]

The neighbor statistics of the backend.

Returns
type[NeighborStat]

The neighbor statistics of the backend.

property serialize_hook: Callable[[str], dict]

The serialize hook to convert the model file to a dictionary.

Returns
Callable[[str], dict]

The serialize hook of the backend.

suffixes: ClassVar[List[str]] = ['.pb']

The suffixes of the backend.