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 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: 2 additions & 0 deletions deepmd/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
) -> None:
"""Constructor."""
root = DPPath(sys_path)
if not root.is_dir():
raise FileNotFoundError(f"System {sys_path} is not found!")

Check warning on line 64 in deepmd/utils/data.py

View check run for this annotation

Codecov / codecov/patch

deepmd/utils/data.py#L64

Added line #L64 was not covered by tests
self.dirs = root.glob(set_prefix + ".*")
if not len(self.dirs):
raise FileNotFoundError(f"No {set_prefix}.* is found in {sys_path}")
Expand Down
22 changes: 2 additions & 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,8 @@
del rcut
self.system_dirs = systems
self.nsystems = len(self.system_dirs)
if self.nsystems <= 0:
raise ValueError("No systems provided")

Check warning on line 104 in deepmd/utils/data_system.py

View check run for this annotation

Codecov / codecov/patch

deepmd/utils/data_system.py#L104

Added line #L104 was not covered by tests
self.data_systems = []
for ii in self.system_dirs:
self.data_systems.append(
Expand Down Expand Up @@ -755,23 +754,6 @@
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
12 changes: 6 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,22 @@
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
.
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)

def load_numpy(self) -> np.ndarray:
"""Load NumPy array.
Expand Down Expand Up @@ -300,6 +298,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")

Check warning on line 302 in deepmd/utils/path.py

View check run for this annotation

Codecov / codecov/patch

deepmd/utils/path.py#L302

Added line #L302 was not covered by tests
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