deepmd.utils package

Submodules

deepmd.utils.argcheck module

deepmd.utils.argcheck.descrpt_hybrid_args()[source]
deepmd.utils.argcheck.descrpt_local_frame_args()[source]
deepmd.utils.argcheck.descrpt_se_a_args()[source]
deepmd.utils.argcheck.descrpt_se_a_tpe_args()[source]
deepmd.utils.argcheck.descrpt_se_ar_args()[source]
deepmd.utils.argcheck.descrpt_se_r_args()[source]
deepmd.utils.argcheck.descrpt_se_t_args()[source]
deepmd.utils.argcheck.descrpt_variant_type_args()[source]
deepmd.utils.argcheck.fitting_dipole()[source]
deepmd.utils.argcheck.fitting_ener()[source]
deepmd.utils.argcheck.fitting_polar()[source]
deepmd.utils.argcheck.fitting_variant_type_args()[source]
deepmd.utils.argcheck.gen_doc(*, make_anchor=True, make_link=True, **kwargs)[source]
deepmd.utils.argcheck.gen_json(**kwargs)[source]
deepmd.utils.argcheck.learning_rate_args()[source]
deepmd.utils.argcheck.learning_rate_exp()[source]
deepmd.utils.argcheck.learning_rate_variant_type_args()[source]
deepmd.utils.argcheck.limit_pref(item)[source]
deepmd.utils.argcheck.list_to_doc(xx)[source]
deepmd.utils.argcheck.loss_args()[source]
deepmd.utils.argcheck.loss_ener()[source]
deepmd.utils.argcheck.loss_tensor()[source]
deepmd.utils.argcheck.loss_variant_type_args()[source]
deepmd.utils.argcheck.make_index(keys)[source]
deepmd.utils.argcheck.model_args()[source]
deepmd.utils.argcheck.model_compression()[source]
deepmd.utils.argcheck.model_compression_type_args()[source]
deepmd.utils.argcheck.modifier_dipole_charge()[source]
deepmd.utils.argcheck.modifier_variant_type_args()[source]
deepmd.utils.argcheck.normalize(data)[source]
deepmd.utils.argcheck.normalize_hybrid_list(hy_list)[source]
deepmd.utils.argcheck.start_pref(item)[source]
deepmd.utils.argcheck.training_args()[source]
deepmd.utils.argcheck.training_data_args()[source]
deepmd.utils.argcheck.type_embedding_args()[source]
deepmd.utils.argcheck.validation_data_args()[source]

deepmd.utils.compat module

Module providing compatibility between 0.x.x and 1.x.x input versions.

deepmd.utils.compat.convert_input_v0_v1(jdata: Dict[str, Any], warning: bool = True, dump: Optional[Union[str, pathlib.Path]] = None)Dict[str, Any][source]

Convert input from v0 format to v1.

Parameters
jdataDict[str, Any]

loaded json/yaml file

warningbool, optional

whether to show deprecation warning, by default True

dumpOptional[Union[str, Path]], optional

whether to dump converted file, by default None

Returns
Dict[str, Any]

converted output

deepmd.utils.compat.convert_input_v1_v2(jdata: Dict[str, Any], warning: bool = True, dump: Optional[Union[str, pathlib.Path]] = None)Dict[str, Any][source]
deepmd.utils.compat.remove_decay_rate(jdata: Dict[str, Any])[source]

convert decay_rate to stop_lr.

Parameters
jdata: Dict[str, Any]

input data

deepmd.utils.compat.updata_deepmd_input(jdata: Dict[str, Any], warning: bool = True, dump: Optional[Union[str, pathlib.Path]] = None)Dict[str, Any][source]

deepmd.utils.convert module

deepmd.utils.convert.convert_12_to_20(input_model: str, output_model: str)[source]
deepmd.utils.convert.convert_13_to_20(input_model: str, output_model: str)[source]
deepmd.utils.convert.convert_dp12_to_dp13(file)[source]
deepmd.utils.convert.convert_dp13_to_dp20(fname: str)[source]
deepmd.utils.convert.convert_pb_to_pbtxt(pbfile: str, pbtxtfile: str)[source]
deepmd.utils.convert.convert_pbtxt_to_pb(pbtxtfile: str, pbfile: str)[source]

deepmd.utils.data module

class deepmd.utils.data.DataSets(sys_path, set_prefix, seed=None, shuffle_test=True)[source]

