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

Perf: remove redundant checks on data integrity #4433

Merged
merged 8 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
21 changes: 1 addition & 20 deletions deepmd/utils/data_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
from deepmd.utils.out_stat import (
compute_stats_from_redu,
)
from deepmd.utils.path import (
DPPath,
)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -103,6 +100,7 @@ def __init__(
del rcut
self.system_dirs = systems
self.nsystems = len(self.system_dirs)
assert self.nsystems > 0, "No systems provided"
caic99 marked this conversation as resolved.
Show resolved Hide resolved
caic99 marked this conversation as resolved.
Show resolved Hide resolved
self.data_systems = []
for ii in self.system_dirs:
self.data_systems.append(
Expand Down Expand Up @@ -755,23 +753,6 @@ def process_systems(systems: Union[str, list[str]]) -> list[str]:
systems = expand_sys_str(systems)
elif isinstance(systems, list):
systems = systems.copy()
help_msg = "Please check your setting for data systems"
# check length of systems
if len(systems) == 0:
msg = "cannot find valid a data system"
log.fatal(msg)
raise OSError(msg, help_msg)
# roughly check all items in systems are valid
for ii in systems:
ii = DPPath(ii)
if not ii.is_dir():
msg = f"dir {ii} is not a valid dir"
log.fatal(msg)
raise OSError(msg, help_msg)
if not (ii / "type.raw").is_file():
msg = f"dir {ii} is not a valid data system dir"
log.fatal(msg)
raise OSError(msg, help_msg)
return systems
caic99 marked this conversation as resolved.
Show resolved Hide resolved


Expand Down
14 changes: 8 additions & 6 deletions deepmd/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import (
ClassVar,
Optional,
Union,
)

import h5py
Expand Down Expand Up @@ -151,25 +152,24 @@
If true, no error will be raised if the target directory already exists.
"""


Check warning

Code scanning / CodeQL

`__eq__` not overridden when adding attributes Warning

The class 'DPOSPath' does not override
'__eq__'
, but adds the new attribute
mode
.
The class 'DPOSPath' does not override
'__eq__'
, but adds the new attribute
path
.
class DPOSPath(DPPath):
"""The OS path class to data system (DeepmdData) for real directories.

Parameters
----------
path : str
path : Union[str, Path]
path
mode : str, optional
mode, by default "r"
"""

def __init__(self, path: str, mode: str = "r") -> None:
def __init__(self, path: Union[str, Path], mode: str = "r") -> None:
super().__init__()
self.mode = mode
if isinstance(path, Path):
self.path = path
else:
self.path = Path(path)
self.path = Path(path)
if not self.path.exists():
raise FileNotFoundError(f"{self.path} not found")

def load_numpy(self) -> np.ndarray:
"""Load NumPy array.
Expand Down Expand Up @@ -300,6 +300,8 @@
# so we do not support file names containing #...
s = path.split("#")
self.root_path = s[0]
if not os.path.isfile(self.root_path):
raise FileNotFoundError(f"{self.root_path} not found")
self.root = self._load_h5py(s[0], mode)
# h5 path: default is the root path
self._name = s[1] if len(s) > 1 else "/"
Expand Down
Loading