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 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.
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.
- static detect_backend_by_model(filename: str) Type[Backend] [source]
Detect the backend of the given model file.
- Parameters
- filename
str
The model file name
- filename
- abstract property entry_point_hook: Callable[[Namespace], None]
The entry point hook of 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
- feature
Backend.Feature
the feature flag
- feature
- 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.
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.
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.
- is_available() bool [source]
Check if the backend is available.
- Returns
- bool
Whether the backend is available.
- property neighbor_stat: Type[NeighborStat]
The neighbor statistics of the backend.
- Returns
type
[NeighborStat
]The neighbor statistics 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.
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.
- is_available() bool [source]
Check if the backend is available.
- Returns
- bool
Whether the backend is available.
- property neighbor_stat: Type[NeighborStat]
The neighbor statistics of the backend.
- Returns
type
[NeighborStat
]The neighbor statistics 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
- 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.
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.
- is_available() bool [source]
Check if the backend is available.
- Returns
- bool
Whether the backend is available.
- property neighbor_stat: Type[NeighborStat]
The neighbor statistics of the backend.
- Returns
type
[NeighborStat
]The neighbor statistics of the backend.