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

[BUG] Inconsistent optimization trajectories when using DPA2 and ASE #4502

Closed
Chengqian-Zhang opened this issue Dec 24, 2024 · 4 comments
Closed
Labels

Comments

@Chengqian-Zhang
Copy link
Collaborator

Bug summary

When using DPA2 and ASE for two identical structural optimizations, the trajectories are inconsistent.

The first time:
Image
The second time:
Image

Note that the python script and init structure is completely the same. So the two trajs should be the same.

DeePMD-kit Version

devel

Backend and its version

pytorch v2.5.1+cu124

How did you download the software?

pip

Input Files, Running Commands, Error Log, etc.

# relax.py
from ase import Atoms
from deepmd.calculator import DP
from ase.io import Trajectory
water = Atoms('H2O3', positions=[(0.3, 0.3, 0.3),(0.5, 0.5, 0.5),(0.7, 0.7, 0.7),(0.1,0.1,0.1),(0.6,2.5,3.7)],cell=[5, 5, 5],calculator=DP(model="dpa2_frozen_model.pth"))
print(water.get_potential_energy())
print(water.get_forces())
from ase.optimize import LBFGS
traj = Trajectory('traj.traj', 'w', water)
dyn = LBFGS(water)
dyn.attach(traj.write, interval=1)
dyn.run(fmax=1e-6,steps=50)

print(water.get_positions())

Steps to Reproduce

run

python3 relax.py

for two times.
The results are different.

Further Information, Files, and Links

When a structure is used for energy and force inference, there may be some small errors (such as 1e-10), but this error of dpa2 will accumulate with the increase of optimization steps, and this bug will occur when it accumulates to a relatively large value. The error accumulation of the small model (se_2_a) is not as fast as dpa2.
Image
Image

@njzjz
Copy link
Member

njzjz commented Dec 24, 2024

Could you call torch.use_deterministic_algorithms(True) and see if the result is still different?

@wanghan-iapcm
Copy link
Collaborator

It may happen that starting from the same initial point, the structure is relaxed to different local minima due to the small perturbation (like the truncation error) on the trajectory.

water = Atoms('H2O3', positions=[(0.3, 0.3, 0.3),(0.5, 0.5, 0.5),(0.7, 0.7, 0.7),(0.1,0.1,0.1),(0.6,2.5,3.7)],cell=[5, 5, 5],calculator=DP(model="dpa2_frozen_model.pth"))

It is not physically meaningful structure,

  1. the formula does not make sense.
  2. at least the first 2 H atoms are too close: distance 0.34 A

@QuantumMisaka
Copy link

QuantumMisaka commented Dec 25, 2024

@Chengqian-Zhang You can try with a physical input structure. in my practices using DPA-2 for surface reactions simulation, the geometry optimizaition and even transition state optimization in ASE using DPA-2 will be repeatable

@Chengqian-Zhang
Copy link
Collaborator Author

Thank you for your patient explanation.
There are two conclusion:

  1. Reaching different local minima due to the small perturbation is normal whening using unphysically initial structure.
  2. If one want to reach completely the same local minima. Calling torch.use_deterministic_algorithms(True) works well.
    So I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants