Repository navigation
HagerZhang: do not evaluate a secant point that is not strictly inside the bracket - #213
Merged
Merged
Conversation
…e the bracket `secant2!` evaluated `ϕdϕ(c)` at the secant root before checking where it landed. The root is not finite when the two slopes coincide, which was already handled by bisecting, and it rounds onto an endpoint when the bracket is a few ulps wide or one slope is negligible against the other. The value and slope at an endpoint are already stored, so that evaluation is a wasted objective call, and `update!` (since JuliaNLSolvers#212) discards its result anyway. It is also the evaluation that exposed JuliaNLSolvers#211: a fresh slope at alpha = 0 that disagreed in sign with the stored `dphi_0`. Treat a non-interior secant root like a non-finite one and bisect instead, and require the second secant point to be strictly interior as well.
pkofod
reviewed
Sep 14, 2026
pkofod
approved these changes
Sep 14, 2026
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.
HagerZhang: do not evaluate a secant point that is not strictly inside the bracket
Follow-up to #211 / #212.
The problem
secant2!computes the secant rootcand callsϕdϕ(c)before checking whereclanded. Only afterwards doesupdate!classify it, and since #212 it rejects acthat is not strictly interior. So a secant root that rounds onto an endpoint costs a full objective evaluation whose result is thrown away.The root lands on an endpoint in two ordinary situations: the bracket is a few ulps wide, or one slope is negligible against the other, so
(a * dphi_b - b * dphi_a) / (dphi_b - dphi_a)rounds toaorb. The value and slope at both endpoints are already stored, so there is nothing to learn from evaluating there.This is also the evaluation that exposed #211. With
a == 0, the wasted call re-evaluates the objective atx + 0 * s == x, and if the slope it returns differs from the storeddphi_0by rounding, it can differ in sign once the true slope is at the noise floor. #212 madeupdate!robust to that; this PR removes the evaluation that produced the disagreement in the first place. With it, nothing in HagerZhang ever re-evaluates the objective atalpha = 0, so the route by which the caller computeddphi_0cannot matter to the line search.The change
c(!(a < c < b)) like the existing non-finite case and bisect instead. The non-finite check is subsumed, sincea < NaN < bis false.a < c < brather thana <= c <= bbefore evaluating. The aside in HagerZhang: update! can return a zero-width bracket, tripping @assert B > A #211 already noted this evaluation is discarded byupdate!.The trajectory of a line search that never produces an endpoint root is unchanged. When one is produced, the bisection midpoint replaces the discarded endpoint evaluation, so the evaluation count does not increase.
Test
A new testset in
test/errors.jlbuilds a bracket[1.0, nextfloat(1.0, 2)]with slopes chosen so the secant root rounds exactly ontoain one case and ontobin the other, checks that it does, then callssecant2!with a recordingϕdϕand asserts every evaluation is strictly interior. On master both cases fail (the endpoint is evaluated); on this branch they pass.Related
The same measurement that motivated JuliaNLSolvers/Optim.jl#1284 shows the two slope routes differ at the level of the objective's own derivative noise (it tracks the ODE solver tolerance of that objective one for one), so re-evaluating at an endpoint could never have given a more trustworthy slope than the stored one. JuliaNLSolvers/Optim.jl#1286 reverts #1285 on that basis.