deepmodeling / DMFF

DMFF (Differentiable Molecular Force Field) is a Jax-based python package that provides a full differentiable implementation of molecular force field models.
GNU Lesser General Public License v3.0
154 stars 43 forks source link

Errors of `example/classical/demo.ipynb` #82

Closed robinzyb closed 1 year ago

robinzyb commented 1 year ago

cell 5 line 7

nbList = NeighborList(box, rc=4, potentials.meta["cov_map"])

should be

nbList = NeighborList(box, r_cutoff=4, covalent_map=potentials.meta["cov_map"])

cell 8 line 2

pgrad = param_grad_func(positions, box, pairs, params) 

reported error for pairs

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[12], line 2
1 param_grad_func = jax.grad(nbfunc, argnums=-1)
----> 2 pgrad = param_grad_func(positions, box, pairs, params)
3 pgrad["NonbondedForce"]["charge"]

[... skipping hidden 4 frame]

File ~/anaconda3/envs/dmff/lib/python3.9/site-packages/jax/_src/api.py:1120, in _check_input_dtype_revderiv(name, holomorphic, allow_int, x)
1117 if (dtypes.issubdtype(aval.dtype, np.integer) or
         1118     dtypes.issubdtype(aval.dtype, np.bool_)):
1119   if not allow_int:
-> 1120     raise TypeError(f"{name} requires real- or complex-valued inputs (input dtype "
                            1121                     f"that is a sub-dtype of np.inexact), but got {aval.dtype.name}. "
1122                     "If you want to use Boolean- or integer-valued inputs, use vjp "
1123                     "or set allow_int to True.")
1124 elif not dtypes.issubdtype(aval.dtype, np.inexact):
1125   raise TypeError(f"{name} requires numerical-valued inputs (input dtype that is a "
                       1126                   f"sub-dtype of np.bool_ or np.number), but got {aval.dtype.name}.")

TypeError: grad requires real- or complex-valued inputs (input dtype that is a sub-dtype of np.inexact), but got int32. If you want to use Boolean- or integer-valued inputs, use vjp or set allow_int to True.
WangXinyan940 commented 1 year ago

https://github.com/deepmodeling/DMFF/commit/f23f683ca9add580a42324aed5654cee81290d28

Fixed in devel branch. Close issue.