-
Notifications
You must be signed in to change notification settings - Fork 136
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
add decrecaption warning when dpdata throws errors while parsing cp2k #558
Conversation
for more information, see https://pre-commit.ci
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## devel #558 +/- ##
==========================================
- Coverage 82.90% 82.85% -0.06%
==========================================
Files 73 73
Lines 6541 6556 +15
==========================================
+ Hits 5423 5432 +9
- Misses 1118 1124 +6
☔ View full report in Codecov by Sentry. |
#556 didn't throw any errors though |
I don't know how he wrote the code for dpdata, however, I got errors when I use his files. import dpdata
dpdata.LabeledSystem(file_name="./55-20rfj2", fmt="cp2k/aimd_output") {
"name": "PendingDeprecationWarning",
"message": "
Hi, you got an error from dpdata,
please check if your cp2k files include full information,
otherwise its version is not supported by dpdata.
Try use dpdata plugin from cp2kdata package,
for details, please refer to
https://robinzyb.github.io/cp2kdata/
",
"stack": "---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
File ~/anaconda3/envs/ectoolkit/lib/python3.8/site-packages/dpdata/plugins/cp2k.py:22, in CP2KAIMDOutputFormat.from_labeled_system(self, file_name, restart, **kwargs)
21 xyz_file = sorted(glob.glob(f\"{file_name}/*pos*.xyz\"))[0]
---> 22 log_file = sorted(glob.glob(f\"{file_name}/*.log\"))[0]
23 print(tuple(Cp2kSystems(log_file, xyz_file, restart)))
IndexError: list index out of range
During handling of the above exception, another exception occurred:
PendingDeprecationWarning Traceback (most recent call last)
/Users/robinzhuang/workdir/tmp/cp2kdata_testspace/Untitled-1.ipynb Cell 2 line 2
<a href='vscode-notebook-cell:/Users/robinzhuang/workdir/tmp/cp2kdata_testspace/Untitled-1.ipynb#W1sZmlsZQ%3D%3D?line=0'>1</a> import dpdata
----> <a href='vscode-notebook-cell:/Users/robinzhuang/workdir/tmp/cp2kdata_testspace/Untitled-1.ipynb#W1sZmlsZQ%3D%3D?line=1'>2</a> dpdata.LabeledSystem(file_name=\"./55-20rfj2\", fmt=\"cp2k/aimd_output\")
File ~/anaconda3/envs/ectoolkit/lib/python3.8/site-packages/dpdata/system.py:281, in System.__init__(self, file_name, fmt, type_map, begin, step, data, convergence_check, **kwargs)
279 if file_name is None:
280 return
--> 281 self.from_fmt(
282 file_name,
283 fmt,
284 type_map=type_map,
285 begin=begin,
286 step=step,
287 convergence_check=convergence_check,
288 **kwargs,
289 )
291 if type_map is not None:
292 self.apply_type_map(type_map)
File ~/anaconda3/envs/ectoolkit/lib/python3.8/site-packages/dpdata/system.py:318, in System.from_fmt(self, file_name, fmt, **kwargs)
316 if fmt == \"auto\":
317 fmt = os.path.basename(file_name).split(\".\")[-1].lower()
--> 318 return self.from_fmt_obj(load_format(fmt), file_name, **kwargs)
File ~/anaconda3/envs/ectoolkit/lib/python3.8/site-packages/dpdata/system.py:1162, in LabeledSystem.from_fmt_obj(self, fmtobj, file_name, **kwargs)
1161 def from_fmt_obj(self, fmtobj, file_name, **kwargs):
-> 1162 data = fmtobj.from_labeled_system(file_name, **kwargs)
1163 if data:
1164 if isinstance(data, (list, tuple)):
File ~/anaconda3/envs/ectoolkit/lib/python3.8/site-packages/dpdata/plugins/cp2k.py:27, in CP2KAIMDOutputFormat.from_labeled_system(self, file_name, restart, **kwargs)
25 return tuple(Cp2kSystems(log_file, xyz_file, restart))
26 except :
---> 27 raise PendingDeprecationWarning(string_warning)
PendingDeprecationWarning:
Hi, you got an error from dpdata,
please check if your cp2k files include full information,
otherwise its version is not supported by dpdata.
Try use dpdata plugin from cp2kdata package,
for details, please refer to
https://robinzyb.github.io/cp2kdata/
"
} |
Firstly, move mv 1.out 1.log Then there are no errors anymore. Catching an exception will not work. >>> import dpdata
>>> dpdata.LabeledSystem(file_name="./", fmt="cp2k/aimd_output")
Data Summary
Labeled System
-------------------
Frame Numbers : 0
Atom Numbers : 0
Including Virials : No
Element List :
------------------- |
for more information, see https://pre-commit.ci
The old code returns empty dict even if nothing is matched. Extra lines are added to raise StopIteration when all matches is failed. |
dpdata/plugins/cp2k.py
Outdated
# TODO: when pattern match is failed | ||
# TODO: For now just use RuntimeError as a placeholder. | ||
except RuntimeError: | ||
print(string_warning) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ignores the error and does not exit the program. Is it expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be two codes acceptable:
except RuntimeError from e:
raise PendingDeprecationWarning(string_warning) from e
or
except RuntimeError from e:
warnings.warn(string_warning)
raise e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not exactly. I was trying to find a decent way that raises errors without showing too much trace back. In that case, users are often distracted by the trace back. But except: print
won't stop the code which would cause worse consequences. I will added them back.
dpdata/plugins/cp2k.py
Outdated
xyz_file = sorted(glob.glob(f"{file_name}/*pos*.xyz"))[0] | ||
log_file = sorted(glob.glob(f"{file_name}/*.log"))[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines do not need to be inside the try...except
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just a grammar issue.
Hi, you got an error from dpdata, | ||
please check if your cp2k files include full information, | ||
otherwise its version is not supported by dpdata. | ||
Try use dpdata plugin from cp2kdata package, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try use dpdata plugin from cp2kdata package, | |
Try to use dpdata plugin from cp2kdata package, |
@robinzyb, we only use Squash merge. |
…deepmodeling#558) Squashed commit of the following: commit dfb6191 Merge: 1b55e6c 5028af6 Author: Yongbin Zhuang <[email protected]> Date: Mon Oct 30 22:02:15 2023 +0100 add decrecaption warning when dpdata throws errors while parsing cp2k (deepmodeling#558) commit 5028af6 Author: robinzyb <[email protected]> Date: Mon Oct 30 21:28:21 2023 +0100 raise PendingDeprecationWarning commit 3ee373d Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon Oct 30 19:51:57 2023 +0000 [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci commit cec3fc2 Author: robinzyb <[email protected]> Date: Mon Oct 30 20:51:26 2023 +0100 add exact except for the cp2k plugin. commit 7a09854 Author: robinzyb <[email protected]> Date: Mon Oct 30 20:38:23 2023 +0100 fixed typo in checking cp2k pattern match. commit 1a4b985 Author: robinzyb <[email protected]> Date: Mon Oct 30 14:34:50 2023 +0100 update error for cp2k aimdoutput if none pattern is matched commit a1a171a Merge: 621d686 1b55e6c Author: Yongbin Zhuang <[email protected]> Date: Mon Oct 30 13:59:10 2023 +0100 Merge branch 'deepmodeling:devel' into devel commit 621d686 Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri Oct 20 22:53:54 2023 +0000 [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci commit 03cc010 Author: robinzyb <[email protected]> Date: Sat Oct 21 00:50:51 2023 +0200 add decrecaption warning when dpdata throws errors while parsing cp2k commit 0576449 Merge: 4840bbc dbe2bc9 Author: Yongbin Zhuang <[email protected]> Date: Sat Oct 21 00:30:18 2023 +0200 Merge branch 'deepmodeling:devel' into devel commit 4840bbc Author: robinzyb <[email protected]> Date: Thu Sep 7 14:12:19 2023 +0200 Update README.md for recommendation of using cp2kdata
I squashed and recommitted this PR in 7fb45d8 and force-pushed to the devel branch. |
sorry. didn't know the procedure. How should I do next? |
No description provided.