Bases: object

Outdated class for one data system.

Deprecated since version 2.0.0: This class is not maintained any more.

Methods

get_batch(batch_size)

returned property prefector [4] in order: energy, force, virial, atom_ener

get_test()

returned property prefector [4] in order: energy, force, virial, atom_ener

load_energy(set_name, nframes, nvalues, …)

return : coeff_ener, ener, coeff_atom_ener, atom_ener

check_batch_size

check_test_size

get_ener

get_natoms

get_natoms_2

get_natoms_vec

get_numb_set

get_set

get_sys_numb_batch

get_type_map

load_batch_set

load_data

load_set

load_test_set

load_type

load_type_map

numb_aparam

numb_fparam

reset_iter

set_numb_batch

stats_energy

check_batch_size(batch_size)[source]
check_test_size(test_size)[source]
get_batch(batch_size)[source]

returned property prefector [4] in order: energy, force, virial, atom_ener

get_ener()[source]
get_natoms()[source]
get_natoms_2(ntypes)[source]
get_natoms_vec(ntypes)[source]
get_numb_set()[source]
get_set(data, idx=None)[source]
get_sys_numb_batch(batch_size)[source]
get_test()[source]

returned property prefector [4] in order: energy, force, virial, atom_ener

get_type_map()[source]
load_batch_set(set_name)[source]
load_data(set_name, data_name, shape, is_necessary=True)[source]
load_energy(set_name, nframes, nvalues, energy_file, atom_energy_file)[source]

return : coeff_ener, ener, coeff_atom_ener, atom_ener

load_set(set_name, shuffle=True)[source]
load_test_set(set_name, shuffle_test)[source]
load_type(sys_path)[source]
load_type_map(sys_path)[source]
numb_aparam()[source]
numb_fparam()[source]
reset_iter()[source]
set_numb_batch(batch_size)[source]
stats_energy()[source]
class deepmd.utils.data.DeepmdData(sys_path: str, set_prefix: str = 'set', shuffle_test: bool = True, type_map: Optional[List[str]] = None, modifier=None, trn_all_set: bool = False)[source]

Bases: object

Class for a data system.

It loads data from hard disk, and mantains the data as a data_dict

Parameters
sys_path

Path to the data system

set_prefix

Prefix for the directories of different sets

shuffle_test

If the test data are shuffled

type_map

Gives the name of different atom types

modifier

Data modifier that has the method modify_data

trn_all_set

Use all sets as training dataset. Otherwise, if the number of sets is more than 1, the last set is left for test.

Methods

add(key, ndof[, atomic, must, high_prec, …])

Add a data item that to be loaded

avg(key)

Return the average value of an item.

check_batch_size(batch_size)

Check if the system can get a batch of data with batch_size frames.

check_test_size(test_size)

Check if the system can get a test dataset with test_size frames.

get_atom_type()

Get atom types

get_batch(batch_size)

Get a batch of data with batch_size frames.

get_data_dict()

Get the data_dict

get_natoms()

Get number of atoms

get_natoms_vec(ntypes)

Get number of atoms and number of atoms in different types

get_ntypes()

Number of atom types in the system

get_numb_batch(batch_size, set_idx)

Get the number of batches in a set.

get_numb_set()

Get number of training sets

get_sys_numb_batch(batch_size)

Get the number of batches in the data system.

get_test([ntests])

Get the test data with ntests frames.

get_type_map()

Get the type map

reduce(key_out, key_in)

Generate a new item from the reduction of another atom

reset_get_batch

add(key: str, ndof: int, atomic: bool = False, must: bool = False, high_prec: bool = False, type_sel: Optional[List[int]] = None, repeat: int = 1)[source]

Add a data item that to be loaded

Parameters
key

The key of the item. The corresponding data is stored in sys_path/set.*/key.npy

ndof

The number of dof

atomic

The item is an atomic property. If False, the size of the data should be nframes x ndof If True, the size of data should be nframes x natoms x ndof

must

The data file sys_path/set.*/key.npy must exist. If must is False and the data file does not exist, the data_dict[find_key] is set to 0.0

high_prec

Load the data and store in float64, otherwise in float32

type_sel

Select certain type of atoms

repeat

The data will be repeated repeat times.

avg(key)[source]

Return the average value of an item.

check_batch_size(batch_size)[source]

Check if the system can get a batch of data with batch_size frames.

