Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect type hints and docstrings #1001

Merged
merged 2 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deepmd/cluster/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_gpus():
"""Get available IDs of GPU cards at local.
These IDs are valid when used as the TensorFlow device ID.

Returns:
Returns
-------
Optional[List[int]]
List of available GPU IDs. Otherwise, None.
Expand Down
6 changes: 4 additions & 2 deletions deepmd/descriptor/hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def get_nlist_i(self,
----------
ii : int
Get the neighbor information of the ii-th descriptor

Returns
-------
nlist
Expand Down Expand Up @@ -194,8 +195,9 @@ def prod_force_virial(self,
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
Return
------

Returns
-------
force
The force on atoms
virial
Expand Down
3 changes: 2 additions & 1 deletion deepmd/descriptor/loc_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ def prod_force_virial(self,
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
Return

Returns
------
force
The force on atoms
Expand Down
3 changes: 2 additions & 1 deletion deepmd/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ def prod_force_virial(self,
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
Return

Returns
------
force
The force on atoms
Expand Down
3 changes: 2 additions & 1 deletion deepmd/descriptor/se_a_ef.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ def prod_force_virial(self,
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
Return

Returns
------
force
The force on atoms
Expand Down
3 changes: 2 additions & 1 deletion deepmd/descriptor/se_r.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ def prod_force_virial(self,
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
Return

Returns
------
force
The force on atoms
Expand Down
3 changes: 2 additions & 1 deletion deepmd/descriptor/se_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ def prod_force_virial(self,
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
Return

Returns
------
force
The force on atoms
Expand Down
4 changes: 2 additions & 2 deletions deepmd/fit/dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def build (self,
suffix
Name suffix to identify this descriptor

Return
------
Returns
-------
dipole
The atomic dipole.
"""
Expand Down
7 changes: 4 additions & 3 deletions deepmd/fit/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def compute_input_stats(self,
"""
Compute the input statistics

Parameters:
Parameters
----------
all_stat
if numb_fparam > 0 must have all_stat['fparam']
if numb_aparam > 0 must have all_stat['aparam']
Expand Down Expand Up @@ -315,8 +316,8 @@ def build (self,
suffix
Name suffix to identify this descriptor

Return
------
Returns
-------
ener
The system energy
"""
Expand Down
11 changes: 6 additions & 5 deletions deepmd/fit/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def compute_input_stats(self,
"""
Compute the input statistics

Parameters:
Parameters
----------
all_stat
Dictionary of inputs.
can be prepared by model.make_stat_input
Expand Down Expand Up @@ -292,8 +293,8 @@ def build (self,
suffix
Name suffix to identify this descriptor

Return
------
Returns
-------
atomic_polar
The atomic polarizability
"""
Expand Down Expand Up @@ -464,8 +465,8 @@ def build (self,
suffix
Name suffix to identify this descriptor

Return
------
Returns
-------
polar
The system polarizability
"""
Expand Down
8 changes: 4 additions & 4 deletions deepmd/infer/data_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ def _slice_descrpt_deriv(self, deriv):


def eval(self,
coord : np.array,
box : np.array,
atype : np.array,
coord : np.ndarray,
box : np.ndarray,
atype : np.ndarray,
eval_fv : bool = True
) -> Tuple[np.array, np.array, np.array]:
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Evaluate the modification

Expand Down
10 changes: 7 additions & 3 deletions deepmd/infer/deep_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def model_type(self) -> str:
def model_version(self) -> str:
"""Get type of model.

:type:str
Returns
-------
str
type of model
"""
if not self._model_version:
try:
Expand All @@ -71,7 +74,8 @@ def _graph_compatable(
) -> bool :
""" Check the model compatability

Return
Returns
-------
bool
If the model stored in the graph file is compatable with the current code
"""
Expand Down Expand Up @@ -146,7 +150,7 @@ def _load_graph(

@staticmethod
def sort_input(
coord : np.array, atom_type : np.array, sel_atoms : List[int] = None
coord : np.ndarray, atom_type : np.ndarray, sel_atoms : List[int] = None
):
"""
Sort atoms in the system according their types.
Expand Down
12 changes: 6 additions & 6 deletions deepmd/infer/deep_polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ def __init__(

def eval(
self,
coords: np.array,
cells: np.array,
coords: np.ndarray,
cells: np.ndarray,
atom_types: List[int],
atomic: bool = False,
fparam: Optional[np.array] = None,
aparam: Optional[np.array] = None,
efield: Optional[np.array] = None,
) -> np.array:
fparam: Optional[np.ndarray] = None,
aparam: Optional[np.ndarray] = None,
efield: Optional[np.ndarray] = None,
) -> np.ndarray:
"""Evaluate the model.

Parameters
Expand Down
10 changes: 5 additions & 5 deletions deepmd/infer/deep_pot.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ def get_dim_aparam(self) -> int:

def eval(
self,
coords: np.array,
cells: np.array,
coords: np.ndarray,
cells: np.ndarray,
atom_types: List[int],
atomic: bool = False,
fparam: Optional[np.array] = None,
aparam: Optional[np.array] = None,
efield: Optional[np.array] = None
fparam: Optional[np.ndarray] = None,
aparam: Optional[np.ndarray] = None,
efield: Optional[np.ndarray] = None
) -> Tuple[np.ndarray, ...]:
"""Evaluate the energy, force and virial by using this DP.

Expand Down
16 changes: 8 additions & 8 deletions deepmd/infer/deep_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ def get_dim_aparam(self) -> int:

def eval(
self,
coords: np.array,
cells: np.array,
coords: np.ndarray,
cells: np.ndarray,
atom_types: List[int],
atomic: bool = True,
fparam: Optional[np.array] = None,
aparam: Optional[np.array] = None,
efield: Optional[np.array] = None
) -> np.array:
fparam: Optional[np.ndarray] = None,
aparam: Optional[np.ndarray] = None,
efield: Optional[np.ndarray] = None
) -> np.ndarray:
"""Evaluate the model.

Parameters
Expand Down Expand Up @@ -211,8 +211,8 @@ def eval(

def eval_full(
self,
coords: np.array,
cells: np.array,
coords: np.ndarray,
cells: np.ndarray,
atom_types: List[int],
atomic: bool = False,
fparam: Optional[np.array] = None,
Expand Down
8 changes: 4 additions & 4 deletions deepmd/infer/ewald_recp.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def __init__(self,
self.sess = tf.Session(graph=graph, config=default_tf_session_config)

def eval(self,
coord : np.array,
charge : np.array,
box : np.array
) -> Tuple[np.array, np.array, np.array] :
coord : np.ndarray,
charge : np.ndarray,
box : np.ndarray
) -> Tuple[np.ndarray, np.ndarray, np.ndarray] :
"""
Evaluate

Expand Down
35 changes: 24 additions & 11 deletions deepmd/infer/model_devi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,53 @@
from ..utils.data import DeepmdData


def calc_model_devi_f(fs):
def calc_model_devi_f(fs: np.ndarray):
'''
fs : numpy.ndarray, size of `n_models x n_frames x n_atoms x 3`
Parameters
----------
fs : numpy.ndarray
size of `n_models x n_frames x n_atoms x 3`
'''
fs_devi = np.linalg.norm(np.std(fs, axis=0), axis=-1)
max_devi_f = np.max(fs_devi, axis=-1)
min_devi_f = np.min(fs_devi, axis=-1)
avg_devi_f = np.mean(fs_devi, axis=-1)
return max_devi_f, min_devi_f, avg_devi_f

def calc_model_devi_e(es):
def calc_model_devi_e(es: np.ndarray):
'''
es : numpy.ndarray, size of `n_models x n_frames x n_atoms
Parameters
----------
es : numpy.ndarray
size of `n_models x n_frames x n_atoms
'''
es_devi = np.std(es, axis=0)
max_devi_e = np.max(es_devi, axis=1)
min_devi_e = np.min(es_devi, axis=1)
avg_devi_e = np.mean(es_devi, axis=1)
return max_devi_e, min_devi_e, avg_devi_e

def calc_model_devi_v(vs):
def calc_model_devi_v(vs: np.ndarray):
'''
vs : numpy.ndarray, size of `n_models x n_frames x 9`
Parameters
----------
vs : numpy.ndarray
size of `n_models x n_frames x 9`
'''
vs_devi = np.std(vs, axis=0)
max_devi_v = np.max(vs_devi, axis=-1)
min_devi_v = np.min(vs_devi, axis=-1)
avg_devi_v = np.linalg.norm(vs_devi, axis=-1) / 3
return max_devi_v, min_devi_v, avg_devi_v

def write_model_devi_out(devi, fname):
def write_model_devi_out(devi: np.ndarray, fname: str):
'''
devi : numpy.ndarray, the first column is the steps index
fname : str, the file name to dump
Parameters
----------
devi : numpy.ndarray
the first column is the steps index
fname : str
the file name to dump
'''
assert devi.shape[1] == 7
header = "%10s" % "step"
Expand Down Expand Up @@ -75,7 +88,7 @@ def calc_model_devi(coord,
'''
Python interface to calculate model deviation

Parameters:
Parameters
-----------
coord : numpy.ndarray, `n_frames x n_atoms x 3`
Coordinates of system to calculate
Expand All @@ -92,7 +105,7 @@ def calc_model_devi(coord,
nopbc : bool
Whether to use pbc conditions

Return:
Returns
-------
model_devi : numpy.ndarray, `n_frames x 7`
Model deviation results. The first column is index of steps, the other 6 columns are
Expand Down
Loading