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

Support DPSpin for AtomicModel #3301

Merged
merged 69 commits into from
Mar 7, 2024
Merged

Support DPSpin for AtomicModel #3301

merged 69 commits into from
Mar 7, 2024

Conversation

iProzd
Copy link
Collaborator

@iProzd iProzd commented Feb 19, 2024

This PR support DPSpin for AtomicModel:

  • Spin base class to handle spin-related information.

  • SpinModel implementation in pt, which can generally take any backbone model, with input and output process for output like energy, dipole and etc.

  • SpinEnergyModel implementation inherited from SpinModel for energy calclulation.

  • Input improvement, now DPSpin model can take real spin as input with vitual_scale, which can support much more flexible input. (Also with dataset support for spin input.)

  • EnergySpinLoss class to process energy, force_real, force_mag, virial.

  • Add protection for environment calculations.

TODO:

  • Support forward_lower for SpinModel.
  • Add data_stat with general exclude_types for descriptors and fittings.
  • Add examples and UTs.
  • numpy model
  • Support multi-task training for SpinModel models.

Will fix in next PRs:

  • tf consistency test (?)

deepmd/pt/train/training.py Fixed Show fixed Hide fixed
deepmd/dpmodel/utils/spin.py Fixed Show fixed Hide fixed
deepmd/dpmodel/utils/spin.py Fixed Show fixed Hide fixed
deepmd/dpmodel/utils/spin.py Fixed Show fixed Hide fixed
deepmd/pt/loss/ener_spin.py Fixed Show fixed Hide fixed
deepmd/pt/loss/ener_spin.py Fixed Show fixed Hide fixed
Copy link

codecov bot commented Feb 19, 2024

Codecov Report

Attention: Patch coverage is 83.60656% with 140 lines in your changes are missing coverage. Please review.

Project coverage is 77.04%. Comparing base (fa8e645) to head (c0700c9).

Files Patch % Lines
deepmd/dpmodel/model/spin_model.py 68.96% 45 Missing ⚠️
deepmd/pt/loss/ener_spin.py 69.15% 33 Missing ⚠️
deepmd/utils/spin.py 82.55% 15 Missing ⚠️
deepmd/dpmodel/model/model.py 33.33% 14 Missing ⚠️
deepmd/entrypoints/test.py 66.66% 12 Missing ⚠️
deepmd/pt/infer/deep_eval.py 83.33% 12 Missing ⚠️
deepmd/dpmodel/utils/exclude_mask.py 50.00% 3 Missing ⚠️
deepmd/pt/train/training.py 78.57% 3 Missing ⚠️
deepmd/pt/model/model/spin_model.py 99.54% 1 Missing ⚠️
deepmd/tf/descriptor/se_a.py 66.66% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #3301      +/-   ##
==========================================
+ Coverage   76.97%   77.04%   +0.06%     
==========================================
  Files         423      394      -29     
  Lines       35950    31948    -4002     
  Branches     1620      909     -711     
==========================================
- Hits        27674    24613    -3061     
+ Misses       7408     6807     -601     
+ Partials      868      528     -340     

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

deepmd/pt/model/descriptor/env_mat.py Outdated Show resolved Hide resolved
deepmd/pt/model/atomic_model/wrapper_atomic_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_zbl_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/ener_model.py Outdated Show resolved Hide resolved
deepmd/dpmodel/utils/spin.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/__init__.py Outdated Show resolved Hide resolved
deepmd/pt/utils/stat.py Outdated Show resolved Hide resolved
deepmd/pt/utils/spin.py Fixed Show fixed Hide fixed
deepmd/dpmodel/utils/spin.py Outdated Show resolved Hide resolved
deepmd/pt/utils/env_mat_stat.py Outdated Show resolved Hide resolved
deepmd/pt/model/task/ener.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/__init__.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@wanghan-iapcm wanghan-iapcm left a comment

Choose a reason for hiding this comment

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

  • UT for all the spin implementations.
  • env_protection should be added to dpmodel
  • UT for env_protection.
  • the implementation of the dpmodel is not consistent with the pt side.

deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
deepmd/pt/utils/spin.py Outdated Show resolved Hide resolved
deepmd/pt/utils/spin.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
deepmd/pt/model/model/dp_spin_model.py Outdated Show resolved Hide resolved
pref_e = self.limit_pref_e + (self.start_pref_e - self.limit_pref_e) * coef
pref_fr = self.limit_pref_fr + (self.start_pref_fr - self.limit_pref_fr) * coef
pref_fm = self.limit_pref_fm + (self.start_pref_fm - self.limit_pref_fm) * coef
pref_v = self.limit_pref_v + (self.start_pref_v - self.limit_pref_v) * coef

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable pref_v is not used.
source/tests/tf/test_deeppot_a.py Fixed Show fixed Hide fixed
source/tests/tf/test_deeppot_a.py Fixed Show fixed Hide fixed
deepmd/infer/deep_eval.py Outdated Show resolved Hide resolved
examples/spin/se_e2_a/input_torch.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@wanghan-iapcm wanghan-iapcm left a comment

Choose a reason for hiding this comment

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

I see

deepmd/dpmodel/output_def.py Show resolved Hide resolved
source/tests/pt/model/test_autodiff.py Outdated Show resolved Hide resolved
source/tests/pt/model/test_autodiff.py Outdated Show resolved Hide resolved
deepmd/pt/infer/deep_eval.py Outdated Show resolved Hide resolved
deepmd/infer/deep_pot.py Outdated Show resolved Hide resolved
deepmd/pt/loss/ener_spin.py Show resolved Hide resolved
deepmd/pt/model/descriptor/descriptor.py Outdated Show resolved Hide resolved
deepmd/pt/model/task/fitting.py Outdated Show resolved Hide resolved
deepmd/pt/utils/env_mat_stat.py Outdated Show resolved Hide resolved
deepmd/utils/spin.py Outdated Show resolved Hide resolved
source/tests/pt/test_dp_test.py Fixed Show resolved Hide resolved
source/tests/pt/test_dp_test.py Fixed Show fixed Hide fixed
@iProzd iProzd requested review from njzjz and wanghan-iapcm March 7, 2024 07:38

class SpinTest(unittest.TestCase):
def setUp(self):
type_map_1 = ["H", "O"]

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable type_map_1 is not used.
self.use_spin_1 = [False, False]
self.virtual_scale_1 = [0.1, 0.1]

type_map_2 = ["B", "Ni", "O"]

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable type_map_2 is not used.
self.use_spin_2 = [False, True, False]
self.virtual_scale_2 = [0.1, 0.1, 0.1]

type_map_3 = ["H", "O", "B", "Ni", "O"]

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable type_map_3 is not used.
@wanghan-iapcm
Copy link
Collaborator

LGTM

@njzjz njzjz enabled auto-merge March 7, 2024 17:22
@njzjz njzjz added this pull request to the merge queue Mar 7, 2024
Merged via the queue into deepmodeling:devel with commit 09bd522 Mar 7, 2024
48 checks passed
@iProzd iProzd deleted the spin_rf branch March 28, 2024 07:40
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants