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 an interface to eval descriptors #1483

Merged
merged 11 commits into from
Feb 21, 2022

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Feb 18, 2022

Fix #1393.

@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2022

Codecov Report

Merging #1483 (a55f10b) into devel (33a1dfa) will increase coverage by 0.04%.
The diff coverage is 76.74%.

Impacted file tree graph

@@            Coverage Diff             @@
##            devel    #1483      +/-   ##
==========================================
+ Coverage   75.99%   76.03%   +0.04%     
==========================================
  Files          93       93              
  Lines        7674     7729      +55     
==========================================
+ Hits         5832     5877      +45     
- Misses       1842     1852      +10     
Impacted Files Coverage Δ
deepmd/infer/deep_pot.py 70.27% <76.74%> (+1.40%) ⬆️
source/op/_gelu.py 69.23% <0.00%> (-12.59%) ⬇️
deepmd/descriptor/se.py 66.66% <0.00%> (-6.07%) ⬇️
deepmd/descriptor/loc_frame.py 96.21% <0.00%> (-1.43%) ⬇️
deepmd/descriptor/se_a_ef.py 55.02% <0.00%> (-0.30%) ⬇️
source/op/_tabulate_grad.py 100.00% <0.00%> (ø)
source/op/_prod_force_grad.py 100.00% <0.00%> (ø)
source/op/_prod_virial_grad.py 100.00% <0.00%> (ø)
source/op/_soft_min_force_grad.py 100.00% <0.00%> (ø)
source/op/_prod_force_se_a_grad.py 100.00% <0.00%> (ø)
... and 11 more

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 33a1dfa...a55f10b. Read the comment docs.

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 would recommend provide an separate method for inferring the descriptors, because strictly speaking, they are intermediate variable, not the output of a model. The eval method is provided to infer the output of a model.

Comment on lines -240 to -255
if self.auto_batch_size is not None:
return self.auto_batch_size.execute_all(self._eval_inner, numb_test, natoms,
coords, cells, atom_types, fparam = fparam, aparam = aparam, atomic = atomic, efield = efield)
return self._eval_inner(coords, cells, atom_types, fparam = fparam, aparam = aparam, atomic = atomic, efield = efield)
else :
if self.auto_batch_size is not None:
e, f, v = self.auto_batch_size.execute_all(self._eval_inner, numb_test, natoms,
coords, cells, atom_types, fparam = fparam, aparam = aparam, atomic = atomic, efield = efield)
else:
e, f, v = self._eval_inner(coords, cells, atom_types, fparam = fparam, aparam = aparam, atomic = atomic, efield = efield)
if self.modifier_type is not None:
me, mf, mv = self.dm.eval(coords, cells, atom_types)
e += me.reshape(e.shape)
f += mf.reshape(f.shape)
v += mv.reshape(v.shape)
return e, f, v
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason why auto_batch_size is removed?

Copy link
Member Author

@njzjz njzjz Feb 19, 2022

Choose a reason for hiding this comment

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

Not removed. Instead, it's moved into a wrapper eval_func to make the code more clear.

@njzjz njzjz marked this pull request as draft February 19, 2022 22:10
@njzjz njzjz marked this pull request as ready for review February 20, 2022 01:00
Comment on lines 273 to 275
e += me.reshape(e.shape)
f += mf.reshape(f.shape)
v += mv.reshape(v.shape)
Copy link
Collaborator

Choose a reason for hiding this comment

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

output is not updated with me, mf, mv before return.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so. Here is a minimal example:

>>> import numpy as np
>>> output = (np.ones(3), np.ones(3), np.ones(3), np.ones(3), np.ones(3))
>>> e,f,v = output[:3]
>>> e += 1
>>> f += 2
>>> v += 3
>>> output
(array([2., 2., 2.]), array([3., 3., 3.]), array([4., 4., 4.]), array([1., 1., 1.]), array([1., 1., 1.]))

See https://stackoverflow.com/a/35910888/9567349. In Python, a+=b is different from a=a+b. a=a+b creates a new object, but a+=b modifies the original object.

Copy link
Collaborator

Choose a reason for hiding this comment

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

by e,f,v = output[:3] e, f, v are copies of the list, not refs of the list element. You may do a test as

In [1]: a = [1,2,3]                                                             

In [2]: a[2]+=1                                                                 

In [3]: a                                                                       
Out[3]: [1, 2, 4]

In [4]: e,f,v=a[:3]                                                             

In [5]: e+=1                                                                    

In [6]: f+=1                                                                    

In [7]: v+=1                                                                    

In [8]: a                                                                       
Out[8]: [1, 2, 4]

In [9]: e, f, v                                                                 
Out[9]: (2, 3, 5)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can reproduce your example.
It seems that python does not copy the numpy arrays , but do copy numbers.
Adding modification in this way confuses the readers of the code, I suggest you changing it to

output[0] += me.reshape(e.shape)
...

Comment on lines 273 to 275
e += me.reshape(e.shape)
f += mf.reshape(f.shape)
v += mv.reshape(v.shape)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can reproduce your example.
It seems that python does not copy the numpy arrays , but do copy numbers.
Adding modification in this way confuses the readers of the code, I suggest you changing it to

output[0] += me.reshape(e.shape)
...

@wanghan-iapcm wanghan-iapcm merged commit e6a7358 into deepmodeling:devel Feb 21, 2022
@njzjz njzjz deleted the eval_descriptors branch February 21, 2022 01:56
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.

None yet

3 participants