-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add Halley's method via descent API #404
base: master
Are you sure you want to change the base?
Conversation
src/descent/halley.jl
Outdated
end | ||
b = cache.b | ||
# compute the hessian-vector-vector product | ||
hvvp = derivative(x -> cache.f(x, cache.p), u, δu, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hvvp = derivative(x -> cache.f(x, cache.p), u, δu, 2) | |
hvvp = derivative(Base.Fix2(cache.f, cache.p), u, δu, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also need a case for inplace cache.f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. TaylorDiff.jl haven't got a in-place mode yet, but will do this week
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #404 +/- ##
==========================================
- Coverage 86.45% 77.45% -9.01%
==========================================
Files 47 49 +2
Lines 2872 2918 +46
==========================================
- Hits 2483 2260 -223
- Misses 389 658 +269 ☔ View full report in Codecov by Sentry. |
@avik-pal Support for in-place I think there isn't an eqivalent for |
Yes mark it as |
test/misc/halley_tests.jl
Outdated
@testitem "Halley method" begin | ||
f(u, p) = u .* u .- p | ||
f!(fu, u, p) = fu .= u .* u .- p | ||
u0 = [1.0, 1.0] | ||
p = 2.0 | ||
|
||
# out-of-place | ||
prob1 = NonlinearProblem(f, u0, p) | ||
sol1 = solve(prob1, Halley()) | ||
@test sol1.u ≈ [sqrt(2.0), sqrt(2.0)] | ||
|
||
# in-place | ||
prob2 = NonlinearProblem(f!, u0, p) | ||
sol2 = solve(prob2, Halley()) | ||
@test sol2.u ≈ [sqrt(2.0), sqrt(2.0)] | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a bit more comprehensive tests here similar to SimpleNonlinearSolve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will do
Yeah ReTestItems doesn't yet work with VSCode Test Runner. In a julia REPL activate the test using TestEnv then do using ReTestItems
ReTestItems.runtests(<path to file or test directory>; name="<name of the testitem>") |
Ok I added it to this file near |
@avik-pal Do you have an out-of-place version of 23 problems? When testing with
|
Don't the tests in simplenonlinearsolve use the oop version? |
So currently, the tests at https://github.com/SciML/SimpleNonlinearSolve.jl/blob/main/test/core/23_test_problems_tests.jl doesn't include Halley's method, and when I tried to add Halley in the same way as Newton, I get the error above. And the file at https://github.com/SciML/DiffEqProblemLibrary.jl/blob/master/lib/NonlinearProblemLibrary/src/NonlinearProblemLibrary.jl doesn't have out-of-place |
Ok so I manually ran |
Should be fine now, @avik-pal could you review that again? |
Handle the test failures, the |
Ok, tried to fix the precompilation issue and added compat |
Now all fails are unrelated |
Are you sure? There are no failures on master. Some weird interaction of Taylor diff with zygote? |
hmm, that's weird. The Zygote stuff in TaylorDiff doesn't have type piracy so shouldn't have weird interactions |
@tansongchen TaylorDiff is definitely causing problems. See #441 |
@@ -28,6 +28,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | |||
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804" | |||
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" | |||
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" | |||
TaylorDiff = "b36ab563-344f-407b-a36a-4f200bebf99c" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TaylorDiff brings in Symbolics, which seems like quite a heavy dep. We have quite a few downstream users notably OrdinaryDiffEq.
Won't this affect load times? @ChrisRackauckas @oscardssmith thoughts on this? Should we make it a weak dep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this be an extension alg in a lib like what we're doing in OrdinaryDiffEq.jl? NonlinearSolve.jl is going to have the same issue of just having too many algorithms at some point, and this seems like something that can be a lib extension
Add Halley's method by computing Hessian-vector-vector product with TaylorDiff.jl in$O(n)$ time. Note that this isn't structured as something like "HessianCache", but instead structured as a descent method, which can be viewed as "adding some correction term to the Newton's method". This is mainly because Hessian, either implicitly or explicitly, isn't likely to be used elsewhere.
Tests haven't been added because TaylorDiff.jl should be added to an extension. Once that is done, it is straightforward to add tests.
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Add any other context about the problem here.