deepmd.tf.loss

Contents

deepmd.tf.loss#

Submodules#

Classes#

DOSLoss

Loss function for DeepDOS models.

EnerDipoleLoss

The abstract class for the loss function.

EnerSpinLoss

The abstract class for the loss function.

EnerStdLoss

Standard loss function for DP models.

TensorLoss

Loss function for tensorial properties.

Package Contents#

class deepmd.tf.loss.DOSLoss(starter_learning_rate: float, numb_dos: int = 500, start_pref_dos: float = 1.0, limit_pref_dos: float = 1.0, start_pref_cdf: float = 1000, limit_pref_cdf: float = 1.0, start_pref_ados: float = 0.0, limit_pref_ados: float = 0.0, start_pref_acdf: float = 0.0, limit_pref_acdf: float = 0.0, protect_value: float = 1e-08, log_fit: bool = False, **kwargs)[source]#

Bases: deepmd.tf.loss.loss.Loss

Loss function for DeepDOS models.

starter_learning_rate#
numb_dos = 500#
protect_value = 1e-08#
log_fit = False#
start_pref_dos = 1.0#
limit_pref_dos = 1.0#
start_pref_cdf = 1000#
limit_pref_cdf = 1.0#
start_pref_ados = 0.0#
limit_pref_ados = 0.0#
start_pref_acdf = 0.0#
limit_pref_acdf = 0.0#
has_dos#
has_cdf#
has_ados#
has_acdf#
build(learning_rate, natoms, model_dict, label_dict, suffix)[source]#

Build the loss function graph.

Parameters:
learning_ratetf.Tensor

learning rate

natomstf.Tensor

number of atoms

model_dictdict[str, tf.Tensor]

A dictionary that maps model keys to tensors

label_dictdict[str, tf.Tensor]

A dictionary that maps label keys to tensors

suffixstr

suffix

Returns:
tf.Tensor

the total squared loss

dict[str, tf.Tensor]

A dictionary that maps loss keys to more loss tensors

eval(sess, feed_dict, natoms)[source]#

Eval the loss function.

Parameters:
sesstf.Session

TensorFlow session

feed_dictdict[tf.placeholder, tf.Tensor]

A dictionary that maps graph elements to values

natomstf.Tensor

number of atoms

Returns:
dict

A dictionary that maps keys to values. It should contain key natoms

property label_requirement: list[deepmd.utils.data.DataRequirementItem]#

Return data label requirements needed for this loss calculation.

class deepmd.tf.loss.EnerDipoleLoss(starter_learning_rate: float, start_pref_e: float = 0.1, limit_pref_e: float = 1.0, start_pref_ed: float = 1.0, limit_pref_ed: float = 1.0)[source]#

Bases: deepmd.tf.loss.loss.Loss

The abstract class for the loss function.

starter_learning_rate#
start_pref_e = 0.1#
limit_pref_e = 1.0#
start_pref_ed = 1.0#
limit_pref_ed = 1.0#
build(learning_rate, natoms, model_dict, label_dict, suffix)[source]#

Build the loss function graph.

Parameters:
learning_ratetf.Tensor

learning rate

natomstf.Tensor

number of atoms

model_dictdict[str, tf.Tensor]

A dictionary that maps model keys to tensors

label_dictdict[str, tf.Tensor]

A dictionary that maps label keys to tensors

suffixstr

suffix

Returns:
tf.Tensor

the total squared loss

dict[str, tf.Tensor]

A dictionary that maps loss keys to more loss tensors

eval(sess, feed_dict, natoms)[source]#

Eval the loss function.

Parameters:
sesstf.Session

TensorFlow session

feed_dictdict[tf.placeholder, tf.Tensor]

A dictionary that maps graph elements to values

natomstf.Tensor

number of atoms

Returns:
dict

A dictionary that maps keys to values. It should contain key natoms

property label_requirement: list[deepmd.utils.data.DataRequirementItem]#

Return data label requirements needed for this loss calculation.