check_test_size(test_size)[source]

Check if the system can get a test dataset with test_size frames.

get_atom_type()List[int][source]

Get atom types

get_batch(batch_size: int)dict[source]

Get a batch of data with batch_size frames. The frames are randomly picked from the data system.

Parameters
batch_size

size of the batch

get_data_dict()dict[source]

Get the data_dict

get_natoms()[source]

Get number of atoms

get_natoms_vec(ntypes: int)[source]

Get number of atoms and number of atoms in different types

Parameters
ntypes

Number of types (may be larger than the actual number of types in the system).

Returns
natoms

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

get_ntypes()int[source]

Number of atom types in the system

get_numb_batch(batch_size: int, set_idx: int)int[source]

Get the number of batches in a set.

get_numb_set()int[source]

Get number of training sets

get_sys_numb_batch(batch_size: int)int[source]

Get the number of batches in the data system.

get_test(ntests: int = - 1)dict[source]

Get the test data with ntests frames.

Parameters
ntests

Size of the test data set. If ntests is -1, all test data will be get.

get_type_map()List[str][source]

Get the type map

reduce(key_out: str, key_in: str)[source]

Generate a new item from the reduction of another atom

Parameters
key_out

The name of the reduced item

key_in

The name of the data item to be reduced

reset_get_batch()[source]

deepmd.utils.data_system module

class deepmd.utils.data_system.DataSystem(systems, set_prefix, batch_size, test_size, rcut, run_opt=None)[source]

Bases: object

Outdated class for the data systems.

Deprecated since version 2.0.0: This class is not maintained any more.

Methods

check_type_map_consistency

compute_energy_shift

format_name_length

get_batch

get_batch_size

get_nbatches

get_nsystems

get_ntypes

get_sys

get_test

get_type_map

numb_fparam

print_summary

process_sys_weights

check_type_map_consistency(type_map_list)[source]
compute_energy_shift()[source]
format_name_length(name, width)[source]
get_batch(sys_idx=None, sys_weights=None, style='prob_sys_size')[source]
get_batch_size()[source]
get_nbatches()[source]
get_nsystems()[source]
get_ntypes()[source]
get_sys(sys_idx)[source]
get_test(sys_idx=None)[source]
get_type_map()[source]
numb_fparam()[source]
print_summary()[source]
process_sys_weights(sys_weights)[source]
class deepmd.utils.data_system.DeepmdDataSystem(systems: List[str], batch_size: int, test_size: int, rcut: float, set_prefix: str = 'set', shuffle_test: bool = True, type_map: Optional[List[str]] = None, modifier=None, trn_all_set=False, sys_probs=None, auto_prob_style='prob_sys_size')[source]

Bases: object

Class for manipulating many data systems.

It is implemented with the help of DeepmdData

Methods

add(key, ndof[, atomic, must, high_prec, …])

Add a data item that to be loaded

add_dict(adict)

Add items to the data system by a dict. adict should have items like adict[key] = { ‘ndof’: ndof, ‘atomic’: atomic, ‘must’: must, ‘high_prec’: high_prec, ‘type_sel’: type_sel, ‘repeat’: repeat, } For the explaination of the keys see add.

get_batch([sys_idx])

Get a batch of data from the data systems

get_batch_size()

Get the batch size

get_nbatches()

Get the total number of batches

get_nsystems()

Get the number of data systems

get_ntypes()

Get the number of types

get_sys(idx)

Get a certain data system

get_sys_ntest([sys_idx])

Get number of tests for the currently selected system,

get_test([sys_idx, n_test])

Get test data from the the data systems.

get_type_map()

Get the type map

reduce(key_out, key_in)

Generate a new item from the reduction of another atom

compute_energy_shift

get_data_dict

print_summary

set_sys_probs

add(key: str, ndof: int, atomic: bool = False, must: bool = False, high_prec: bool = False, type_sel: Optional[List[int]] = None, repeat: int = 1)[source]

Add a data item that to be loaded

Parameters
key

The key of the item. The corresponding data is stored in sys_path/set.*/key.npy

ndof

The number of dof

atomic

The item is an atomic property. If False, the size of the data should be nframes x ndof If True, the size of data should be nframes x natoms x ndof

must

The data file sys_path/set.*/key.npy must exist. If must is False and the data file does not exist, the data_dict[find_key] is set to 0.0

high_prec

Load the data and store in float64, otherwise in float32

type_sel

Select certain type of atoms

repeat

The data will be repeated repeat times.

add_dict(adict: dict)None[source]

Add items to the data system by a dict. adict should have items like adict[key] = {

‘ndof’: ndof, ‘atomic’: atomic, ‘must’: must, ‘high_prec’: high_prec, ‘type_sel’: type_sel, ‘repeat’: repeat,

} For the explaination of the keys see add

compute_energy_shift(rcond=0.001, key='energy')[source]
get_batch(sys_idx: Optional[int] = None)[source]

Get a batch of data from the data systems

Parameters
sys_idx: int

The index of system from which the batch is get. If sys_idx is not None, sys_probs and auto_prob_style are ignored If sys_idx is None, automatically determine the system according to sys_probs or auto_prob_style, see the following.

get_batch_size()int[source]

Get the batch size

get_data_dict(ii: int = 0)dict[source]
get_nbatches()int[source]

Get the total number of batches

get_nsystems()int[source]

Get the number of data systems

get_ntypes()int[source]

Get the number of types

get_sys(idx: int)deepmd.utils.data.DeepmdData[source]

Get a certain data system

get_sys_ntest(sys_idx=None)[source]
Get number of tests for the currently selected system,

or one defined by sys_idx.

get_test(sys_idx: Optional[int] = None, n_test: int = - 1)[source]

Get test data from the the data systems.

Parameters
sys_idx

The test dat of system with index sys_idx will be returned. If is None, the currently selected system will be returned.

n_test

Number of test data. If set to -1 all test data will be get.

get_type_map()List[str][source]

Get the type map

print_summary(name)[source]
reduce(key_out, key_in)[source]

Generate a new item from the reduction of another atom

Parameters
key_out

The name of the reduced item

key_in

The name of the data item to be reduced

set_sys_probs(sys_probs=None, auto_prob_style: str = 'prob_sys_size')[source]

deepmd.utils.errors module

exception deepmd.utils.errors.GraphTooLargeError[source]

Bases: Exception

exception deepmd.utils.errors.GraphWithoutTensorError[source]

Bases: Exception

deepmd.utils.graph module

deepmd.utils.graph.get_embedding_net_nodes(model_file: str, suffix: str = '')Dict[source]

Get the embedding net nodes with the given frozen model(model_file)

Parameters
model_file

The input frozen model path

suffixstr, optional

The suffix of the scope

Returns
Dict

The embedding net nodes with the given frozen model

deepmd.utils.graph.get_embedding_net_nodes_from_graph_def(graph_def: tensorflow.core.framework.graph_pb2.GraphDef, suffix: str = '')Dict[source]

Get the embedding net nodes with the given tf.GraphDef object

Parameters
graph_def

The input tf.GraphDef object

suffixstr, optional

The scope suffix

Returns
Dict

The embedding net nodes within the given tf.GraphDef object

deepmd.utils.graph.get_embedding_net_variables(model_file: str, suffix: str = '')Dict[source]

Get the embedding net variables with the given frozen model(model_file)

Parameters
model_file

The input frozen model path

suffixstr, optional

The suffix of the scope

Returns
Dict

The embedding net variables within the given frozen model

deepmd.utils.graph.get_embedding_net_variables_from_graph_def(graph_def: tensorflow.core.framework.graph_pb2.GraphDef, suffix: str = '')Dict[source]

Get the embedding net variables with the given tf.GraphDef object

Parameters
graph_def

The input tf.GraphDef object

suffixstr, optional

The suffix of the scope

Returns
Dict

The embedding net variables within the given tf.GraphDef object

deepmd.utils.graph.get_fitting_net_nodes(model_file: str)Dict[source]

Get the fitting net nodes with the given frozen model(model_file)

Parameters
model_file

The input frozen model path

Returns
Dict

The fitting net nodes with the given frozen model

deepmd.utils.graph.get_fitting_net_nodes_from_graph_def(graph_def: tensorflow.core.framework.graph_pb2.GraphDef)Dict[source]

Get the fitting net nodes with the given tf.GraphDef object

Parameters
graph_def

The input tf.GraphDef object

Returns
Dict

The fitting net nodes within the given tf.GraphDef object

deepmd.utils.graph.get_fitting_net_variables(model_file: str)Dict[source]

Get the fitting net variables with the given frozen model(model_file)

Parameters
model_file

