deepmd.pt.utils package
- class deepmd.pt.utils.AtomExcludeMask(ntypes: int, exclude_types: List[int] = [])[source]
Bases:
ModuleComputes the type exclusion mask for atoms.
Methods
add_module(name, module)Add a child module to the current module.
apply(fn)Apply
fnrecursively to every submodule (as returned by.children()) as well as self.bfloat16()Casts all floating point parameters and buffers to
bfloat16datatype.buffers([recurse])Return an iterator over module buffers.
children()Return an iterator over immediate children modules.
compile(*args, **kwargs)Compile this Module's forward using
torch.compile().cpu()Move all model parameters and buffers to the CPU.
cuda([device])Move all model parameters and buffers to the GPU.
double()Casts all floating point parameters and buffers to
doubledatatype.eval()Set the module in evaluation mode.
extra_repr()Set the extra representation of the module.
float()Casts all floating point parameters and buffers to
floatdatatype.forward(atype)Compute type exclusion mask for atoms.
get_buffer(target)Return the buffer given by
targetif it exists, otherwise throw an error.get_extra_state()Return any extra state to include in the module's state_dict.
get_parameter(target)Return the parameter given by
targetif it exists, otherwise throw an error.get_submodule(target)Return the submodule given by
targetif it exists, otherwise throw an error.half()Casts all floating point parameters and buffers to
halfdatatype.ipu([device])Move all model parameters and buffers to the IPU.
load_state_dict(state_dict[, strict, assign])Copy parameters and buffers from
state_dictinto this module and its descendants.modules()Return an iterator over all modules in the network.
named_buffers([prefix, recurse, ...])Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children()Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules([memo, prefix, remove_duplicate])Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters([prefix, recurse, ...])Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters([recurse])Return an iterator over module parameters.
register_backward_hook(hook)Register a backward hook on the module.
register_buffer(name, tensor[, persistent])Add a buffer to the module.
register_forward_hook(hook, *[, prepend, ...])Register a forward hook on the module.
register_forward_pre_hook(hook, *[, ...])Register a forward pre-hook on the module.
register_full_backward_hook(hook[, prepend])Register a backward hook on the module.
register_full_backward_pre_hook(hook[, prepend])Register a backward pre-hook on the module.
register_load_state_dict_post_hook(hook)Register a post hook to be run after module's
load_state_dictis called.register_module(name, module)Alias for
add_module().register_parameter(name, param)Add a parameter to the module.
register_state_dict_pre_hook(hook)Register a pre-hook for the
load_state_dict()method.requires_grad_([requires_grad])Change if autograd should record operations on parameters in this module.
set_extra_state(state)Set extra state contained in the loaded state_dict.
share_memory()See
torch.Tensor.share_memory_().state_dict(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the module.
to(*args, **kwargs)Move and/or cast the parameters and buffers.
to_empty(*, device[, recurse])Move the parameters and buffers to the specified device without copying storage.
train([mode])Set the module in training mode.
type(dst_type)Casts all parameters and buffers to
dst_type.xpu([device])Move all model parameters and buffers to the XPU.
zero_grad([set_to_none])Reset gradients of all model parameters.
__call__
reinit
- class deepmd.pt.utils.PairExcludeMask(ntypes: int, exclude_types: List[Tuple[int, int]] = [])[source]
Bases:
ModuleComputes the type exclusion mask for atom pairs.
Methods
add_module(name, module)Add a child module to the current module.
apply(fn)Apply
fnrecursively to every submodule (as returned by.children()) as well as self.bfloat16()Casts all floating point parameters and buffers to
bfloat16datatype.buffers([recurse])Return an iterator over module buffers.
children()Return an iterator over immediate children modules.
compile(*args, **kwargs)Compile this Module's forward using
torch.compile().cpu()Move all model parameters and buffers to the CPU.
cuda([device])Move all model parameters and buffers to the GPU.
double()Casts all floating point parameters and buffers to
doubledatatype.eval()Set the module in evaluation mode.
extra_repr()Set the extra representation of the module.
float()Casts all floating point parameters and buffers to
floatdatatype.forward(nlist, atype_ext)Compute type exclusion mask.
get_buffer(target)Return the buffer given by
targetif it exists, otherwise throw an error.get_extra_state()Return any extra state to include in the module's state_dict.
get_parameter(target)Return the parameter given by
targetif it exists, otherwise throw an error.get_submodule(target)Return the submodule given by
targetif it exists, otherwise throw an error.half()Casts all floating point parameters and buffers to
halfdatatype.ipu([device])Move all model parameters and buffers to the IPU.
load_state_dict(state_dict[, strict, assign])Copy parameters and buffers from
state_dictinto this module and its descendants.modules()Return an iterator over all modules in the network.
named_buffers([prefix, recurse, ...])Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children()Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules([memo, prefix, remove_duplicate])Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters([prefix, recurse, ...])Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters([recurse])Return an iterator over module parameters.
register_backward_hook(hook)Register a backward hook on the module.
register_buffer(name, tensor[, persistent])Add a buffer to the module.
register_forward_hook(hook, *[, prepend, ...])Register a forward hook on the module.
register_forward_pre_hook(hook, *[, ...])Register a forward pre-hook on the module.
register_full_backward_hook(hook[, prepend])Register a backward hook on the module.
register_full_backward_pre_hook(hook[, prepend])Register a backward pre-hook on the module.
register_load_state_dict_post_hook(hook)Register a post hook to be run after module's
load_state_dictis called.register_module(name, module)Alias for
add_module().register_parameter(name, param)Add a parameter to the module.
register_state_dict_pre_hook(hook)Register a pre-hook for the
load_state_dict()method.requires_grad_([requires_grad])Change if autograd should record operations on parameters in this module.
set_extra_state(state)Set extra state contained in the loaded state_dict.
share_memory()See
torch.Tensor.share_memory_().state_dict(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the module.
to(*args, **kwargs)Move and/or cast the parameters and buffers.
to_empty(*, device[, recurse])Move the parameters and buffers to the specified device without copying storage.
train([mode])Set the module in training mode.
type(dst_type)Casts all parameters and buffers to
dst_type.xpu([device])Move all model parameters and buffers to the XPU.
zero_grad([set_to_none])Reset gradients of all model parameters.
__call__
reinit
- forward(nlist: Tensor, atype_ext: Tensor) Tensor[source]
Compute type exclusion mask.
- Parameters
- nlist
The neighbor list. shape: nf x nloc x nnei
- atype_ext
The extended aotm types. shape: nf x nall
- Returns
maskThe type exclusion mask of shape: nf x nloc x nnei. Element [ff,ii,jj] being 0 if type(ii), type(nlist[ff,ii,jj]) is excluded, otherwise being 1.
Submodules
deepmd.pt.utils.ase_calc module
deepmd.pt.utils.auto_batch_size module
- class deepmd.pt.utils.auto_batch_size.AutoBatchSize(initial_batch_size: int = 1024, factor: float = 2.0)[source]
Bases:
AutoBatchSizeMethods
execute(callable, start_index, natoms)Excuate a method with given batch size.
execute_all(callable, total_size, natoms, ...)Excuate a method with all given data.
Check if GPU is available.
is_oom_error(e)Check if the exception is an OOM error.
deepmd.pt.utils.cache module
deepmd.pt.utils.dataloader module
- class deepmd.pt.utils.dataloader.BackgroundConsumer(queue, source, max_len)[source]
Bases:
Thread- Attributes
daemonA boolean value indicating whether this thread is a daemon thread.
identThread identifier of this thread or None if it has not been started.
nameA string used for identification purposes only.
native_idNative integral thread ID of this thread, or None if it has not been started.
Methods
is_alive()Return whether the thread is alive.
join([timeout])Wait until the thread terminates.
run()Method representing the thread's activity.
start()Start the thread's activity.
getName
isDaemon
setDaemon
setName
- run()[source]
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- class deepmd.pt.utils.dataloader.DpLoaderSet(systems, batch_size, model_params, seed=10, shuffle=True)[source]
Bases:
DatasetA dataset for storing DataLoaders to multiple Systems.
Methods
add_data_requirement(data_requirement)Add data requirement for each system in multiple systems.
print_summary
set_noise
- add_data_requirement(data_requirement: List[DataRequirementItem])[source]
Add data requirement for each system in multiple systems.
deepmd.pt.utils.dataset module
- class deepmd.pt.utils.dataset.DeepmdDataSetForLoader(system: str, type_map: str, shuffle=True)[source]
Bases:
DatasetMethods
add_data_requirement(data_requirement)Add data requirement for this data system.
- add_data_requirement(data_requirement: List[DataRequirementItem])[source]
Add data requirement for this data system.
deepmd.pt.utils.dp_random module
- deepmd.pt.utils.dp_random.choice(a: Union[ndarray, int], size: Optional[Union[int, Tuple[int, ...]]] = None, replace: bool = True, p: Optional[ndarray] = None)[source]
Generates a random sample from a given 1-D array.
- Parameters
- a1-D array_like or
int If an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if it were np.arange(a)
- size
intortupleofints,optional Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
- replacebool,
optional Whether the sample is with or without replacement. Default is True, meaning that a value of a can be selected multiple times.
- p1-D array_like,
optional The probabilities associated with each entry in a. If not given, the sample assumes a uniform distribution over all entries in a.
- a1-D array_like or
- Returns
np.ndarrayarrays with results and their shapes
- deepmd.pt.utils.dp_random.random(size=None)[source]
Return random floats in the half-open interval [0.0, 1.0).
- Parameters
- size
Output shape.
- Returns
np.ndarrayArrays with results and their shapes.
- deepmd.pt.utils.dp_random.seed(val: Optional[int] = None)[source]
Seed the generator.
- Parameters
- val
int Seed.
- val
- deepmd.pt.utils.dp_random.shuffle(x: ndarray)[source]
Modify a sequence in-place by shuffling its contents.
- Parameters
- x
np.ndarray The array or list to be shuffled.
- x
deepmd.pt.utils.env module
- deepmd.pt.utils.env.GLOBAL_ENER_FLOAT_PRECISION
alias of
float64
- deepmd.pt.utils.env.GLOBAL_NP_FLOAT_PRECISION
alias of
float64
deepmd.pt.utils.env_mat_stat module
- class deepmd.pt.utils.env_mat_stat.EnvMatStat[source]
Bases:
EnvMatStatMethods
compute_stat(env_mat)Compute the statistics of the environment matrix for a single system.
compute_stats(data)Compute the statistics of the environment matrix.
get_avg([default])Get the average of the environment matrix.
get_std([default, protection])Get the standard deviation of the environment matrix.
iter(data)Get the iterator of the environment matrix.
load_or_compute_stats(data[, path])Load the statistics of the environment matrix if it exists, otherwise compute and save it.
load_stats(path)Load the statistics of the environment matrix.
save_stats(path)Save the statistics of the environment matrix.
- class deepmd.pt.utils.env_mat_stat.EnvMatStatSe(descriptor: DescriptorBlock)[source]
Bases:
EnvMatStatEnvironmental matrix statistics for the se_a/se_r environemntal matrix.
- Parameters
- descriptor
DescriptorBlock The descriptor of the model.
- descriptor
Methods
__call__()Call self as a function.
compute_stat(env_mat)Compute the statistics of the environment matrix for a single system.
compute_stats(data)Compute the statistics of the environment matrix.
get_avg([default])Get the average of the environment matrix.
get_hash()Get the hash of the environment matrix.
get_std([default, protection])Get the standard deviation of the environment matrix.
iter(data)Get the iterator of the environment matrix.
load_or_compute_stats(data[, path])Load the statistics of the environment matrix if it exists, otherwise compute and save it.
load_stats(path)Load the statistics of the environment matrix.
save_stats(path)Save the statistics of the environment matrix.
deepmd.pt.utils.exclude_mask module
- class deepmd.pt.utils.exclude_mask.AtomExcludeMask(ntypes: int, exclude_types: List[int] = [])[source]
Bases:
ModuleComputes the type exclusion mask for atoms.
Methods
add_module(name, module)Add a child module to the current module.
apply(fn)Apply
fnrecursively to every submodule (as returned by.children()) as well as self.bfloat16()Casts all floating point parameters and buffers to
bfloat16datatype.buffers([recurse])Return an iterator over module buffers.
children()Return an iterator over immediate children modules.
compile(*args, **kwargs)Compile this Module's forward using
torch.compile().cpu()Move all model parameters and buffers to the CPU.
cuda([device])Move all model parameters and buffers to the GPU.
double()Casts all floating point parameters and buffers to
doubledatatype.eval()Set the module in evaluation mode.
extra_repr()Set the extra representation of the module.
float()Casts all floating point parameters and buffers to
floatdatatype.forward(atype)Compute type exclusion mask for atoms.
get_buffer(target)Return the buffer given by
targetif it exists, otherwise throw an error.get_extra_state()Return any extra state to include in the module's state_dict.
get_parameter(target)Return the parameter given by
targetif it exists, otherwise throw an error.get_submodule(target)Return the submodule given by
targetif it exists, otherwise throw an error.half()Casts all floating point parameters and buffers to
halfdatatype.ipu([device])Move all model parameters and buffers to the IPU.
load_state_dict(state_dict[, strict, assign])Copy parameters and buffers from
state_dictinto this module and its descendants.modules()Return an iterator over all modules in the network.
named_buffers([prefix, recurse, ...])Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children()Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules([memo, prefix, remove_duplicate])Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters([prefix, recurse, ...])Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters([recurse])Return an iterator over module parameters.
register_backward_hook(hook)Register a backward hook on the module.
register_buffer(name, tensor[, persistent])Add a buffer to the module.
register_forward_hook(hook, *[, prepend, ...])Register a forward hook on the module.
register_forward_pre_hook(hook, *[, ...])Register a forward pre-hook on the module.
register_full_backward_hook(hook[, prepend])Register a backward hook on the module.
register_full_backward_pre_hook(hook[, prepend])Register a backward pre-hook on the module.
register_load_state_dict_post_hook(hook)Register a post hook to be run after module's
load_state_dictis called.register_module(name, module)Alias for
add_module().register_parameter(name, param)Add a parameter to the module.
register_state_dict_pre_hook(hook)Register a pre-hook for the
load_state_dict()method.requires_grad_([requires_grad])Change if autograd should record operations on parameters in this module.
set_extra_state(state)Set extra state contained in the loaded state_dict.
share_memory()See
torch.Tensor.share_memory_().state_dict(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the module.
to(*args, **kwargs)Move and/or cast the parameters and buffers.
to_empty(*, device[, recurse])Move the parameters and buffers to the specified device without copying storage.
train([mode])Set the module in training mode.
type(dst_type)Casts all parameters and buffers to
dst_type.xpu([device])Move all model parameters and buffers to the XPU.
zero_grad([set_to_none])Reset gradients of all model parameters.
__call__
reinit
- class deepmd.pt.utils.exclude_mask.PairExcludeMask(ntypes: int, exclude_types: List[Tuple[int, int]] = [])[source]
Bases:
ModuleComputes the type exclusion mask for atom pairs.
Methods
add_module(name, module)Add a child module to the current module.
apply(fn)Apply
fnrecursively to every submodule (as returned by.children()) as well as self.bfloat16()Casts all floating point parameters and buffers to
bfloat16datatype.buffers([recurse])Return an iterator over module buffers.
children()Return an iterator over immediate children modules.
compile(*args, **kwargs)Compile this Module's forward using
torch.compile().cpu()Move all model parameters and buffers to the CPU.
cuda([device])Move all model parameters and buffers to the GPU.
double()Casts all floating point parameters and buffers to
doubledatatype.eval()Set the module in evaluation mode.
extra_repr()Set the extra representation of the module.
float()Casts all floating point parameters and buffers to
floatdatatype.forward(nlist, atype_ext)Compute type exclusion mask.
get_buffer(target)Return the buffer given by
targetif it exists, otherwise throw an error.get_extra_state()Return any extra state to include in the module's state_dict.
get_parameter(target)Return the parameter given by
targetif it exists, otherwise throw an error.get_submodule(target)Return the submodule given by
targetif it exists, otherwise throw an error.half()Casts all floating point parameters and buffers to
halfdatatype.ipu([device])Move all model parameters and buffers to the IPU.
load_state_dict(state_dict[, strict, assign])Copy parameters and buffers from
state_dictinto this module and its descendants.modules()Return an iterator over all modules in the network.
named_buffers([prefix, recurse, ...])Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children()Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules([memo, prefix, remove_duplicate])Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters([prefix, recurse, ...])Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters([recurse])Return an iterator over module parameters.
register_backward_hook(hook)Register a backward hook on the module.
register_buffer(name, tensor[, persistent])Add a buffer to the module.
register_forward_hook(hook, *[, prepend, ...])Register a forward hook on the module.
register_forward_pre_hook(hook, *[, ...])Register a forward pre-hook on the module.
register_full_backward_hook(hook[, prepend])Register a backward hook on the module.
register_full_backward_pre_hook(hook[, prepend])Register a backward pre-hook on the module.
register_load_state_dict_post_hook(hook)Register a post hook to be run after module's
load_state_dictis called.register_module(name, module)Alias for
add_module().register_parameter(name, param)Add a parameter to the module.
register_state_dict_pre_hook(hook)Register a pre-hook for the
load_state_dict()method.requires_grad_([requires_grad])Change if autograd should record operations on parameters in this module.
set_extra_state(state)Set extra state contained in the loaded state_dict.
share_memory()See
torch.Tensor.share_memory_().state_dict(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the module.
to(*args, **kwargs)Move and/or cast the parameters and buffers.
to_empty(*, device[, recurse])Move the parameters and buffers to the specified device without copying storage.
train([mode])Set the module in training mode.
type(dst_type)Casts all parameters and buffers to
dst_type.xpu([device])Move all model parameters and buffers to the XPU.
zero_grad([set_to_none])Reset gradients of all model parameters.
__call__
reinit
- forward(nlist: Tensor, atype_ext: Tensor) Tensor[source]
Compute type exclusion mask.
- Parameters
- nlist
The neighbor list. shape: nf x nloc x nnei
- atype_ext
The extended aotm types. shape: nf x nall
- Returns
maskThe type exclusion mask of shape: nf x nloc x nnei. Element [ff,ii,jj] being 0 if type(ii), type(nlist[ff,ii,jj]) is excluded, otherwise being 1.
deepmd.pt.utils.finetune module
deepmd.pt.utils.learning_rate module
deepmd.pt.utils.multi_task module
Preprocess the model params for multitask model, and generate the links dict for further sharing.
- Parameters
model_config – Model params of multitask model.
- Returns
- model_config:
Preprocessedmodelparamsofmultitaskmodel. Those string names are replaced with real params in shared_dict of model params.
- shared_links:
Dictoflinkinfosforfurthersharing. Each item, whose key must be in shared_dict, is a dict with following keys: - “type”: The real class type of this item. - “links”: List of shared settings, each sub-item is a dict with following keys:
“model_key”: Model key in the model_dict to share this item.
“shared_type”: Type of this shard item.
- “shared_level”: Shared level (int) of this item in this model.
Lower for more params to share, 0 means to share all params in this item.
This list are sorted by “shared_level”.
Forexample,ifonehasmodel_configlikethis:- “model”: {
- “shared_dict”: {
“my_type_map”: [“foo”, “bar”], “my_des1”: {
“type”: “se_e2_a”, “neuron”: [10, 20, 40] },
}, “model_dict”: {
- “model_1”: {
“type_map”: “my_type_map”, “descriptor”: “my_des1”, “fitting_net”: {
“neuron”: [100, 100, 100]
}
}, “model_2”: {
“type_map”: “my_type_map”, “descriptor”: “my_des1”, “fitting_net”: {
“neuron”: [100, 100, 100]
}
} “model_3”: {
“type_map”: “my_type_map”, “descriptor”: “my_des1:1”, “fitting_net”: {
“neuron”: [100, 100, 100]
}
}
}
- }
Theaboveconfigwillinitthreemodelbranchesnamedmodel_1andmodel_2andmodel_3,inwhich:model_2 and model_3 will have the same type_map as that in model_1.
model_2 will share all the parameters of descriptor with model_1,
while model_3 will share part of parameters of descriptor with model_1 on human-defined share-level 1 (default is 0, meaning share all the parameters). - model_1, model_2 and model_3 have three different `fitting_net`s.
Thereturnedmodel_configwillautomaticallyfulfilltheinputmodel_configasifthere’snosharing,andtheshared_linkswillkeepallthesharinginformationwithlooking:
- {
- ‘my_des1’: {
‘type’: ‘DescrptSeA’, ‘links’: [
{‘model_key’: ‘model_1’, ‘shared_type’: ‘descriptor’, ‘shared_level’: 0}, {‘model_key’: ‘model_2’, ‘shared_type’: ‘descriptor’, ‘shared_level’: 0}, {‘model_key’: ‘model_3’, ‘shared_type’: ‘descriptor’, ‘shared_level’: 1} ]
}
- }
- model_config:
deepmd.pt.utils.neighbor_stat module
- class deepmd.pt.utils.neighbor_stat.NeighborStat(ntypes: int, rcut: float, mixed_type: bool = False)[source]
Bases:
NeighborStatNeighbor statistics using pure NumPy.
- Parameters
Methods
get_stat(data)Get the data statistics of the training data, including nearest nbor distance between atoms, max nbor size of atoms.
iterator(data)Abstract method for producing data.
- class deepmd.pt.utils.neighbor_stat.NeighborStatOP(ntypes: int, rcut: float, mixed_types: bool)[source]
Bases:
ModuleClass for getting neighbor statics data information.
- Parameters
- ntypes
The num of atom types
- rcut
The cut-off radius
- mixed_typesbool,
optional If True, treat neighbors of all types as a single type.
Methods
add_module(name, module)Add a child module to the current module.
apply(fn)Apply
fnrecursively to every submodule (as returned by.children()) as well as self.bfloat16()Casts all floating point parameters and buffers to
bfloat16datatype.buffers([recurse])Return an iterator over module buffers.
children()Return an iterator over immediate children modules.
compile(*args, **kwargs)Compile this Module's forward using
torch.compile().cpu()Move all model parameters and buffers to the CPU.
cuda([device])Move all model parameters and buffers to the GPU.
double()Casts all floating point parameters and buffers to
doubledatatype.eval()Set the module in evaluation mode.
extra_repr()Set the extra representation of the module.
float()Casts all floating point parameters and buffers to
floatdatatype.forward(coord, atype, cell)Calculate the neareest neighbor distance between atoms, maximum nbor size of atoms and the output data range of the environment matrix.
get_buffer(target)Return the buffer given by
targetif it exists, otherwise throw an error.get_extra_state()Return any extra state to include in the module's state_dict.
get_parameter(target)Return the parameter given by
targetif it exists, otherwise throw an error.get_submodule(target)Return the submodule given by
targetif it exists, otherwise throw an error.half()Casts all floating point parameters and buffers to
halfdatatype.ipu([device])Move all model parameters and buffers to the IPU.
load_state_dict(state_dict[, strict, assign])Copy parameters and buffers from
state_dictinto this module and its descendants.modules()Return an iterator over all modules in the network.
named_buffers([prefix, recurse, ...])Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children()Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules([memo, prefix, remove_duplicate])Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters([prefix, recurse, ...])Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters([recurse])Return an iterator over module parameters.
register_backward_hook(hook)Register a backward hook on the module.
register_buffer(name, tensor[, persistent])Add a buffer to the module.
register_forward_hook(hook, *[, prepend, ...])Register a forward hook on the module.
register_forward_pre_hook(hook, *[, ...])Register a forward pre-hook on the module.
register_full_backward_hook(hook[, prepend])Register a backward hook on the module.
register_full_backward_pre_hook(hook[, prepend])Register a backward pre-hook on the module.
register_load_state_dict_post_hook(hook)Register a post hook to be run after module's
load_state_dictis called.register_module(name, module)Alias for
add_module().register_parameter(name, param)Add a parameter to the module.
register_state_dict_pre_hook(hook)Register a pre-hook for the
load_state_dict()method.requires_grad_([requires_grad])Change if autograd should record operations on parameters in this module.
set_extra_state(state)Set extra state contained in the loaded state_dict.
share_memory()See
torch.Tensor.share_memory_().state_dict(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the module.
to(*args, **kwargs)Move and/or cast the parameters and buffers.
to_empty(*, device[, recurse])Move the parameters and buffers to the specified device without copying storage.
train([mode])Set the module in training mode.
type(dst_type)Casts all parameters and buffers to
dst_type.xpu([device])Move all model parameters and buffers to the XPU.
zero_grad([set_to_none])Reset gradients of all model parameters.
__call__
- forward(coord: Tensor, atype: Tensor, cell: Optional[Tensor]) Tuple[Tensor, Tensor][source]
Calculate the neareest neighbor distance between atoms, maximum nbor size of atoms and the output data range of the environment matrix.
- Parameters
- coord
The coordinates of atoms.
- atype
The atom types.
- cell
The cell.
- Returns
torch.TensorThe minimal squared distance between two atoms, in the shape of (nframes,)
torch.TensorThe maximal number of neighbors
deepmd.pt.utils.nlist module
- deepmd.pt.utils.nlist.build_multiple_neighbor_list(coord: Tensor, nlist: Tensor, rcuts: List[float], nsels: List[int]) Dict[str, Tensor][source]
Input one neighbor list, and produce multiple neighbor lists with different cutoff radius and numbers of selection out of it. The required rcuts and nsels should be smaller or equal to the input nlist.
- Parameters
- coord
torch.Tensor exptended coordinates of shape [batch_size, nall x 3]
- nlist
torch.Tensor Neighbor list of shape [batch_size, nloc, nsel], the neighbors should be stored in an ascending order.
- rcuts
List[float] list of cut-off radius in ascending order.
- nsels
List[int] maximal number of neighbors in ascending order.
- coord
- Returns
- deepmd.pt.utils.nlist.build_neighbor_list(coord1: Tensor, atype: Tensor, nloc: int, rcut: float, sel: Union[int, List[int]], distinguish_types: bool = True) Tensor[source]
Build neightbor list for a single frame. keeps nsel neighbors.
- Parameters
- coord1
torch.Tensor exptended coordinates of shape [batch_size, nall x 3]
- atype
torch.Tensor extended atomic types of shape [batch_size, nall]
- nloc
int number of local atoms.
- rcut
float cut-off radius
- sel
intorList[int] maximal number of neighbors (of each type). if distinguish_types==True, nsel should be list and the length of nsel should be equal to number of types.
- distinguish_typesbool
distinguish different types.
- coord1
- Returns
- neighbor_list
torch.Tensor Neighbor list of shape [batch_size, nloc, nsel], the neighbors are stored in an ascending order. If the number of neighbors is less than nsel, the positions are masked with -1. The neighbor list of an atom looks like |------ nsel ------| xx xx xx xx -1 -1 -1 if distinguish_types==True and we have two types |---- nsel[0] -----| |---- nsel[1] -----| xx xx xx xx -1 -1 -1 xx xx xx -1 -1 -1 -1
- neighbor_list
- deepmd.pt.utils.nlist.extend_coord_with_ghosts(coord: Tensor, atype: Tensor, cell: Optional[Tensor], rcut: float)[source]
Extend the coordinates of the atoms by appending peridoc images. The number of images is large enough to ensure all the neighbors within rcut are appended.
- Parameters
- coord
torch.Tensor original coordinates of shape [-1, nloc*3].
- atype
torch.Tensor atom type of shape [-1, nloc].
- cell
torch.Tensor simulation cell tensor of shape [-1, 9].
- rcut
float the cutoff radius
- coord
- Returns
- extended_coord:
torch.Tensor extended coordinates of shape [-1, nall*3].
- extended_atype:
torch.Tensor extended atom type of shape [-1, nall].
- index_mapping:
torch.Tensor maping extended index to the local index
- extended_coord:
deepmd.pt.utils.plugin module
Base of plugin systems.
- class deepmd.pt.utils.plugin.Plugin[source]
Bases:
objectA class to register and restore plugins.
Examples
>>> plugin = Plugin() >>> @plugin.register("xx") def xxx(): pass >>> print(plugin.plugins["xx"])
Methods
get_plugin(key)Visit a plugin by key.
register(key)Register a plugin.
- class deepmd.pt.utils.plugin.PluginVariant(*args, **kwargs)[source]
Bases:
objectA class to remove type from input arguments.
- class deepmd.pt.utils.plugin.VariantABCMeta(name, bases, namespace, **kwargs)[source]
Bases:
VariantMeta,ABCMetaMethods
__call__(*args, **kwargs)Remove type and keys that starts with underline.
mro(/)Return a type's method resolution order.
register(subclass)Register a virtual subclass of an ABC.
deepmd.pt.utils.preprocess module
- class deepmd.pt.utils.preprocess.Region3D(boxt)[source]
Bases:
objectMethods
Return face distinces to each surface of YZ, ZX, XY.
inter2phys(coord)Convert internal coordinates to physical ones.
phys2inter(coord)Convert physical coordinates to internal ones.
- deepmd.pt.utils.preprocess.append_neighbors(coord, region: Region3D, atype, rcut: float)[source]
Make ghost atoms who are valid neighbors.
Args: - coord: shape is [nloc*3] - atype: shape is [nloc]
- deepmd.pt.utils.preprocess.build_inside_clist(coord, region: Region3D, ncell)[source]
Build cell list on atoms inside region.
Args: - coord: shape is [nloc*3] - ncell: shape is [3]
- deepmd.pt.utils.preprocess.build_neighbor_list(nloc: int, coord, atype, rcut: float, sec, mapping, type_split=True, min_check=False)[source]
For each atom inside region, build its neighbor list.
Args: - coord: shape is [nall*3] - atype: shape is [nall]
- deepmd.pt.utils.preprocess.compute_pbc_shift(cell_offset, ncell)[source]
Tell shift count to move the atom into region.
- deepmd.pt.utils.preprocess.compute_serial_cid(cell_offset, ncell)[source]
Tell the sequential cell ID in its 3D space.
Args: - cell_offset: shape is [3] - ncell: shape is [3]
- deepmd.pt.utils.preprocess.compute_smooth_weight(distance, rmin: float, rmax: float)[source]
Compute smooth weight for descriptor elements.
- deepmd.pt.utils.preprocess.make_env_mat(coord, atype, region, rcut: Union[float, list], sec, pbc=True, type_split=True, min_check=False)[source]
Based on atom coordinates, return environment matrix.
- Returns
- nlist:
nlist, [nloc,nnei] - merged_coord_shift:
shiftonnallatoms, [nall, 3] - merged_mapping:
mappingfromnallindextonlocindex, [nall]
- nlist:
deepmd.pt.utils.region module
- deepmd.pt.utils.region.inter2phys(coord: Tensor, cell: Tensor) Tensor[source]
Convert internal(direct) coordinates to physical coordinates.
- deepmd.pt.utils.region.normalize_coord(coord: Tensor, cell: Tensor) Tensor[source]
Apply PBC according to the atomic coordinates.
deepmd.pt.utils.serialization module
deepmd.pt.utils.stat module
deepmd.pt.utils.update_sel module
- class deepmd.pt.utils.update_sel.UpdateSel[source]
Bases:
BaseUpdateSel- Attributes
- neighbor_stat
Methods
get_min_nbor_dist
get_nbor_stat
get_rcut
get_sel
get_type_map
hook
parse_auto_sel
parse_auto_sel_ratio
update_one_sel
wrap_up_4
- property neighbor_stat: Type[NeighborStat]
deepmd.pt.utils.utils module
- class deepmd.pt.utils.utils.ActivationFn(activation: Optional[str])[source]
Bases:
ModuleMethods
add_module(name, module)Add a child module to the current module.
apply(fn)Apply
fnrecursively to every submodule (as returned by.children()) as well as self.bfloat16()Casts all floating point parameters and buffers to
bfloat16datatype.buffers([recurse])Return an iterator over module buffers.
children()Return an iterator over immediate children modules.
compile(*args, **kwargs)Compile this Module's forward using
torch.compile().cpu()Move all model parameters and buffers to the CPU.
cuda([device])Move all model parameters and buffers to the GPU.
double()Casts all floating point parameters and buffers to
doubledatatype.eval()Set the module in evaluation mode.
extra_repr()Set the extra representation of the module.
float()Casts all floating point parameters and buffers to
floatdatatype.forward(x)Returns the tensor after applying activation function corresponding to activation.
get_buffer(target)Return the buffer given by
targetif it exists, otherwise throw an error.get_extra_state()Return any extra state to include in the module's state_dict.
get_parameter(target)Return the parameter given by
targetif it exists, otherwise throw an error.get_submodule(target)Return the submodule given by
targetif it exists, otherwise throw an error.half()Casts all floating point parameters and buffers to
halfdatatype.ipu([device])Move all model parameters and buffers to the IPU.
load_state_dict(state_dict[, strict, assign])Copy parameters and buffers from
state_dictinto this module and its descendants.modules()Return an iterator over all modules in the network.
named_buffers([prefix, recurse, ...])Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children()Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.
named_modules([memo, prefix, remove_duplicate])Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.
named_parameters([prefix, recurse, ...])Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.
parameters([recurse])Return an iterator over module parameters.
register_backward_hook(hook)Register a backward hook on the module.
register_buffer(name, tensor[, persistent])Add a buffer to the module.
register_forward_hook(hook, *[, prepend, ...])Register a forward hook on the module.
register_forward_pre_hook(hook, *[, ...])Register a forward pre-hook on the module.
register_full_backward_hook(hook[, prepend])Register a backward hook on the module.
register_full_backward_pre_hook(hook[, prepend])Register a backward pre-hook on the module.
register_load_state_dict_post_hook(hook)Register a post hook to be run after module's
load_state_dictis called.register_module(name, module)Alias for
add_module().register_parameter(name, param)Add a parameter to the module.
register_state_dict_pre_hook(hook)Register a pre-hook for the
load_state_dict()method.requires_grad_([requires_grad])Change if autograd should record operations on parameters in this module.
set_extra_state(state)Set extra state contained in the loaded state_dict.
share_memory()See
torch.Tensor.share_memory_().state_dict(*args[, destination, prefix, ...])Return a dictionary containing references to the whole state of the module.
to(*args, **kwargs)Move and/or cast the parameters and buffers.
to_empty(*, device[, recurse])Move the parameters and buffers to the specified device without copying storage.
train([mode])Set the module in training mode.
type(dst_type)Casts all parameters and buffers to
dst_type.xpu([device])Move all model parameters and buffers to the XPU.
zero_grad([set_to_none])Reset gradients of all model parameters.
__call__
- deepmd.pt.utils.utils.get_activation_fn(activation: str) Callable[source]
Returns the activation function corresponding to activation.