deepmd.tf.fit.ener#

Attributes#

Classes#

EnerFitting

Fitting the energy of the system. The force and the virial can also be trained.

Functions#

change_energy_bias_lower(→ numpy.ndarray)

Change the energy bias according to the input data and the pretrained model.

Module Contents#

deepmd.tf.fit.ener.log[source]#
class deepmd.tf.fit.ener.EnerFitting(ntypes: int, dim_descrpt: int, neuron: list[int] = [120, 120, 120], resnet_dt: bool = True, numb_fparam: int = 0, numb_aparam: int = 0, dim_case_embd: int = 0, rcond: float | None = None, tot_ener_zero: bool = False, trainable: list[bool] | None = None, seed: int | None = None, atom_ener: list[float] = [], activation_function: str = 'tanh', precision: str = 'default', uniform_seed: bool = False, layer_name: list[str | None] | None = None, use_aparam_as_mask: bool = False, spin: deepmd.tf.utils.spin.Spin | None = None, mixed_types: bool = False, type_map: list[str] | None = None, default_fparam: list[float] | None = None, **kwargs: Any)[source]#

Bases: deepmd.tf.fit.fitting.Fitting

Fitting the energy of the system. The force and the virial can also be trained.

The potential energy \(E\) is a fitting network function of the descriptor \(\mathcal{D}\):

\[E(\mathcal{D}) = \mathcal{L}^{(n)} \circ \mathcal{L}^{(n-1)} \circ \cdots \circ \mathcal{L}^{(1)} \circ \mathcal{L}^{(0)}\]

The first \(n\) hidden layers \(\mathcal{L}^{(0)}, \cdots, \mathcal{L}^{(n-1)}\) are given by

\[\mathbf{y}=\mathcal{L}(\mathbf{x};\mathbf{w},\mathbf{b})= \boldsymbol{\phi}(\mathbf{x}^T\mathbf{w}+\mathbf{b})\]

where \(\mathbf{x} \in \mathbb{R}^{N_1}\) is the input vector and \(\mathbf{y} \in \mathbb{R}^{N_2}\) is the output vector. \(\mathbf{w} \in \mathbb{R}^{N_1 \times N_2}\) and \(\mathbf{b} \in \mathbb{R}^{N_2}\) are weights and biases, respectively, both of which are trainable if trainable[i] is True. \(\boldsymbol{\phi}\) is the activation function.

The output layer \(\mathcal{L}^{(n)}\) is given by

\[\mathbf{y}=\mathcal{L}^{(n)}(\mathbf{x};\mathbf{w},\mathbf{b})= \mathbf{x}^T\mathbf{w}+\mathbf{b}\]

where \(\mathbf{x} \in \mathbb{R}^{N_{n-1}}\) is the input vector and \(\mathbf{y} \in \mathbb{R}\) is the output scalar. \(\mathbf{w} \in \mathbb{R}^{N_{n-1}}\) and \(\mathbf{b} \in \mathbb{R}\) are weights and bias, respectively, both of which are trainable if trainable[n] is True.

Parameters:
ntypes

The ntypes of the descriptor \(\mathcal{D}\)

dim_descrpt

The dimension of the descriptor \(\mathcal{D}\)

neuron

Number of neurons \(N\) in each hidden layer of the fitting net

resnet_dt

Time-step dt in the resnet construction: \(y = x + dt * \phi (Wx + b)\)

numb_fparam

Number of frame parameter

numb_aparam

Number of atomic parameter

dim_case_embd

Dimension of case specific embedding.

default_fparam

The default frame parameter. This parameter is not supported in TensorFlow.

rcond

The condition number for the regression of atomic energy.

tot_ener_zero

Force the total energy to zero. Useful for the charge fitting.

trainable

If the weights of fitting net are trainable. Suppose that we have \(N_l\) hidden layers in the fitting net, this list is of length \(N_l + 1\), specifying if the hidden layers and the output layer are trainable.

seed

Random seed for initializing the network parameters.

atom_ener

Specifying atomic energy contribution in vacuum. The set_davg_zero key in the descriptor should be set.

activation_function

The activation function \(\boldsymbol{\phi}\) in the embedding net. Supported options are “softplus”, “tanh”, “linear”, “gelu_tf”, “silu”, “none”, “relu6”, “gelu”, “silut”, “sigmoid”, “relu”.

precision

The precision of the embedding net parameters. Supported options are “bfloat16”, “float16”, “default”, “float64”, “float32”.

uniform_seed

Only for the purpose of backward compatibility, retrieves the old behavior of using the random seed

layer_namelist[Optional[str]], optional

The name of the each layer. If two layers, either in the same fitting or different fittings, have the same name, they will share the same neural network parameters.

use_aparam_as_mask: bool, optional

If True, the atomic parameters will be used as a mask that determines the atom is real/virtual. And the aparam will not be used as the atomic parameters for embedding.

mixed_typesbool

If true, use a uniform fitting net for all atom types, otherwise use different fitting nets for different atom types.

default_fparam: list[float], optional

The default frame parameter. If set, when fparam.npy files are not included in the data system, this value will be used as the default value for the frame parameter in the fitting net.

type_map: list[str], Optional

A list of strings. Give the name to each type of atoms.

