Fix line search step logic problem in lineSearchWolfe...#49
Merged
dong-hao merged 1 commit intomagnetotellurics:mainfrom Apr 10, 2026
Merged
Conversation
MiCurry
reviewed
Apr 3, 2026
| write(*,'(a50)') '!======Strong Wolfe Condition NOT satisfied!======' | ||
| write(ioLog,'(a50)') '!======Strong Wolfe Condition NOT satisfied!======' | ||
| write(*,'(a47)') '!=====Strong Wolfe Condition NOT satisfied!====' | ||
| write(ioLog,'(a47)') '!=====Strong Wolfe Condition NOT satisfied!====' |
Member
There was a problem hiding this comment.
I think we can also just use A here without the width specification: write(*, '(A)') .... Since we always want this full string printed, there isn't a need to specify the length, regardless, what you have here is fine and I'm good to approve it!
Member
|
I can't really speak for the math/logic of the line search, but I am able to run this on the MF, SP, and SP2 versions of the code with both Wolfe line searches for NLCG and LBFGS! So I'm good to have this PR merged in! Thanks @dong-hao! |
Member
Author
|
Thanks for the review and comments @MiCurry - just found some time to work on it... I will go ahead and merge it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
... for both NLCG and LBFGS.
The problem: the fallback measure for a failed cubic fitting can lead to a zero line search step. In NLCG.f90, the fallback uses sqrt(alpha_l*alpha_r) to calculate a test step length. However, since alpha_l is initialized to 0 at the beginning of the lineSearchWolfe, this can produce alpha = 0 and the NaN problem in issue #47.
Also fixed a couple of possible problems when g_1 can be uninitialized before the cubic phase. If f > f_1 and also f_1 >= f_0, the code skips both gradient evaluations but still use g_1 to update alpha_l/alpha_r, which may lead to unpredictable results.
On the other hand, the cubic sectioning procedure is not safeguarded to stay inside the previous bracket. Alpha was taken directly from the cubic minimizer (but never checked to be between [alpha_l, alpha_r]. This may also lead to a failed bracketing procedure.
Still, this bug should have no impact at all as lineSearchWolfe was never wired in either NLCG or LBFGS (unless a user suddenly wants to try it and modifies the hard-coded "flavor" for line search).