Skip to content

Commit

Permalink
add error message
Browse files Browse the repository at this point in the history
  • Loading branch information
caic99 committed Nov 29, 2024
1 parent 0e1944a commit b093fd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 2 additions & 6 deletions deepmd/utils/data_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(
del rcut
self.system_dirs = systems
self.nsystems = len(self.system_dirs)
assert self.nsystems > 0, "No systems provided"
self.data_systems = []
for ii in self.system_dirs:
self.data_systems.append(
Expand Down Expand Up @@ -752,12 +753,7 @@ 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 any valid data systems"
log.fatal(msg)
raise OSError(msg, help_msg)
assert systems, "No systems provided"
return systems


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 @@ -157,19 +158,18 @@ class DPOSPath(DPPath):
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 @@ def __init__(self, path: str, mode: str = "r") -> None:
# 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

0 comments on commit b093fd7

Please sign in to comment.