Skip to content

Navigation Menu

Sign in
Sign up

Question about using the analytical Hessian feature (related to PR #5287) #5349

Answered by njzjz
RA-zoL asked this question in Q&A
Discussion options

Dear deepmodeling team,

I am trying to optimize some molecular transition state structures with the recently released DPA3-Omol-Large model. It works well in providing energy, analytical forces and numerical Hessians to the optimizer.

I noticed that PR #5287 introduced support for calculating the analytical Hessians. However, I couldn't find any related discussion or documentation on how to actually use this feature.

Could you please clarify how to invoke the analytical Hessian functionality?

Any guidance or pointers to relevant docs/examples would be greatly appreciated. Thank you for your work on DeepMD.

You must be logged in to vote

I fixed a bug in #5351. After patching that PR, you could obtain the Hessian with the following script

from deepmd.infer import DeepPot
import numpy as np
dp=DeepPot("/home/jzzeng/.cache/deepmd/pretrained/models/DPA3-Omol-Large.pt", no_jit=True)
dp.get_model().enable_hessian()
dp.deep_eval._has_hessian=True
coord = np.array([[1, 0, 0], [0, 0, 1.5], [1, 0, 3]]).reshape([1, -1])
atype = [1, 0, 1]
e, f, v, h = dp.eval(coord, None, atype)
print(h)

Replies: 2 comments 1 reply

Comment options

Hi @RA-zoL! I'm Dosu and I’m helping the deepmd-kit team.

The analytical Hessian feature is documented here: Fit energy Hessian.

To use it with the PyTorch backend:

  1. Enable Hessian on your model:
model.enable_hessian()
model.requires_hessian("energy")
  1. Or use the factory function:
from deepmd.pt.model.model import make_hessian_model
model_hess = make_hessian_model(EnergyModel)(descriptor, fitting, type_map=type_map)
model_hess.requires_hessian("energy")
  1. Get the Hessian from forward pass:
ret_dict = model_hess.forward_common(coord, atype, box=cell)
ana_hess = ret_dict["hessian"] # or "energy_derv_r_derv_r"

There's also a complete test example showing usage.

Important limitations:

Regarding DPA3-Omol-Large: The Hessian implementation is descriptor-agnostic and uses PyTorch's automatic differentiation at the model level, so it should theoretically work with DPA3 models. However, I didn't find explicit tests or documentation confirming DPA3 + Hessian compatibility, so you may want to test this or check with the maintainers.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about deepmd-kit with Dosu Add Dosu to your team

You must be logged in to vote
0 replies
Comment options

I fixed a bug in #5351. After patching that PR, you could obtain the Hessian with the following script

from deepmd.infer import DeepPot
import numpy as np
dp=DeepPot("/home/jzzeng/.cache/deepmd/pretrained/models/DPA3-Omol-Large.pt", no_jit=True)
dp.get_model().enable_hessian()
dp.deep_eval._has_hessian=True
coord = np.array([[1, 0, 0], [0, 0, 1.5], [1, 0, 3]]).reshape([1, -1])
atype = [1, 0, 1]
e, f, v, h = dp.eval(coord, None, atype)
print(h)
You must be logged in to vote
1 reply
Comment options

Thank you for your reply!

Answer selected by RA-zoL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /