Skip to content

Fix line search step logic problem in lineSearchWolfe...#49

Merged
dong-hao merged 1 commit intomagnetotellurics:mainfrom
dong-hao:fix/logic-lineSearchWolfe
Apr 10, 2026
Merged

Fix line search step logic problem in lineSearchWolfe...#49
dong-hao merged 1 commit intomagnetotellurics:mainfrom
dong-hao:fix/logic-lineSearchWolfe

Conversation

@dong-hao
Copy link
Copy Markdown
Member

@dong-hao dong-hao commented Apr 3, 2026

... 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).

@MiCurry MiCurry self-requested a review April 3, 2026 18:02
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!===='
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@MiCurry
Copy link
Copy Markdown
Member

MiCurry commented Apr 3, 2026

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!

@dong-hao
Copy link
Copy Markdown
Member Author

dong-hao commented Apr 10, 2026

Thanks for the review and comments @MiCurry - just found some time to work on it... I will go ahead and merge it.

@dong-hao dong-hao merged commit 84f7806 into magnetotellurics:main Apr 10, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants