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

Line Search failed using LBFGS for optimisation of chemical structures #33

Open
conradhuebler opened this issue May 10, 2023 · 12 comments

Comments

@conradhuebler
Copy link

Hey,

I am using this nice header-only LBFGS implementation to provide a geometry optimisation method in my molecular modelling program (https://github.com/conradhuebler/curcuma).

In order to have more control over the optimisation with respect to my quantities of interest, I made some changes to allow single steps during the minimisation and yesterday I merged the current upstream repo into my fork. However, now the line search and the optimisation fail.

As I merged the repos and need my personal changes, I can not track down the specific commit, which makes it fail.

So can I tweak some settings to recover the behaviour of the linesearch before:
commit 563106b
Author: Yixuan Qiu yixuanq@gmail.com
Date: Fri May 27 09:13:20 2022 +0800
?

The problem is, that either the numer of iterations in the line search is to low (thousends are not enough) or it might take to long for no positive outcome.

Is there something I could try?
Thanks and thanks for making LBFGSpp,
Conrad

@genmeblog
Copy link

genmeblog commented May 10, 2023

You can find #32 related. Try to comment out normalization step: #32 (comment)
In case you're using MoreThuente linesearch

@conradhuebler
Copy link
Author

Thanks for the comment. However, this does not really apply for my problem, as I am not using the box-constrained approach. Furthermore, it happens, depending on the 3D structure for several LineSearch methods.

I have provided some samples and documentation:
https://gist.github.com/conradhuebler/445e6cd16c1f91230a9386c5abc320eb

@yixuan
Copy link
Owner

yixuan commented May 11, 2023

I'll take a look over the weekends.

@yixuan
Copy link
Owner

yixuan commented May 14, 2023

Since I am not super familiar with the library, I want to make sure one thing before I dive into the details. In your program, is the gradient computed analytically or numerically? Sometimes this is important since the line search can heavily rely on the accuracy of the gradient.

@conradhuebler
Copy link
Author

Depending on the method to calculate the energy, the gradient is calculated either numerically or analytically. If no method is specified or '-method uff' is added, the gradient is still calculated numerically, but if the methods are gfn1 or gfn2 are used, the gradients are evaluated analytical.
However, in older versions of LBFGSpp, the numerically evaluated gradient did not make trouble.

@yixuan
Copy link
Owner

yixuan commented May 21, 2023

After some investigation I guess it is because in the old version, the line search silently exits if it reaches the maximum iteration (76ac83f), and in the new version it explicitly raises an exception.

I would consider allowing some "failed" line searches in the new version. But still, an accurate computation of the gradient is invaluable in any case.

@conradhuebler
Copy link
Author

Thanks for having a look at it. I am currently implementing the analytical gradients for the universal force field and with two terms out of five replaced, the optimisation is faster (of course) and much smoother.

However, another method, which I just use via an interface and already is having analytical gradients, fails. So some kind "failed" lines searches sound great.

@yixuan
Copy link
Owner

yixuan commented May 24, 2023

I have pushed a commit (6803e70) that realizes such an idea. Could you help test on your problems? Thanks.

@conradhuebler
Copy link
Author

Hi,

I now have implemented the last part of the analytical gradient. I will compile some test cases in an extra branch. However, as far as I tested it already, your update does not really fix the issue, and it is more or less independent of the scheme to calculate the gradient.

More will follow in the next days.

Nevertheless, thanks for your time :-)

@yixuan
Copy link
Owner

yixuan commented May 31, 2023

Sure. Some minimal examples would be greatly appreciated.

@conradhuebler
Copy link
Author

Hi, I have added some example structure files and some short explanation to https://github.com/conradhuebler/curcuma/tree/lbfgs/test_cases/optimisation in the branch https://github.com/conradhuebler/curcuma/tree/lbfgs.

It might be a bit tricky to get started first but:
The energy and gradients are obtained using the methods: UFF, GFNFF, and GFN2. They can be requested with
-method uff
-method gfnff
-method gfn2

-method uff is not necessary, as uff is the default one. There are numerical and analytical gradients for uff (-gradient 0 and -gradient 1). The gradients in gfnff und gfn2 are analytical. However, these methods are slower and come from third-party software. The first thing to start would be with the triose structure.
So within that directory
~/yourpath/curcuma -opt input.xyz with LBFGS master and LBFGS (7e38486)
This should show the difference.
Thanks and good luck :-)

@conradhuebler
Copy link
Author

Hi there,

I have been playing around with the optimisation. I think, that for optimisation of chemical structure, throwing an exception if the linesearch fails etc is to harsh. The optimisation may proceed if this errors are just ignored for some steps. However, more digging is mandantory.

I will adopt my fork to realise single step optimisation, where each of the termination condition can be handled individually and maybe some parameters can be altered during the optimsation. That is more (al)chemsitry than maths and if you are not interested in having this abilities in your library, than feel free to close this issue.

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

No branches or pull requests

3 participants