hydride icon indicating copy to clipboard operation
hydride copied to clipboard

Minimization sometimes does not terminate

Open ncoish opened this issue 1 year ago • 5 comments

Frequently when running relax_hydrogen in my project, if I do not set iterations, the function seems to get stuck for particular angle_increment values. Ideally I want my program to run in the default way (i.e. run until a local minimum is found), so I currently am using a somewhat convoluted timeout function which attempts to interrupt the running function if it seems to be a stuck in an endless minimization loop, and then modifies the angle_increment until it finds one that works.

I could avoid using this timeout function if I could instead provide a maximum iterations and swap to a new angle_increment if the maximum iterations are reached. The issue right now is, if I provide iterations, I have no way to tell if the function terminates because it reached a local minimum successfully, or if it just hits the maximum number of iterations. It would be very helpful if the returned value from this function has some way to indicate the circumstances under which is terminated, either by always returning the number of iterations that were performed (which exposes the most information), or if that's not desired for some reason, just returning some kind of indicator of whether a local minimum was reached.

ncoish avatar Nov 18 '24 15:11 ncoish

I think you have a good point here. It wouldn't hurt to return the number of iterations.

What worries me a bit is the minimization loop you mentioned. If you have a small reproducible example, could you create an issue for that?

padix-key avatar Nov 22 '24 21:11 padix-key

Sorry it's taken me so long to come back and have a look at this. I've discovered two things:

  1. I didn't realize that I could get the energies back from relax_hydrogen. This array will allow me to infer what n_iterations was, so I actually don't need this feature!
  2. I have found several examples where this problem occurs, but the structures we have generated contain proprietary data, so I cannot share them. I will continue looking for a simple structure which replicates the problem, but in the meantime, I've noticed that when the algorithm terminates, the energy values are relatively low, and display decimal point values:
[14704.08984375  5410.91064453  2115.15258789  1218.01000977
  1101.6027832   1101.52026367  1101.50854492  1101.50854492]

Whereas in the case where the algorithm does not terminate (until it hits max_iterations) the value seems to stop changing, but is quite large and I can only see the whole number portion of the floating point value.

[22285790. 22276296. 22272872. 22271888. 22271706. 22271662. 22271638.
 22271624. 22271616. 22271610. 22271610. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606. 22271606. 22271606. 22271606. 22271606. 22271606.
 22271606. 22271606.]

I hope this is helpful.

ncoish avatar Mar 28 '25 17:03 ncoish

For what it's worth, I think the high energies may likely be due to some mistaken bonds that our scientists may be adding between very distant atoms, so maybe the energies are still changing at each step, but only at a highly precise value as the relaxation tries to resolve these bad bonds.

ncoish avatar Mar 28 '25 18:03 ncoish

I suspect that there might be some bug in the termination condition, making the minimization oscillate around some minimum energy state. When I have time, I will revisit #11, which introduces a different minimization algorithm and hence probably would solve this problem.

padix-key avatar Mar 29 '25 16:03 padix-key

I didn't realize that I could get the energies back from relax_hydrogen. This array will allow me to infer what n_iterations was, so I actually don't need this feature!

You are right! I did not think about this option. I'll rename this PR to discuss the 'endless minimization loop' bug instead

padix-key avatar Mar 29 '25 16:03 padix-key