Use gradient!(d, x). in perform_linesearch#1207
Merged
Conversation
This shouldn't matter, but *if* somehow happened to be calling the objective function in the callback or some other way this would now produce the correct result. Previously, it used the most recent evaluation. Now, it will try to evaluate at state.x and if that was the last point evaluated we'll just use the cached result. This should always be the case unless someone messed with the objective outside. We could even assert that g_calls is constant around the call to be sure to catch it but then users wouldn't be able to call the gradient outside at their own expense of runtime.
Contributor
Benchmark Results (Julia vlts)Time benchmarks
Memory benchmarks
A plot of the benchmark results has been uploaded as an artifact at . |
devmotion
reviewed
Nov 13, 2025
src/utilities/perform_linesearch.jl
Outdated
| dphi_0 = real(dot(gradient(d), state.s)) # update after direction reset | ||
| dphi_0 = real(dot(gx, state.s)) # update after direction reset | ||
| end | ||
| phi_0 = value(d) |
Contributor
There was a problem hiding this comment.
I guess this could be made safer as well by calling
Suggested change
| phi_0 = value(d) | |
| phi_0 = value!(d, state.x) |
But possibly you'd want to combine it with the gradient! call above.
Member
Author
|
Interesting that fminbox fails here.. that would indicate that it was doing some funny business in the resets |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1207 +/- ##
==========================================
- Coverage 87.56% 87.51% -0.05%
==========================================
Files 45 45
Lines 3514 3517 +3
==========================================
+ Hits 3077 3078 +1
- Misses 437 439 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This shouldn't matter, but if somehow happened to be calling the objective function in the callback or some other way this would now produce the correct result. Previously, it used the most recent evaluation. Now, it will try to evaluate at state.x and if that was the last point evaluated we'll just use the cached result. This should always be the case unless someone messed with the objective outside. We could even assert that g_calls is constant around the call to be sure to catch it but then users wouldn't be able to call the gradient outside at their own expense of runtime.