deepmd.dpmodel.output_def

Module Contents

Classes

OutputVariableOperation

Defines the operation of the output variable.

OutputVariableCategory

Defines the category of the output variable.

OutputVariableDef

Defines the shape and other properties of the one output variable.

FittingOutputDef

Defines the shapes and other properties of the fitting network outputs.

ModelOutputDef

Defines the shapes and other properties of the model outputs.

Functions

check_shape(shape, def_shape)

Check if the shape satisfies the defined shape.

check_var(var, var_def)

model_check_output(cls)

Check if the output of the Model is consistent with the definition.

fitting_check_output(cls)

Check if the output of the Fitting is consistent with the definition.

get_reduce_name(→ str)

get_deriv_name(→ Tuple[str, str])

get_deriv_name_mag(→ Tuple[str, str])

get_hessian_name(→ str)

apply_operation(→ int)

Apply an operation to the category of a variable definition.

check_operation_applied(→ bool)

Check if a operation has been applied to a variable definition.

do_reduce(→ Dict[str, OutputVariableDef])

do_mask(→ Dict[str, OutputVariableDef])

do_derivative(→ Tuple[Dict[str, OutputVariableDef], ...)

deepmd.dpmodel.output_def.check_shape(shape: List[int], def_shape: List[int])[source]

Check if the shape satisfies the defined shape.

deepmd.dpmodel.output_def.check_var(var, var_def)[source]
deepmd.dpmodel.output_def.model_check_output(cls)[source]

Check if the output of the Model is consistent with the definition.

Two methods are assumed to be provided by the Model: 1. Model.output_def that gives the output definition. 2. Model.__call__ that defines the forward path of the model.

deepmd.dpmodel.output_def.fitting_check_output(cls)[source]

Check if the output of the Fitting is consistent with the definition.

Two methods are assumed to be provided by the Fitting: 1. Fitting.output_def that gives the output definition. 2. Fitting.__call__ defines the forward path of the fitting.

class deepmd.dpmodel.output_def.OutputVariableOperation[source]

Bases: enum.IntEnum

Defines the operation of the output variable.

_NONE = 0[source]

No operation.

REDU = 1[source]

Reduce the output variable.

DERV_R = 2[source]

Derivative w.r.t. coordinates.

DERV_C = 4[source]

Derivative w.r.t. cell.

_SEC_DERV_R = 8[source]

Second derivative w.r.t. coordinates.

MAG = 16[source]

Magnetic output.

class deepmd.dpmodel.output_def.OutputVariableCategory[source]

Bases: enum.IntEnum

Defines the category of the output variable.

OUT[source]

Output variable. (e.g. atom energy)

REDU[source]

Reduced output variable. (e.g. system energy)

DERV_R[source]

Negative derivative w.r.t. coordinates. (e.g. force)

DERV_C[source]

Atomic component of the virial, see PRB 104, 224202 (2021)

DERV_C_REDU[source]

Virial, the transposed negative gradient with cell tensor times cell tensor, see eq 40 JCP 159, 054801 (2023).

DERV_R_DERV_R[source]

Hession matrix, the second derivative w.r.t. coordinates.

DERV_R_MAG[source]

Magnetic part of negative derivative w.r.t. coordinates. (e.g. magnetic force)

DERV_C_MAG[source]

Magnetic part of atomic component of the virial.

class deepmd.dpmodel.output_def.OutputVariableDef(name: str, shape: List[int], reduciable: bool = False, r_differentiable: bool = False, c_differentiable: bool = False, atomic: bool = True, category: int = OutputVariableCategory.OUT.value, r_hessian: bool = False, magnetic: bool = False)[source]

Defines the shape and other properties of the one output variable.

It is assume that the fitting network output variables for each local atom. This class defines one output variable, including its name, shape, reducibility and differentiability.

Parameters:
name

Name of the output variable. Notice that the xxxx_redu, xxxx_derv_c, xxxx_derv_r are reserved names that should not be used to define variables.

shape

The shape of the variable. e.g. energy should be [1], dipole should be [3], polarizabilty should be [3,3].

reduciable

If the variable is reduced.

r_differentiable

If the variable is differentiated with respect to coordinates of atoms. Only reduciable variable are differentiable. Negative derivative w.r.t. coordinates will be calcualted. (e.g. force)

c_differentiable

If the variable is differentiated with respect to the cell tensor (pbc case). Only reduciable variable are differentiable. Virial, the transposed negative gradient with cell tensor times cell tensor, will be calculated, see eq 40 JCP 159, 054801 (2023).

atomicbool

If the variable is defined for each atom.

categoryint

The category of the output variable.

r_hessianbool

If hessian is requred

magneticbool

If the derivatives of variable have magnetic parts.

property size[source]
class deepmd.dpmodel.output_def.FittingOutputDef(var_defs: List[OutputVariableDef])[source]

Defines the shapes and other properties of the fitting network outputs.

It is assume that the fitting network output variables for each local atom. This class defines all the outputs.

Parameters:
var_defs

List of output variable definitions.

__getitem__(key: str) OutputVariableDef[source]
get_data() Dict[str, OutputVariableDef][source]
keys()[source]
class deepmd.dpmodel.output_def.ModelOutputDef(fit_defs: FittingOutputDef)[source]

Defines the shapes and other properties of the model outputs.

The model reduce and differentiate fitting outputs if applicable. If a variable is named by foo, then the reduced variable is called foo_redu, the derivative w.r.t. coordinates is called foo_derv_r and the derivative w.r.t. cell is called foo_derv_c.

Parameters:
fit_defs

Definition for the fitting net output

__getitem__(key: str) OutputVariableDef[source]
get_data(key: str) Dict[str, OutputVariableDef][source]
keys()[source]
keys_outp()[source]
keys_redu()[source]
keys_derv_r()[source]
keys_hess_r()[source]
keys_derv_c()[source]
keys_derv_c_redu()[source]
deepmd.dpmodel.output_def.get_reduce_name(name: str) str[source]
deepmd.dpmodel.output_def.get_deriv_name(name: str) Tuple[str, str][source]
deepmd.dpmodel.output_def.get_deriv_name_mag(name: str) Tuple[str, str][source]
deepmd.dpmodel.output_def.get_hessian_name(name: str) str[source]
deepmd.dpmodel.output_def.apply_operation(var_def: OutputVariableDef, op: OutputVariableOperation) int[source]

Apply an operation to the category of a variable definition.

Parameters:
var_defOutputVariableDef

The variable definition.

opOutputVariableOperation

The operation to be applied.

Returns:
int

The new category of the variable definition.

Raises:
ValueError

If the operation has been applied to the variable definition, and exceed the maximum limitation.

deepmd.dpmodel.output_def.check_operation_applied(var_def: OutputVariableDef, op: OutputVariableOperation) bool[source]

Check if a operation has been applied to a variable definition.

Parameters:
var_defOutputVariableDef

The variable definition.

opOutputVariableOperation

The operation to be checked.

Returns:
bool

True if the operation has been applied, False otherwise.

deepmd.dpmodel.output_def.do_reduce(def_outp_data: Dict[str, OutputVariableDef]) Dict[str, OutputVariableDef][source]
deepmd.dpmodel.output_def.do_mask(def_outp_data: Dict[str, OutputVariableDef]) Dict[str, OutputVariableDef][source]
deepmd.dpmodel.output_def.do_derivative(def_outp_data: Dict[str, OutputVariableDef]) Tuple[Dict[str, OutputVariableDef], Dict[str, OutputVariableDef]][source]