deepmd.dpmodel.utils.network#
Native DP model format for multiple backends.
See issue #2982 for more information.
Attributes#
Classes#
The unit operation of a native model. | |
Native representation of a layer. | |
Implementation of Layer Normalization layer. | |
A collection of networks for multiple elements. |
Functions#
| Sigmoid. |
| |
| |
| |
| |
| Aggregate rows in data by specifying the owners. |
| Get the index mapping for edge graph and angle graph, ready in aggregate or index_select. |
Module Contents#
- deepmd.dpmodel.utils.network.sigmoid_t(x: numpy.ndarray) numpy.ndarray[source]#
Sigmoid.
- class deepmd.dpmodel.utils.network.Identity[source]#
Bases:
deepmd.dpmodel.NativeOPThe unit operation of a native model.
- call(x: numpy.ndarray) numpy.ndarray[source]#
The Identity operation layer.
- class deepmd.dpmodel.utils.network.NativeLayer(num_in, num_out, bias: bool = True, use_timestep: bool = False, activation_function: str | None = None, resnet: bool = False, precision: str = DEFAULT_PRECISION, seed: int | list[int] | None = None)[source]#
Bases:
deepmd.dpmodel.NativeOPNative representation of a layer.
- Parameters:
- w
np.ndarray,optional The weights of the layer.
- b
np.ndarray,optional The biases of the layer.
- idt
np.ndarray,optional The identity matrix of the layer.
- activation_function
str,optional The activation function of the layer.
- resnetbool,
optional Whether the layer is a residual layer.
- precision
str,optional The precision of the layer.
- seed
int,optional Random seed.
- w
- classmethod deserialize(data: dict) NativeLayer[source]#
Deserialize the layer from a dict.
- Parameters:
- data
dict The dict to deserialize from.
- data
- call(x: numpy.ndarray) numpy.ndarray[source]#
Forward pass.
- Parameters:
- x
np.ndarray The input.
- x
- Returns:
np.ndarrayThe output.
- deepmd.dpmodel.utils.network.get_activation_fn(activation_function: str) Callable[[numpy.ndarray], numpy.ndarray][source]#
- class deepmd.dpmodel.utils.network.LayerNorm(num_in: int, eps: float = 1e-05, uni_init: bool = True, trainable: bool = True, precision: str = DEFAULT_PRECISION, seed: int | list[int] | None = None)[source]#
Bases:
NativeLayerImplementation of Layer Normalization layer.
- Parameters:
- num_in
int The input dimension of the layer.
- eps
float,optional A small value added to prevent division by zero in calculations.
- uni_initbool,
optional If initialize the weights to be zeros and ones.
- trainablebool,
optional If the weights are trainable.
- precision
str,optional The precision of the layer.
- seed
int,optional Random seed.
- num_in
- classmethod deserialize(data: dict) LayerNorm[source]#
Deserialize the layer from a dict.
- Parameters:
- data
dict The dict to deserialize from.
- data
- call(x: numpy.ndarray) numpy.ndarray[source]#
Forward pass.
- Parameters:
- x
np.ndarray The input.
- x
- Returns:
np.ndarrayThe output.
- deepmd.dpmodel.utils.network.make_fitting_network(T_EmbeddingNet, T_Network, T_NetworkLayer)[source]#
- class deepmd.dpmodel.utils.network.NetworkCollection(ndim: int, ntypes: int, network_type: str = 'network', networks: list[NativeNet | dict] = [])[source]#
A collection of networks for multiple elements.
The number of dimensions for types might be 0, 1, or 2. - 0: embedding or fitting with type embedding, in () - 1: embedding with type_one_side, or fitting, in (type_i) - 2: embedding without type_one_side, in (type_i, type_j)
- Parameters:
- check_completeness() None[source]#
Check whether the collection is complete.
- Raises:
RuntimeErrorIf the collection is incomplete.
- classmethod deserialize(data: dict) NetworkCollection[source]#
Deserialize the networks from a dict.
- Parameters:
- data
dict The dict to deserialize from.
- data
- deepmd.dpmodel.utils.network.aggregate(data: numpy.ndarray, owners: numpy.ndarray, average=True, num_owner=None)[source]#
Aggregate rows in data by specifying the owners.
- Parameters:
- Returns:
- output: [
num_owner,feature_dim]
- output: [
- deepmd.dpmodel.utils.network.get_graph_index(nlist: numpy.ndarray, nlist_mask: numpy.ndarray, a_nlist_mask: numpy.ndarray, nall: int, use_loc_mapping: bool = True)[source]#
Get the index mapping for edge graph and angle graph, ready in aggregate or index_select.
- Parameters:
- nlist
nfxnlocxnnei Neighbor list. (padded neis are set to 0)
- nlist_mask
nfxnlocxnnei Masks of the neighbor list. real nei 1 otherwise 0
- a_nlist_mask
nfxnlocxa_nnei Masks of the neighbor list for angle. real nei 1 otherwise 0
- nall
The number of extended atoms.
- use_loc_mapping
Whether to use local atom index mapping in training or non-parallel inference. When True, local indexing and mapping are applied to neighbor lists and embeddings during descriptor computation.
- nlist
- Returns:
- edge_index
n_edgex2 - n2e_indexn_edge
Broadcast indices from node(i) to edge(ij), or reduction indices from edge(ij) to node(i).
- n_ext2e_indexn_edge
Broadcast indices from extended node(j) to edge(ij).
- angle_index
n_anglex3 - n2a_indexn_angle
Broadcast indices from extended node(j) to angle(ijk).
- eij2a_indexn_angle
Broadcast indices from extended edge(ij) to angle(ijk), or reduction indices from angle(ijk) to edge(ij).
- eik2a_indexn_angle
Broadcast indices from extended edge(ik) to angle(ijk).
- edge_index