Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tansongchen
Copy link
Collaborator

@tansongchen tansongchen commented Apr 8, 2024

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

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add any other context about the problem here.

src/descent/halley.jl Outdated Show resolved Hide resolved
src/descent/halley.jl Outdated Show resolved Hide resolved
src/algorithms/halley.jl Outdated Show resolved Hide resolved
Copy link

codecov bot commented Apr 9, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 77.45%. Comparing base (7deb1ed) to head (92264c0).

Files Patch % Lines
src/descent/halley.jl 64.58% 17 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@tansongchen
Copy link
Collaborator Author

tansongchen commented Apr 26, 2024

@avik-pal Support for in-place f and tests are added. Let me know if you have any questions!

I think there isn't an eqivalent for Fix2 that fixes the third argument, which is needed by evaluating the derivatives given p. Is it ok to use a closure?

@avik-pal
Copy link
Member

I think there isn't an eqivalent for Fix2 that fixes the third argument, which is needed by evaluating the derivatives given p. Is it ok to use a closure?

Yes mark it as @closure and do it

@avik-pal avik-pal linked an issue Apr 30, 2024 that may be closed by this pull request
src/descent/halley.jl Outdated Show resolved Hide resolved
test/misc/halley_tests.jl Outdated Show resolved Hide resolved
@tansongchen
Copy link
Collaborator Author

I am trying to add this as a block in 23_test_problems_tests.jl so I can make use of these problems. Do you know how to run a @testitem independently? With the vscode built-in test runner, I am getting the following error:

image

@avik-pal
Copy link
Member

avik-pal commented May 2, 2024

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

@tansongchen
Copy link
Collaborator Author

Ok I added it to this file near NewtonRaphson. Some cases haven't work mainly due to limitations of TaylorDiff.jl

@tansongchen
Copy link
Collaborator Author

@avik-pal Do you have an out-of-place version of 23 problems? When testing with SimpleHallely, I hit

12:48:34 | START (1/1) test item "SimpleHalley" at test/core/23_test_problems_tests.jl:53
┌ Error: ErrorException("SimpleHalley currently only supports out-of-place nonlinear problems")
└ @ Main.var"##RobustnessTesting#247" ~/Public/SimpleNonlinearSolve.jl/test/core/23_test_problems_tests.jl:28

@avik-pal
Copy link
Member

Don't the tests in simplenonlinearsolve use the oop version?

@tansongchen
Copy link
Collaborator Author

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 f's

@tansongchen
Copy link
Collaborator Author

Ok so I manually ran [1, 5, 8, 15, 16] against SimpleHalley, and 1, 5, 15, 16 also failed. 8 is due to an error on TaylorDiff.jl and has been fixed. I need to release a new version of TaylorDiff to make the CIs pass though.

@tansongchen
Copy link
Collaborator Author

Should be fine now, @avik-pal could you review that again?

@avik-pal
Copy link
Member

Handle the test failures, the Misc ones are real

@tansongchen
Copy link
Collaborator Author

Ok, tried to fix the precompilation issue and added compat

@tansongchen
Copy link
Collaborator Author

Now all fails are unrelated

@avik-pal
Copy link
Member

Are you sure? There are no failures on master. Some weird interaction of Taylor diff with zygote?

@tansongchen
Copy link
Collaborator Author

hmm, that's weird. The Zygote stuff in TaylorDiff doesn't have type piracy so shouldn't have weird interactions

@avik-pal avik-pal mentioned this pull request Jun 1, 2024
@avik-pal
Copy link
Member

avik-pal commented Jun 1, 2024

@tansongchen TaylorDiff is definitely causing problems. See #441

@avik-pal avik-pal closed this Jun 22, 2024
@avik-pal avik-pal reopened this Jun 22, 2024
Project.toml Outdated Show resolved Hide resolved
@avik-pal avik-pal mentioned this pull request Aug 17, 2024
12 tasks
@tansongchen tansongchen force-pushed the master branch 4 times, most recently from 00bded1 to 198cd4d Compare November 4, 2024 15:53
@tansongchen
Copy link
Collaborator Author

Copy link
Member

@avik-pal avik-pal left a comment

Choose a reason for hiding this comment

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

Needs some testing aprt from the 23 test problems

@@ -25,6 +25,7 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SciMLJacobianOperators = "19f34311-ddf3-4b8b-af20-060888a46c0e"
Copy link
Member

Choose a reason for hiding this comment

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

needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure why this comes in, I think that got in when I dev the libs. can be removed

Comment on lines +3 to +8
using NonlinearSolveBase: HalleyDescentCache
import NonlinearSolveBase: evaluate_hvvp
using TaylorDiff: derivative, derivative!
using FastClosures: @closure

function evaluate_hvvp(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
using NonlinearSolveBase: HalleyDescentCache
import NonlinearSolveBase: evaluate_hvvp
using TaylorDiff: derivative, derivative!
using FastClosures: @closure
function evaluate_hvvp(
using NonlinearSolveBase: NonlinearSolveBase, HalleyDescentCache
using TaylorDiff: derivative, derivative!
using FastClosures: @closure
function NonlinearSolveBase.evaluate_hvvp(

style nit

Comment on lines +1 to +15
"""
Halley(; concrete_jac = nothing, linsolve = nothing, linesearch = missing,
autodiff = nothing)

An experimental Halley's method implementation. Improves the convergence rate of Newton's method by using second-order derivative information to correct the descent direction.

Currently depends on TaylorDiff.jl to handle the correction terms,
might have more general implementation in the future.
"""
function Halley(; concrete_jac = nothing, linsolve = nothing,
linesearch = missing, autodiff = nothing)
return GeneralizedFirstOrderAlgorithm(;
concrete_jac, name = :Halley, linesearch,
descent = HalleyDescent(; linsolve), autodiff)
end
Copy link
Member

Choose a reason for hiding this comment

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

Not really a First Order method, we might want an additional split cc @ChrisRackauckas

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.

Jacobian and Hessian Free Halley's Method
3 participants