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

make deep tensor deriv again #805

Merged
merged 21 commits into from
Jul 1, 2021
Merged

make deep tensor deriv again #805

merged 21 commits into from
Jul 1, 2021

Conversation

y1xiaoc
Copy link
Contributor

@y1xiaoc y1xiaoc commented Jun 27, 2021

The main purpose of this PR is to implement the (component-wise) force and virial calculation for the global tensor predicted by deep tensor models. Since the outputs are tensors, the force and tensor are calculated on each separate component and later stacked together. Similar tasks has been implemented for dplr calculation in DataModifier class. The current one has the following difference:

  • the derivative is calculated on the global tensor, instead of atomic ones like DataModifier.
  • since global tensor contains few components, the derivative is implemented as loop over components, which may be slower
  • the component-wise derivative (i.e. jacobian) is given directly, and there's no need to pass a head gradient to the graph.

The design is chosen to fit the potential usage in plumed. If per-atom derivative is needed instead, consider using DataModifier or modify it.

In detail, the PR mainly do the following things:

  • change the tensor model so that the graph includes new ops for calculating global tensor, force and (atomic) virial
  • add a new function eval_full in DeepTensor python class, which resembles the eval function in DeepPot class, that will output global tensor, force and virial (and atomic tensor and atomic virial if atoimc=True)
  • add several overload to the compute function in DeepTensor c++ class, which again resemble the compute function in DeepPot class, and correspond to the python counter part

as well as several minor changes:

  • add more unittests to support the new force and virial calculations, and a corner case for the order of the output tensor
  • refine the old eval in the python class of DeepTensor to handle the pbc correctly
  • fix a bug in the old c++ interface where the output tensor could be in wrong order (but old fix dplr was correct)
  • change the output of tensor model to rank 2 (with shape [nframes, (natoms x) odim]) to be consistent with other part of the code (it also handles the suffix correctly now)

and some technical details:

The implementation of this PR paid special attention to backward compatibility, so the old models should still be able to run on the new code without changing anything. However, to use the new force and virial feature, one needs to retrain (since I directly changed the procedure of building the graph) and refreeze a new model.

@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2021

Codecov Report

Merging #805 (7102d2a) into devel (a951d8b) will increase coverage by 0.31%.
The diff coverage is 97.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##            devel     #805      +/-   ##
==========================================
+ Coverage   73.68%   73.99%   +0.31%     
==========================================
  Files          85       84       -1     
  Lines        6646     6733      +87     
==========================================
+ Hits         4897     4982      +85     
- Misses       1749     1751       +2     
Impacted Files Coverage Δ
deepmd/entrypoints/freeze.py 74.46% <ø> (ø)
deepmd/infer/deep_polar.py 65.21% <ø> (ø)
source/api_cc/include/DeepTensor.h 20.00% <ø> (ø)
deepmd/infer/deep_tensor.py 95.12% <96.00%> (+1.90%) ⬆️
deepmd/infer/deep_eval.py 96.87% <100.00%> (-0.04%) ⬇️
deepmd/loss/tensor.py 51.81% <100.00%> (ø)
deepmd/model/tensor.py 96.73% <100.00%> (+1.21%) ⬆️
source/api_cc/include/AtomMap.h

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a951d8b...7102d2a. Read the comment docs.

source/api_cc/tests/test_utils.h Show resolved Hide resolved
source/tests/common.py Outdated Show resolved Hide resolved
@njzjz njzjz linked an issue Jun 30, 2021 that may be closed by this pull request
@amcadmus amcadmus merged commit 424fe13 into deepmodeling:devel Jul 1, 2021
gzq942560379 pushed a commit to HPC-AI-Team/deepmd-kit that referenced this pull request Sep 2, 2021
* fix build bug with cuda 11

* git ignore files generated during build

* global, force, virial  for tensor model in python

* speed up reverse_map in deep_eval

* add atom_virial in tensor model; handle suffix

* support tensor force and virial in python infer

* update gitignore to exclude c++ test builds

* add a  new dipole unit test to reveal the cpp bug

* fix the c++ deeptensor sorting bug (I assume)

* change graph output tensor to rank 2

* fix the missing semicolon

* implement c++ tensor force and virial bug have a bug with nlist

* fix some other bugs, but the nlist on remains

* add finite difference for tensor py infer test

* fix the nlist bug!

* add unittests for c++ deeppolar force

* skip new tests if tf version is too low

* update .gitignore

* add print summary for deep tensor

* fix tab alignment for new functions

* reorganize overloads, refine finite difference
njzjz added a commit to njzjz/deepmd-kit that referenced this pull request Sep 21, 2023
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.

[Feature Request] support -std=c++17
4 participants