deepmd.pt.utils.stat
Module Contents
Functions
| Pack data for statistics. |
| |
| |
| Post process the statistics. |
| |
| Make preset out bias. |
| This function is used to fill atomic stat with global stat. |
| Compute the output statistics (e.g. energy bias) for the fitting net from packed data. |
| This function only handle stat computation from reduced global labels. |
|
Attributes
- 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_stat
Union
[np.ndarray
,None
] The atomic stat.
- global_stat
np.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.
- atomic_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:
- merged
Union
[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.
- ntypes
int
The number of atom types.
- stat_file_path
DPPath
,optional
The path to the stat file.
- rcond
float
,optional
The condition number for the regression of atomic energy.
- preset_bias
Dict
[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_forward
Callable
[…,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.
- merged
- 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.