class deepmd.tf.loss.EnerSpinLoss(starter_learning_rate: float, start_pref_e: float = 0.02, limit_pref_e: float = 1.0, start_pref_fr: float = 1000, limit_pref_fr: float = 1.0, start_pref_fm: float = 10000, limit_pref_fm: float = 10.0, start_pref_v: float = 0.0, limit_pref_v: float = 0.0, start_pref_ae: float = 0.0, limit_pref_ae: float = 0.0, start_pref_pf: float = 0.0, limit_pref_pf: float = 0.0, relative_f: float | None = None, enable_atom_ener_coeff: bool = False, use_spin: list | None = None)[source]#

Bases: deepmd.tf.loss.loss.Loss

The abstract class for the loss function.

starter_learning_rate#
start_pref_e = 0.02#
limit_pref_e = 1.0#
start_pref_fr = 1000#
limit_pref_fr = 1.0#
start_pref_fm = 10000#
limit_pref_fm = 10.0#
start_pref_v = 0.0#
limit_pref_v = 0.0#
start_pref_ae = 0.0#
limit_pref_ae = 0.0#
start_pref_pf = 0.0#
limit_pref_pf = 0.0#
relative_f = None#
enable_atom_ener_coeff = False#
use_spin = None#
has_e#
has_fr#
has_fm#
has_v#
has_ae#
build(learning_rate, natoms, model_dict, label_dict, suffix)[source]#

Build the loss function graph.

Parameters:
learning_ratetf.Tensor

learning rate

natomstf.Tensor

number of atoms

model_dictdict[str, tf.Tensor]

A dictionary that maps model keys to tensors

label_dictdict[str, tf.Tensor]

A dictionary that maps label keys to tensors

suffixstr

suffix

Returns:
tf.Tensor

the total squared loss

dict[str, tf.Tensor]

A dictionary that maps loss keys to more loss tensors

eval(sess, feed_dict, natoms)[source]#

Eval the loss function.

Parameters:
sesstf.Session

TensorFlow session

feed_dictdict[tf.placeholder, tf.Tensor]

A dictionary that maps graph elements to values

natomstf.Tensor

number of atoms

Returns:
dict

A dictionary that maps keys to values. It should contain key natoms

print_header()[source]#
print_on_training(tb_writer, cur_batch, sess, natoms, feed_dict_test, feed_dict_batch)[source]#
property label_requirement: list[deepmd.utils.data.DataRequirementItem]#

Return data label requirements needed for this loss calculation.

class deepmd.tf.loss.EnerStdLoss(starter_learning_rate: float, start_pref_e: float = 0.02, limit_pref_e: float = 1.0, start_pref_f: float = 1000, limit_pref_f: float = 1.0, start_pref_v: float = 0.0, limit_pref_v: float = 0.0, start_pref_ae: float = 0.0, limit_pref_ae: float = 0.0, start_pref_pf: float = 0.0, limit_pref_pf: float = 0.0, relative_f: float | None = None, enable_atom_ener_coeff: bool = False, start_pref_gf: float = 0.0, limit_pref_gf: float = 0.0, numb_generalized_coord: int = 0, use_huber=False, huber_delta=0.01, **kwargs)[source]#

Bases: deepmd.tf.loss.loss.Loss

Standard loss function for DP models.

Parameters:
starter_learning_ratefloat

The learning rate at the start of the training.

start_pref_efloat

The prefactor of energy loss at the start of the training.

limit_pref_efloat

The prefactor of energy loss at the end of the training.

start_pref_ffloat

The prefactor of force loss at the start of the training.

limit_pref_ffloat

The prefactor of force loss at the end of the training.

start_pref_vfloat

The prefactor of virial loss at the start of the training.

limit_pref_vfloat

The prefactor of virial loss at the end of the training.

start_pref_aefloat

The prefactor of atomic energy loss at the start of the training.

limit_pref_aefloat

The prefactor of atomic energy loss at the end of the training.

start_pref_pffloat

The prefactor of atomic prefactor force loss at the start of the training.

limit_pref_pffloat

The prefactor of atomic prefactor force loss at the end of the training.

relative_ffloat

If provided, relative force error will be used in the loss. The difference of force will be normalized by the magnitude of the force in the label with a shift given by relative_f

enable_atom_ener_coeffbool

if true, the energy will be computed as sum_i c_i E_i

