Skip to content
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
4 changes: 2 additions & 2 deletions deepmd/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def add_data_requirement(
atomic: bool = False,
must: bool = False,
high_prec: bool = False,
type_sel: bool = None,
type_sel: Optional[bool] = None,
repeat: int = 1,
default: float = 0.,
):
Expand Down Expand Up @@ -237,7 +237,7 @@ def add(
key: str,
types_: Union[type, List[type]],
alias: Optional[Union[str, List[str]]] = None,
default: Any = None,
default: Optional[Any] = None,
must: bool = False,
) -> "ClassArg":
"""Add key to be parsed.
Expand Down
6 changes: 3 additions & 3 deletions deepmd/descriptor/descriptor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Tuple
from typing import Optional, Any, Dict, List, Tuple

import numpy as np
from deepmd.env import tf
Expand Down Expand Up @@ -185,7 +185,7 @@ def build(self,
box_: tf.Tensor,
mesh: tf.Tensor,
input_dict: Dict[str, Any],
reuse: bool = None,
reuse: Optional[bool] = None,
suffix: str = '',
) -> tf.Tensor:
"""
Expand Down Expand Up @@ -262,7 +262,7 @@ def enable_compression(self,
raise NotImplementedError(
"Descriptor %s doesn't support compression!" % type(self).__name__)

def enable_mixed_precision(self, mixed_prec: dict = None) -> None:
def enable_mixed_precision(self, mixed_prec: Optional[dict] = None) -> None:
"""
Reveive the mixed precision setting.

Expand Down
4 changes: 2 additions & 2 deletions deepmd/descriptor/se_a.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math
import numpy as np
from typing import Tuple, List, Dict, Any
from typing import Optional, Tuple, List, Dict, Any

from deepmd.env import tf
from deepmd.common import get_activation_func, get_precision, cast_precision
Expand Down Expand Up @@ -113,7 +113,7 @@ def __init__ (self,
axis_neuron: int = 8,
resnet_dt: bool = False,
trainable: bool = True,
seed: int = None,
seed: Optional[int] = None,
type_one_side: bool = True,
exclude_types: List[List[int]] = [],
set_davg_zero: bool = False,
Expand Down
4 changes: 2 additions & 2 deletions deepmd/descriptor/se_a_ebd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from typing import Tuple, List
from typing import Optional, Tuple, List

from deepmd.env import tf
from deepmd.common import ClassArg, get_activation_func, get_precision, add_data_requirement
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__ (self,
axis_neuron: int = 8,
resnet_dt: bool = False,
trainable: bool = True,
seed: int = None,
seed: Optional[int] = None,
type_one_side: bool = True,
type_nchanl : int = 2,
type_nlayer : int = 1,
Expand Down
6 changes: 3 additions & 3 deletions deepmd/descriptor/se_a_ef.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from typing import Tuple, List
from typing import Optional, Tuple, List

from deepmd.env import tf
from deepmd.common import add_data_requirement
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self,
axis_neuron: int = 8,
resnet_dt: bool = False,
trainable: bool = True,
seed: int = None,
seed: Optional[int] = None,
type_one_side: bool = True,
exclude_types: List[List[int]] = [],
set_davg_zero: bool = False,
Expand Down Expand Up @@ -284,7 +284,7 @@ def __init__ (self,
axis_neuron: int = 8,
resnet_dt: bool = False,
trainable: bool = True,
seed: int = None,
seed: Optional[int] = None,
type_one_side: bool = True,
exclude_types: List[List[int]] = [],
set_davg_zero: bool = False,
Expand Down
8 changes: 4 additions & 4 deletions deepmd/descriptor/se_atten.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math
import numpy as np
from typing import Tuple, List, Dict, Any
from typing import Optional, Tuple, List, Dict, Any
from packaging.version import Version

from deepmd.env import tf
Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(self,
axis_neuron: int = 8,
resnet_dt: bool = False,
trainable: bool = True,
seed: int = None,
seed: Optional[int] = None,
type_one_side: bool = True,
exclude_types: List[List[int]] = [],
set_davg_zero: bool = False,
Expand Down Expand Up @@ -157,7 +157,7 @@ def compute_input_stats(self,
mesh: list,
input_dict: dict,
mixed_type: bool = False,
real_natoms_vec: list = None
real_natoms_vec: Optional[list] = None
) -> None:
"""
Compute the statisitcs (avg and std) of the training data. The input will be normalized by the statistics.
Expand Down Expand Up @@ -227,7 +227,7 @@ def build(self,
box_: tf.Tensor,
mesh: tf.Tensor,
input_dict: dict,
reuse: bool = None,
reuse: Optional[bool] = None,
suffix: str = ''
) -> tf.Tensor:
"""
Expand Down
4 changes: 2 additions & 2 deletions deepmd/descriptor/se_r.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from typing import Tuple, List
from typing import Optional, Tuple, List

from deepmd.env import tf
from deepmd.common import get_activation_func, get_precision, cast_precision
Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__ (self,
neuron: List[int] = [24,48,96],
resnet_dt: bool = False,
trainable: bool = True,
seed: int = None,
seed: Optional[int] = None,
type_one_side: bool = True,
exclude_types: List[List[int]] = [],
set_davg_zero: bool = False,
Expand Down
4 changes: 2 additions & 2 deletions deepmd/descriptor/se_t.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from typing import Tuple, List
from typing import Optional, Tuple, List

from deepmd.env import tf
from deepmd.common import get_activation_func, get_precision, cast_precision
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__ (self,
neuron: List[int] = [24,48,96],
resnet_dt: bool = False,
trainable: bool = True,
seed: int = None,
seed: Optional[int] = None,
set_davg_zero: bool = False,
activation_function: str = 'tanh',
precision: str = 'default',
Expand Down
4 changes: 2 additions & 2 deletions deepmd/fit/dipole.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warnings
import numpy as np
from typing import Tuple, List
from typing import Optional, Tuple, List

from deepmd.env import tf
from deepmd.common import add_data_requirement, get_activation_func, get_precision, cast_precision
Expand Down Expand Up @@ -139,7 +139,7 @@ def build (self,
input_d : tf.Tensor,
rot_mat : tf.Tensor,
natoms : tf.Tensor,
input_dict: dict = None,
input_dict: Optional[dict] = None,
reuse : bool = None,
suffix : str = '') -> tf.Tensor:
"""
Expand Down
4 changes: 2 additions & 2 deletions deepmd/fit/ener.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import warnings
import numpy as np
from typing import Tuple, List
from typing import Optional, Tuple, List
from packaging.version import Version

from deepmd.env import tf
Expand Down Expand Up @@ -686,7 +686,7 @@ def enable_compression(self,
self.aparam_inv_std = get_tensor_by_name_from_graph(graph, 'fitting_attr%s/t_aparam_istd' % suffix)


def enable_mixed_precision(self, mixed_prec: dict = None) -> None:
def enable_mixed_precision(self, mixed_prec: Optional[dict] = None) -> None:
"""
Reveive the mixed precision setting.

Expand Down
6 changes: 3 additions & 3 deletions deepmd/fit/polar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warnings
import numpy as np
from typing import Tuple, List
from typing import Optional, Tuple, List

from deepmd.env import tf
from deepmd.common import add_data_requirement, cast_precision, get_activation_func, get_precision
Expand Down Expand Up @@ -349,7 +349,7 @@ def build (self,
input_d : tf.Tensor,
rot_mat : tf.Tensor,
natoms : tf.Tensor,
input_dict: dict = None,
input_dict: Optional[dict] = None,
reuse : bool = None,
suffix : str = '') :
"""
Expand Down Expand Up @@ -558,7 +558,7 @@ def build (self,
input_d,
rot_mat,
natoms,
input_dict: dict = None,
input_dict: Optional[dict] = None,
reuse = None,
suffix = '') -> tf.Tensor:
"""
Expand Down
12 changes: 6 additions & 6 deletions deepmd/model/multi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from typing import Tuple, List
from typing import Optional, Tuple, List

from deepmd.env import tf
from deepmd.utils.pair_tab import PairTab
Expand Down Expand Up @@ -47,13 +47,13 @@ def __init__(
fitting_dict,
fitting_type_dict,
typeebd=None,
type_map: List[str] = None,
type_map: Optional[List[str]] = None,
data_stat_nbatch: int = 10,
data_stat_protect: float = 1e-2,
use_srtab: str = None, # all the ener fitting will do this
smin_alpha: float = None,
sw_rmin: float = None,
sw_rmax: float = None
use_srtab: Optional[str] = None, # all the ener fitting will do this
smin_alpha: Optional[float] = None,
sw_rmin: Optional[float] = None,
sw_rmax: Optional[float] = None
) -> None:
"""
Constructor
Expand Down
4 changes: 2 additions & 2 deletions deepmd/utils/parallel_op.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Generator, Tuple, Dict, Any
from typing import Optional, Callable, Generator, Tuple, Dict, Any

from deepmd.env import tf
from deepmd.utils.sess import run_sess
Expand Down Expand Up @@ -32,7 +32,7 @@ class ParallelOp:
>>> print(*p.generate(tf.Session(), feed()))
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
"""
def __init__(self, builder: Callable[..., Tuple[Dict[str, tf.Tensor], Tuple[tf.Tensor]]], nthreads: int = None, config: tf.ConfigProto = None) -> None:
def __init__(self, builder: Callable[..., Tuple[Dict[str, tf.Tensor], Tuple[tf.Tensor]]], nthreads: Optional[int] = None, config: Optional[tf.ConfigProto] = None) -> None:
if nthreads is not None:
self.nthreads = nthreads
elif config is not None:
Expand Down
4 changes: 2 additions & 2 deletions deepmd/utils/path.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from abc import ABC, abstractmethod
from typing import List
from typing import Optional, List
from pathlib import Path
from functools import lru_cache

Expand Down Expand Up @@ -246,7 +246,7 @@ def load_numpy(self) -> np.ndarray:
"""
return self.root[self.name][:]

def load_txt(self, dtype: np.dtype = None, **kwargs) -> np.ndarray:
def load_txt(self, dtype: Optional[np.dtype] = None, **kwargs) -> np.ndarray:
"""Load NumPy array from text.

Returns
Expand Down
6 changes: 4 additions & 2 deletions deepmd/utils/random.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Optional

import numpy as np


_RANDOM_GENERATOR = np.random.RandomState()


def choice(a: np.ndarray, p: np.ndarray = None):
def choice(a: np.ndarray, p: Optional[np.ndarray] = None):
"""Generates a random sample from a given 1-D array.

Parameters
Expand Down Expand Up @@ -38,7 +40,7 @@ def random(size=None):
return _RANDOM_GENERATOR.random_sample(size)


def seed(val: int = None):
def seed(val: Optional[int] = None):
"""Seed the generator.

Parameters
Expand Down
4 changes: 2 additions & 2 deletions deepmd/utils/type_embed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from typing import Tuple, List, Union
from typing import Optional, Tuple, List, Union

from deepmd.env import tf
from deepmd.utils.network import one_layer
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(
activation_function: Union[str, None] = 'tanh',
precision: str = 'default',
trainable: bool = True,
seed: int = None,
seed: Optional[int] = None,
uniform_seed: bool = False,
padding: bool = False,
)->None:
Expand Down