The input frozen model path

Returns
Dict

The fitting net variables within the given frozen model

deepmd.utils.graph.get_fitting_net_variables_from_graph_def(graph_def: tensorflow.core.framework.graph_pb2.GraphDef)Dict[source]

Get the fitting net variables with the given tf.GraphDef object

Parameters
graph_def

The input tf.GraphDef object

Returns
Dict

The fitting net variables within the given tf.GraphDef object

deepmd.utils.graph.get_tensor_by_name(model_file: str, tensor_name: str)tensorflow.python.framework.ops.Tensor[source]

Load tensor value from the frozen model(model_file)

Parameters
model_filestr

The input frozen model path

tensor_namestr

Indicates which tensor which will be loaded from the frozen model

Returns
tf.Tensor

The tensor which was loaded from the frozen model

Raises
GraphWithoutTensorError

Whether the tensor_name is within the frozen model

deepmd.utils.graph.get_tensor_by_name_from_graph(graph: tensorflow.python.framework.ops.Graph, tensor_name: str)tensorflow.python.framework.ops.Tensor[source]

Load tensor value from the given tf.Graph object

Parameters
graphtf.Graph

The input TensorFlow graph

tensor_namestr

Indicates which tensor which will be loaded from the frozen model

Returns
tf.Tensor

The tensor which was loaded from the frozen model

Raises
GraphWithoutTensorError

Whether the tensor_name is within the frozen model

deepmd.utils.graph.get_tensor_by_type(node, data_type: numpy.dtype)tensorflow.python.framework.ops.Tensor[source]

Get the tensor value within the given node according to the input data_type

Parameters
node

The given tensorflow graph node

data_type

The data type of the node

Returns
tf.Tensor

The tensor value of the given node

deepmd.utils.graph.load_graph_def(model_file: str)Tuple[tensorflow.python.framework.ops.Graph, tensorflow.core.framework.graph_pb2.GraphDef][source]

Load graph as well as the graph_def from the frozen model(model_file)

Parameters
model_filestr

The input frozen model path

Returns
tf.Graph

The graph loaded from the frozen model

tf.GraphDef

The graph_def loaded from the frozen model

deepmd.utils.learning_rate module

class deepmd.utils.learning_rate.LearningRateExp(start_lr: float, stop_lr: float = 5e-08, decay_steps: int = 5000, decay_rate: float = 0.95)[source]

Bases: object

The exponentially decaying learning rate.

The learning rate at step \(t\) is given by

\[\alpha(t) = \alpha_0 \lambda ^ { t / \tau }\]

where \(\alpha\) is the learning rate, \(\alpha_0\) is the starting learning rate, \(\lambda\) is the decay rate, and \(\tau\) is the decay steps.

Parameters
start_lr

Starting learning rate \(\alpha_0\)

stop_lr

Stop learning rate \(\alpha_1\)

decay_steps

Learning rate decay every this number of steps \(\tau\)

decay_rate

The decay rate \(\lambda\). If stop_step is provided in build, then it will be determined automatically and overwritten.

Methods

build(global_step[, stop_step])

Build the learning rate

start_lr()

Get the start lr

value(step)

Get the lr at a certain step

build(global_step: tensorflow.python.framework.ops.Tensor, stop_step: Optional[int] = None)tensorflow.python.framework.ops.Tensor[source]

Build the learning rate

Parameters
global_step

The tf Tensor prividing the global training step

stop_step

The stop step. If provided, the decay_rate will be determined automatically and overwritten.

Returns
learning_rate

The learning rate

start_lr()float[source]

Get the start lr

value(step: int)float[source]

Get the lr at a certain step

deepmd.utils.neighbor_stat module

class deepmd.utils.neighbor_stat.NeighborStat(ntypes: int, rcut: float)[source]

Bases: object

Class for getting training data information.

It loads data from DeepmdData object, and measures the data info, including neareest nbor distance between atoms, max nbor size of atoms and the output data range of the environment matrix.

Parameters
ntypes

The num of atom types

rcut

The cut-off radius

Methods

get_stat(data)

get the data statistics of the training data, including nearest nbor distance between atoms, max nbor size of atoms

get_stat(data: deepmd.utils.data_system.DeepmdDataSystem)Tuple[float, List[int]][source]

get the data statistics of the training data, including nearest nbor distance between atoms, max nbor size of atoms

Parameters
data

Class for manipulating many data systems. It is implemented with the help of DeepmdData.

Returns
min_nbor_dist

The nearest distance between neighbor atoms

max_nbor_size

A list with ntypes integers, denotes the actual achieved max sel

deepmd.utils.network module

deepmd.utils.network.embedding_net(xx, network_size, precision, activation_fn=<function tanh>, resnet_dt=False, name_suffix='', stddev=1.0, bavg=0.0, seed=None, trainable=True, uniform_seed=False, initial_variables=None)[source]

The embedding network.

The embedding network function \(\mathcal{N}\) is constructed by is the composition of multiple layers \(\mathcal{L}^{(i)}\):

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

A layer \(\mathcal{L}\) is given by one of the following forms, depending on the number of nodes: [1]

\[\begin{split}\mathbf{y}=\mathcal{L}(\mathbf{x};\mathbf{w},\mathbf{b})= \begin{cases} \boldsymbol{\phi}(\mathbf{x}^T\mathbf{w}+\mathbf{b}) + \mathbf{x}, & N_2=N_1 \\ \boldsymbol{\phi}(\mathbf{x}^T\mathbf{w}+\mathbf{b}) + (\mathbf{x}, \mathbf{x}), & N_2 = 2N_1\\ \boldsymbol{\phi}(\mathbf{x}^T\mathbf{w}+\mathbf{b}), & \text{otherwise} \\ \end{cases}\end{split}\]

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 is True. \(\boldsymbol{\phi}\) is the activation function.

Parameters
xxTensor

Input tensor \(\mathbf{x}\) of shape [-1,1]

network_size: list of int

Size of the embedding network. For example [16,32,64]

precision:

Precision of network weights. For example, tf.float64

activation_fn:

Activation function \(\boldsymbol{\phi}\)

resnet_dt: boolean

Using time-step in the ResNet construction

name_suffix: str

The name suffix append to each variable.

stddev: float

Standard deviation of initializing network parameters

bavg: float

Mean of network intial bias

seed: int

Random seed for initializing network parameters

trainable: boolean

If the network is trainable

uniform_seedbool

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

initial_variablesdict

The input dict which stores the embedding net variables

References

1

Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Identitymappings in deep residual networks. InComputer Vision – ECCV 2016,pages 630–645. Springer International Publishing, 2016.

deepmd.utils.network.embedding_net_rand_seed_shift(network_size)[source]
deepmd.utils.network.one_layer(inputs, outputs_size, activation_fn=<function tanh>, precision=tf.float64, stddev=1.0, bavg=0.0, name='linear', reuse=None, seed=None, use_timestep=False, trainable=True, useBN=False, uniform_seed=False, initial_variables=None)[source]
deepmd.utils.network.one_layer_rand_seed_shift()[source]
deepmd.utils.network.variable_summaries(var: tensorflow.python.ops.variables.VariableV1, name: str)[source]

Attach a lot of summaries to a Tensor (for TensorBoard visualization).

Parameters
vartf.Variable

[description]

namestr

variable name

deepmd.utils.pair_tab module

class deepmd.utils.pair_tab.PairTab(filename: str)[source]

Bases: object

Parameters
filename

File name for the short-range tabulated potential. The table is a text data file with (N_t + 1) * N_t / 2 + 1 columes. The first colume is the distance between atoms. The second to the last columes are energies for pairs of certain types. For example we have two atom types, 0 and 1. The columes from 2nd to 4th are for 0-0, 0-1 and 1-1 correspondingly.

Methods

get()

Get the serialized table.

reinit(filename)

Initialize the tabulated interaction

get()Tuple[numpy.array, numpy.array][source]

Get the serialized table.

reinit(filename: str)None[source]

Initialize the tabulated interaction

Parameters
filename

File name for the short-range tabulated potential. The table is a text data file with (N_t + 1) * N_t / 2 + 1 columes. The first colume is the distance between atoms. The second to the last columes are energies for pairs of certain types. For example we have two atom types, 0 and 1. The columes from 2nd to 4th are for 0-0, 0-1 and 1-1 correspondingly.

deepmd.utils.random module

deepmd.utils.random.choice(a: numpy.ndarray, p: Optional[numpy.ndarray] = None)[source]

Generates a random sample from a given 1-D array.

Parameters
anp.ndarray

A random sample is generated from its elements.

pnp.ndarray

The probabilities associated with each entry in a.

