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

Feat: add pair table model to pytorch #3192

Merged
merged 31 commits into from
Jan 31, 2024
Merged

Conversation

anyangml
Copy link
Collaborator

@anyangml anyangml commented Jan 28, 2024

Migrated from this PR. This is to reimplement the PairTab Model in Pytorch.

Notes:

  1. Different from the tensorflow version, the pytorch version abstracts away all the post energy conversion operations (force, virial).
  2. Added extrapolation when rcut > rmax. The pytorch version overwrite energy beyond extrapolation endpoint to 0. These features are not available in the tensorflow version. The extrapolation uses a cubic spline form, the 1st order derivation for the starting point is estimated using the last two rows in the user defined table. See example below:
  3. There is a known limitation, when performing cubic extrapolation for padding zeros, energy may become negative.

img_v3_027k_b50c690d-dc2d-4803-bd2c-2e73aa3c73fg

img_v3_027k_8de38597-ef4e-4e5b-989e-dbd13cc93fag

img_v3_027k_f8268564-3f5d-49e6-91d6-169a61d9347g

img_v3_027k_3966ef67-dd5e-4f48-992e-c2763311451g

Copy link

codecov bot commented Jan 28, 2024

Codecov Report

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

Comparison is base (d2edb77) 74.32% compared to head (29d95db) 74.36%.

Files Patch % Lines
deepmd/pt/model/model/pair_tab.py 89.74% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #3192      +/-   ##
==========================================
+ Coverage   74.32%   74.36%   +0.04%     
==========================================
  Files         344      345       +1     
  Lines       31868    31981     +113     
  Branches     1592     1592              
==========================================
+ Hits        23686    23783      +97     
- Misses       7257     7273      +16     
  Partials      925      925              

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

source/tests/pt/test_pairtab.py Fixed Show fixed Hide fixed
deepmd/pt/model/model/pair_tab.py Fixed Show fixed Hide fixed
deepmd/pt/model/model/pair_tab.py Fixed Show fixed Hide fixed
deepmd/pt/model/model/pair_tab.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/pair_tab.py Outdated Show resolved Hide resolved
deepmd/utils/pair_tab.py Outdated Show resolved Hide resolved
@njzjz
Copy link
Member

njzjz commented Jan 30, 2024

Does this PR fix #1895 or #1973?

@anyangml
Copy link
Collaborator Author

Does this PR fix #1895 or #1973?

It's related to these issues, and partially solves them. The extrapolation feature added in this PR only handles the case where rcut is larger than the table upper boundary, it will calculate atomic energy with cubic spline extrapolation for atoms in the range between table upper boundary and rcut.

@anyangml anyangml requested a review from njzjz January 30, 2024 08:24
torch.testing.assert_allclose(result["energy"], expected_result, 0.0001, 0.0001)

def test_jit(self):
model = torch.jit.script(self.model)

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable model is not used.
deepmd/pt/model/model/pair_tab.py Fixed Show fixed Hide fixed
@wanghan-iapcm wanghan-iapcm enabled auto-merge (squash) January 31, 2024 09:06
@wanghan-iapcm wanghan-iapcm merged commit afb440a into deepmodeling:devel Jan 31, 2024
45 checks passed
@njzjz njzjz mentioned this pull request Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants