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

add decrecaption warning when dpdata throws errors while parsing cp2k #558

Merged
merged 10 commits into from
Oct 30, 2023

Conversation

robinzyb
Copy link
Collaborator

No description provided.

@robinzyb robinzyb requested a review from njzjz October 20, 2023 22:52
@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (1b55e6c) 82.90% compared to head (5028af6) 82.85%.

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     
Files Coverage Δ
dpdata/cp2k/output.py 97.28% <75.00%> (-0.56%) ⬇️
dpdata/plugins/cp2k.py 84.00% <69.23%> (-16.00%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@njzjz
Copy link
Member

njzjz commented Oct 21, 2023

#556 didn't throw any errors though

@robinzyb
Copy link
Collaborator Author

#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/
"
}

@njzjz
Copy link
Member

njzjz commented Oct 25, 2023

Firstly, move 1.out to 1.log as *.log is hard-coded in the code. (There should be an argument to adjust it.)

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       :
-------------------

@robinzyb
Copy link
Collaborator Author

The old code returns empty dict even if nothing is matched. Extra lines are added to raise StopIteration when all matches is failed.

# TODO: when pattern match is failed
# TODO: For now just use RuntimeError as a placeholder.
except RuntimeError:
print(string_warning)
Copy link
Member

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?

Copy link
Member

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

Copy link
Collaborator Author

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.

Comment on lines 21 to 22
xyz_file = sorted(glob.glob(f"{file_name}/*pos*.xyz"))[0]
log_file = sorted(glob.glob(f"{file_name}/*.log"))[0]
Copy link
Member

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.

Copy link
Member

@njzjz njzjz left a 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Try use dpdata plugin from cp2kdata package,
Try to use dpdata plugin from cp2kdata package,

@robinzyb robinzyb merged commit dfb6191 into deepmodeling:devel Oct 30, 2023
5 of 7 checks passed
@njzjz
Copy link
Member

njzjz commented Oct 30, 2023

@robinzyb, we only use Squash merge.

njzjz pushed a commit to njzjz/dpdata that referenced this pull request Oct 30, 2023
…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
@njzjz
Copy link
Member

njzjz commented Oct 30, 2023

I squashed and recommitted this PR in 7fb45d8 and force-pushed to the devel branch.

@robinzyb
Copy link
Collaborator Author

@robinzyb, we only use Squash merge.

sorry. didn't know the procedure. How should I do next?

@njzjz
Copy link
Member

njzjz commented Oct 31, 2023

How should I do next?

Nothing, as I've manually resolved it. But next time, you'd better select "squash and merge".

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the result is empty when dpdata complete the task of converting the data of cp2k to the data of deepmd
2 participants