Returns
np.ndarray

arrays with results and their shapes

deepmd.utils.random.random(size=None)[source]

Return random floats in the half-open interval [0.0, 1.0).

Parameters
size

Output shape.

Returns
np.ndarray

Arrays with results and their shapes.

deepmd.utils.random.seed(val: Optional[int] = None)[source]

Seed the generator.

Parameters
valint

Seed.

deepmd.utils.random.shuffle(x: numpy.ndarray)[source]

Modify a sequence in-place by shuffling its contents.

Parameters
xnp.ndarray

The array or list to be shuffled.

deepmd.utils.sess module

deepmd.utils.sess.run_sess(sess: tensorflow.python.client.session.Session, *args, **kwargs)[source]

Run session with erorrs caught.

Parameters
sess: tf.Session

TensorFlow Session

Returns
the result of sess.run()

deepmd.utils.tabulate module

class deepmd.utils.tabulate.DPTabulate(model_file: str, type_one_side: bool = False, exclude_types: List[List[int]] = [], activation_fn: Callable[[tensorflow.python.framework.ops.Tensor], tensorflow.python.framework.ops.Tensor] = <function tanh>, suffix: str = '')[source]

Bases: object

Class for tabulation.

Compress a model, which including tabulating the embedding-net. The table is composed of fifth-order polynomial coefficients and is assembled from two sub-tables. The first table takes the stride(parameter) as it’s uniform stride, while the second table takes 10 * stride as its uniform stride The range of the first table is automatically detected by deepmd-kit, while the second table ranges from the first table’s upper boundary(upper) to the extrapolate(parameter) * upper.

Parameters
model_file

The frozen model

type_one_side

Try to build N_types tables. Otherwise, building N_types^2 tables

exclude_typesList[List[int]]

The excluded pairs of types which have no interaction with each other. For example, [[0, 1]] means no interaction between type 0 and type 1.

activation_function

The activation function in the embedding net. Supported options are {“tanh”,”gelu”} in common.ACTIVATION_FN_DICT.

suffixstr, optional

The suffix of the scope

Methods

build(min_nbor_dist, extrapolate, stride0, …)

Build the tables for model compression

build(min_nbor_dist: float, extrapolate: float, stride0: float, stride1: float)Tuple[int, int][source]

Build the tables for model compression

Parameters
min_nbor_dist

The nearest distance between neighbor atoms

extrapolate

The scale of model extrapolation

stride0

The uniform stride of the first table

stride1

The uniform stride of the second table

Returns
lower

The lower boundary of environment matrix

upper

The upper boundary of environment matrix

deepmd.utils.type_embed module

class deepmd.utils.type_embed.TypeEmbedNet[source]

Bases: object

Parameters
neuronlist[int]

Number of neurons in each hidden layers of the embedding net

resnet_dt

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

activation_function

The activation function in the embedding net. Supported options are {0}

precision

The precision of the embedding net parameters. Supported options are {1}

trainable

If the weights of embedding net are trainable.

seed

Random seed for initializing the network parameters.

uniform_seed

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

Methods

build(ntypes[, reuse, suffix])

Build the computational graph for the descriptor

build(ntypes: int, reuse=None, suffix='')[source]

Build the computational graph for the descriptor

Parameters
ntypes

Number of atom types.

reuse

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

suffix

Name suffix to identify this descriptor

Returns
embedded_types

The computational graph for embedded types

deepmd.utils.type_embed.embed_atom_type(ntypes: int, natoms: tensorflow.python.framework.ops.Tensor, type_embedding: tensorflow.python.framework.ops.Tensor)[source]

Make the embedded type for the atoms in system. The atoms are assumed to be sorted according to the type, thus their types are described by a tf.Tensor natoms, see explanation below.

Parameters
ntypes:

Number of types.

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

type_embedding:

The type embedding. It has the shape of [ntypes, embedding_dim]

Returns
atom_embedding

The embedded type of each atom. It has the shape of [numb_atoms, embedding_dim]

deepmd.utils.weight_avg module

deepmd.utils.weight_avg.weighted_average(errors: List[Dict[str, Tuple[float, float]]])Dict[source]

Compute wighted average of prediction errors for model.

Parameters
errorsList[Dict[str, Tuple[float, float]]]

List: the error of systems Dict: the error of quantities, name given by the key Tuple: (error, weight)

Returns
Dict

weighted averages