deepmd.pt.utils.stat

Module Contents

Functions

make_stat_input(datasets, dataloaders, nbatches)

Pack data for statistics.

_restore_from_file(→ Optional[dict])

_save_to_file(stat_file_path, bias_out, std_out)

_post_process_stat(out_bias, out_std)

Post process the statistics.

_compute_model_predict(sampled, keys, model_forward)

_make_preset_out_bias(→ Optional[numpy.array])

Make preset out bias.

_fill_stat_with_global(atomic_stat, global_stat)

This function is used to fill atomic stat with global stat.

compute_output_stats(merged, ntypes[, keys, ...])

Compute the output statistics (e.g. energy bias) for the fitting net from packed data.

compute_output_stats_global(sampled, ntypes, keys[, ...])

This function only handle stat computation from reduced global labels.

compute_output_stats_atomic(sampled, ntypes, keys[, ...])

Attributes

log

deepmd.pt.utils.stat.log[source]
deepmd.pt.utils.stat.make_stat_input(datasets, dataloaders, nbatches)[source]

Pack data for statistics.

Args: - dataset: A list of dataset to analyze. - nbatches: Batch count for collecting stats.

Returns:
  • a list of dicts, each of which contains data from a system
deepmd.pt.utils.stat._restore_from_file(stat_file_path: deepmd.utils.path.DPPath, keys: List[str] = ['energy']) dict | None[source]
deepmd.pt.utils.stat._save_to_file(stat_file_path: deepmd.utils.path.DPPath, bias_out: dict, std_out: dict)[source]
deepmd.pt.utils.stat._post_process_stat(out_bias, out_std)[source]

Post process the statistics.

For global statistics, we do not have the std for each type of atoms, thus fake the output std by ones for all the types.

deepmd.pt.utils.stat._compute_model_predict(sampled: Callable[[], List[dict]] | List[dict], keys: List[str], model_forward: Callable[Ellipsis, torch.Tensor])[source]
deepmd.pt.utils.stat._make_preset_out_bias(ntypes: int, ibias: List[numpy.array | None]) numpy.array | None[source]

Make preset out bias.

output:

a np array of shape [ntypes, *(odim0, odim1, …)] is any item is not None None if all items are None.

deepmd.pt.utils.stat._fill_stat_with_global(atomic_stat: numpy.ndarray | None, global_stat: numpy.ndarray)[source]

This function is used to fill atomic stat with global stat.

Parameters:
atomic_statUnion[np.ndarray, None]

The atomic stat.

global_statnp.ndarray

The global stat.

if the atomic stat is None, use global stat.
if the atomic stat is not None, but has nan values (missing atypes), fill with global stat.
deepmd.pt.utils.stat.compute_output_stats(merged: Callable[[], List[dict]] | List[dict], ntypes: int, keys: str | List[str] = ['energy'], stat_file_path: deepmd.utils.path.DPPath | None = None, rcond: float | None = None, preset_bias: Dict[str, List[torch.Tensor | None]] | None = None, model_forward: Callable[Ellipsis, torch.Tensor] | None = None)[source]

Compute the output statistics (e.g. energy bias) for the fitting net from packed data.

Parameters:
mergedUnion[Callable[[], List[dict]], List[dict]]
  • List[dict]: A list of data samples from various data systems.

    Each element, merged[i], is a data dictionary containing keys: torch.Tensor originating from the i-th data system.

  • Callable[[], List[dict]]: A lazy function that returns data samples in the above format

    only when needed. Since the sampling process can be slow and memory-intensive, the lazy function helps by only sampling once.

ntypesint

The number of atom types.

stat_file_pathDPPath, optional

The path to the stat file.

rcondfloat, optional

The condition number for the regression of atomic energy.

preset_biasDict[str, List[Optional[torch.Tensor]]], optional

Specifying atomic energy contribution in vacuum. Given by key:value pairs. The value is a list specifying the bias. the elements can be None or np.array of output shape. For example: [None, [2.]] means type 0 is not set, type 1 is set to [2.] The set_davg_zero key in the descrptor should be set.

model_forwardCallable[…, torch.Tensor], optional

The wrapped forward function of atomic model. If not None, the model will be utilized to generate the original energy prediction, which will be subtracted from the energy label of the data. The difference will then be used to calculate the delta complement energy bias for each type.

deepmd.pt.utils.stat.compute_output_stats_global(sampled: List[dict], ntypes: int, keys: List[str], rcond: float | None = None, preset_bias: Dict[str, List[torch.Tensor | None]] | None = None, model_pred: Dict[str, numpy.ndarray] | None = None)[source]

This function only handle stat computation from reduced global labels.

deepmd.pt.utils.stat.compute_output_stats_atomic(sampled: List[dict], ntypes: int, keys: List[str], model_pred: Dict[str, numpy.ndarray] | None = None)[source]