ntypes[source]#
dim_descrpt[source]#
use_aparam_as_mask = False[source]#
numb_fparam = 0[source]#
numb_aparam = 0[source]#
dim_case_embd = 0[source]#
default_fparam = None[source]#
n_neuron = [120, 120, 120][source]#
resnet_dt = True[source]#
rcond = None[source]#
seed = None[source]#
uniform_seed = False[source]#
spin = None[source]#
ntypes_spin[source]#
seed_shift = 3[source]#
tot_ener_zero = False[source]#
activation_function_name = 'tanh'[source]#
fitting_activation_fn[source]#
fitting_precision[source]#
trainable = None[source]#
type_map = None[source]#
atom_ener = [][source]#
atom_ener_v = [][source]#
useBN = False[source]#
bias_atom_e[source]#
fparam_avg = None[source]#
fparam_std = None[source]#
fparam_inv_std = None[source]#
aparam_avg = None[source]#
aparam_std = None[source]#
aparam_inv_std = None[source]#
fitting_net_variables = None[source]#
mixed_prec = None[source]#
layer_name = None[source]#
mixed_types = False[source]#
tebd_dim = 0[source]#
get_numb_fparam() int[source]#

Get the number of frame parameters.

get_numb_aparam() int[source]#

Get the number of atomic parameters.

compute_output_stats(all_stat: dict, mixed_type: bool = False) None[source]#

Compute the output statistics.

Parameters:
all_stat

must have the following components: all_stat[‘energy’] of shape n_sys x n_batch x n_frame can be prepared by model.make_stat_input

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

_compute_output_stats(all_stat: dict[str, Any], rcond: float = 0.001, mixed_type: bool = False) tuple[source]#
compute_input_stats(all_stat: dict, protection: float = 0.01) None[source]#

Compute the input statistics.

Parameters:
all_stat

if numb_fparam > 0 must have all_stat[‘fparam’] if numb_aparam > 0 must have all_stat[‘aparam’] can be prepared by model.make_stat_input

protection

Divided-by-zero protection

_compute_std(sumv2: float, sumv: float, sumn: int) float[source]#
_build_lower(start_index: int, natoms: deepmd.tf.env.tf.Tensor, inputs: deepmd.tf.env.tf.Tensor, fparam: deepmd.tf.env.tf.Tensor | None = None, aparam: deepmd.tf.env.tf.Tensor | None = None, bias_atom_e: float = 0.0, type_suffix: str = '', suffix: str = '', reuse: bool | None = None) deepmd.tf.env.tf.Tensor[source]#
build(inputs: deepmd.tf.env.tf.Tensor, natoms: deepmd.tf.env.tf.Tensor, input_dict: dict | None = None, reuse: bool | None = None, suffix: str = '') deepmd.tf.env.tf.Tensor[source]#

Build the computational graph for fitting net.

Parameters:
inputs

The input descriptor

input_dict

Additional dict for inputs. if numb_fparam > 0, should have input_dict[‘fparam’] if numb_aparam > 0, should have input_dict[‘aparam’]

natoms

The number of atoms. This tensor has the length of Ntypes + 2 natoms[0]: number of local atoms natoms[1]: total number of atoms held by this processor natoms[i]: 2 <= i < Ntypes+2, number of type i atoms

reuse

The weights in the networks should be reused when get the variable.

suffix

Name suffix to identify this descriptor

Returns:
ener

The system energy

init_variables(graph: deepmd.tf.env.tf.Graph, graph_def: deepmd.tf.env.tf.GraphDef, suffix: str = '') None[source]#

Init the fitting net variables with the given dict.

Parameters:
graphtf.Graph

The input frozen model graph

graph_deftf.GraphDef

The input frozen model graph_def

suffixstr

suffix to name scope

change_energy_bias(data: deepmd.utils.data_system.DeepmdDataSystem, frozen_model: str, origin_type_map: list, full_type_map: list, bias_adjust_mode: str = 'change-by-statistic', ntest: int = 10) None[source]#
enable_mixed_precision(mixed_prec: dict | None = None) None[source]#

Receive the mixed precision setting.

Parameters:
mixed_prec

The mixed precision setting used in the embedding net

get_loss(loss: dict, lr: deepmd.tf.utils.learning_rate.LearningRateExp) deepmd.tf.loss.loss.Loss[source]#

Get the loss function.

Parameters:
lossdict

The loss function parameters.

lrLearningRateSchedule

The learning rate.

Returns:
Loss

The loss function.

classmethod deserialize(data: dict, suffix: str = '') EnerFitting[source]#

Deserialize the model.

Parameters:
datadict

The serialized data

Returns:
Model

The deserialized model

serialize(suffix: str = '') dict[source]#

Serialize the model.

Returns:
dict

The serialized data

property input_requirement: list[deepmd.utils.data.DataRequirementItem][source]#

Return data requirements needed for the model input.

deepmd.tf.fit.ener.change_energy_bias_lower(data: deepmd.utils.data_system.DeepmdDataSystem, dp: deepmd.infer.deep_eval.DeepEval, origin_type_map: list[str], full_type_map: list[str], bias_atom_e: numpy.ndarray, bias_adjust_mode: str = 'change-by-statistic', ntest: int = 10) numpy.ndarray[source]#

Change the energy bias according to the input data and the pretrained model.

Parameters:
dataDeepmdDataSystem

The training data.

dpstr

The DeepEval object.

origin_type_maplist

The original type_map in dataset, they are targets to change the energy bias.

full_type_mapstr

The full type_map in pretrained model

bias_atom_enp.ndarray

The old energy bias in the pretrained model.

bias_adjust_modestr

The mode for changing energy bias : [‘change-by-statistic’, ‘set-by-statistic’] ‘change-by-statistic’ : perform predictions on energies of target dataset,

and do least square on the errors to obtain the target shift as bias.

‘set-by-statistic’ : directly use the statistic energy bias in the target dataset.

ntestint

The number of test samples in a system to change the energy bias.