start_pref_gffloat

The prefactor of generalized force loss at the start of the training.

limit_pref_gffloat

The prefactor of generalized force loss at the end of the training.

numb_generalized_coordint

The dimension of generalized coordinates.

use_huberbool

Enables Huber loss calculation for energy/force/virial terms with user-defined threshold delta (D). The loss function smoothly transitions between L2 and L1 loss: - For absolute prediction errors within D: quadratic loss (0.5 * (error**2)) - For absolute errors exceeding D: linear loss (D * |error| - 0.5 * D) Formula: loss = 0.5 * (error**2) if |error| <= D else D * (|error| - 0.5 * D).

huber_deltafloat

The threshold delta (D) used for Huber loss, controlling transition between L2 and L1 loss.

**kwargs

Other keyword arguments.

starter_learning_rate#
start_pref_e = 0.02#
limit_pref_e = 1.0#
start_pref_f = 1000#
limit_pref_f = 1.0#
start_pref_v = 0.0#
limit_pref_v = 0.0#
start_pref_ae = 0.0#
limit_pref_ae = 0.0#
start_pref_pf = 0.0#
limit_pref_pf = 0.0#
relative_f = None#
enable_atom_ener_coeff = False#
start_pref_gf = 0.0#
limit_pref_gf = 0.0#
numb_generalized_coord = 0#
has_e#
has_f#
has_v#
has_ae#
has_pf#
has_gf#
use_huber = False#
huber_delta = 0.01#
build(learning_rate, natoms, model_dict, label_dict, suffix)[source]#

Build the loss function graph.

Parameters:
learning_ratetf.Tensor

learning rate

natomstf.Tensor

number of atoms

model_dictdict[str, tf.Tensor]

A dictionary that maps model keys to tensors

label_dictdict[str, tf.Tensor]

A dictionary that maps label keys to tensors

suffixstr

suffix

Returns:
tf.Tensor

the total squared loss

dict[str, tf.Tensor]

A dictionary that maps loss keys to more loss tensors

eval(sess, feed_dict, natoms)[source]#

Eval the loss function.

Parameters:
sesstf.Session

TensorFlow session

feed_dictdict[tf.placeholder, tf.Tensor]

A dictionary that maps graph elements to values

natomstf.Tensor

number of atoms

Returns:
dict

A dictionary that maps keys to values. It should contain key natoms

property label_requirement: list[deepmd.utils.data.DataRequirementItem]#

Return data label requirements needed for this loss calculation.

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

Serialize the loss module.

Parameters:
suffixstr

The suffix of the loss module

Returns:
dict

The serialized loss module

classmethod deserialize(data: dict, suffix: str = '') deepmd.tf.loss.loss.Loss[source]#

Deserialize the loss module.

Parameters:
datadict

The serialized loss module

suffixstr

The suffix of the loss module

Returns:
Loss

The deserialized loss module

class deepmd.tf.loss.TensorLoss(jdata, **kwarg)[source]#

Bases: deepmd.tf.loss.loss.Loss

Loss function for tensorial properties.

tensor_name#
tensor_size#
label_name#
local_weight#
global_weight#
enable_atomic_weight#
build(learning_rate, natoms, model_dict, label_dict, suffix)[source]#

Build the loss function graph.

Parameters:
learning_ratetf.Tensor

learning rate

natomstf.Tensor

number of atoms

model_dictdict[str, tf.Tensor]

A dictionary that maps model keys to tensors

label_dictdict[str, tf.Tensor]

A dictionary that maps label keys to tensors

suffixstr

suffix

Returns:
tf.Tensor

the total squared loss

dict[str, tf.Tensor]

A dictionary that maps loss keys to more loss tensors

eval(sess, feed_dict, natoms)[source]#

Eval the loss function.

Parameters:
sesstf.Session

TensorFlow session

feed_dictdict[tf.placeholder, tf.Tensor]

A dictionary that maps graph elements to values

natomstf.Tensor

number of atoms

Returns:
dict

A dictionary that maps keys to values. It should contain key natoms

property label_requirement: list[deepmd.utils.data.DataRequirementItem]#

Return data label requirements needed for this loss calculation.