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

fix: remove uses of LineSearches.jl backtracking #480

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Downgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ["1"]
version: ["1.10"]
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NonlinearSolve"
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
authors = ["SciML"]
version = "3.15.1"
version = "3.15.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -80,7 +80,7 @@ Hwloc = "3"
InteractiveUtils = "<0.0.1, 1"
LazyArrays = "1.8.2, 2"
LeastSquaresOptim = "0.8.5"
LineSearch = "0.1.2"
LineSearch = "0.1.4"
LineSearches = "7.3"
LinearAlgebra = "1.10"
LinearSolve = "2.35"
Expand All @@ -96,7 +96,7 @@ Pkg = "1.10"
PrecompileTools = "1.2"
Preferences = "1.4"
Printf = "1.10"
Random = "1.91"
Random = "1.10"
ReTestItems = "1.24"
RecursiveArrayTools = "3.27"
Reexport = "1.2"
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/large_systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ prob_brusselator_2d_autosparse = NonlinearProblem(
u0, p; abstol = 1e-10, reltol = 1e-10)

@btime solve(prob_brusselator_2d_autosparse,
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 32)));
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 12)));
@btime solve(prob_brusselator_2d_autosparse,
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 32),
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 12),
linsolve = KLUFactorization()));
@btime solve(prob_brusselator_2d_autosparse,
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 32),
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 12),
linsolve = KrylovJL_GMRES()));
nothing # hide
```
Expand Down
2 changes: 1 addition & 1 deletion src/NonlinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export NewtonDescent, SteepestDescent, Dogleg, DampedNewtonDescent, GeodesicAcce
## Line Search Algorithms
export LineSearchesJL, LiFukushimaLineSearch # FIXME: deprecated. use LineSearch.jl directly
export Static, HagerZhang, MoreThuente, StrongWolfe, BackTracking # FIXME: deprecated
export NoLineSearch, RobustNonMonotoneLineSearch
export LineSearch, NoLineSearch, RobustNonMonotoneLineSearch
## Trust Region Algorithms
export RadiusUpdateSchemes

Expand Down
20 changes: 5 additions & 15 deletions src/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ function RobustMultiNewton(::Type{T} = Float64; concrete_jac = nothing, linsolve
radius_update_scheme = RadiusUpdateSchemes.Bastin),
NewtonRaphson(; concrete_jac, linsolve, precs, autodiff),
NewtonRaphson(; concrete_jac, linsolve, precs,
linesearch = LineSearch.LineSearchesJL(;
method = LineSearches.BackTracking()),
autodiff),
linesearch = LineSearch.BackTracking(), autodiff),
TrustRegion(; concrete_jac, linsolve, precs,
radius_update_scheme = RadiusUpdateSchemes.NLsolve, autodiff),
TrustRegion(; concrete_jac, linsolve, precs,
Expand Down Expand Up @@ -407,9 +405,7 @@ function FastShortcutNonlinearPolyalg(
else
algs = (NewtonRaphson(; concrete_jac, linsolve, precs, autodiff),
NewtonRaphson(; concrete_jac, linsolve, precs,
linesearch = LineSearch.LineSearchesJL(;
method = LineSearches.BackTracking()),
autodiff),
linesearch = LineSearch.BackTracking(), autodiff),
TrustRegion(; concrete_jac, linsolve, precs, autodiff),
TrustRegion(; concrete_jac, linsolve, precs,
radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff))
Expand All @@ -430,9 +426,7 @@ function FastShortcutNonlinearPolyalg(
SimpleKlement(),
NewtonRaphson(; concrete_jac, linsolve, precs, autodiff),
NewtonRaphson(; concrete_jac, linsolve, precs,
linesearch = LineSearch.LineSearchesJL(;
method = LineSearches.BackTracking()),
autodiff),
linesearch = LineSearch.BackTracking(), autodiff),
TrustRegion(; concrete_jac, linsolve, precs,
radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff))
end
Expand All @@ -451,9 +445,7 @@ function FastShortcutNonlinearPolyalg(
Klement(; linsolve, precs, autodiff),
NewtonRaphson(; concrete_jac, linsolve, precs, autodiff),
NewtonRaphson(; concrete_jac, linsolve, precs,
linesearch = LineSearch.LineSearchesJL(;
method = LineSearches.BackTracking()),
autodiff),
linesearch = LineSearch.BackTracking(), autodiff),
TrustRegion(; concrete_jac, linsolve, precs, autodiff),
TrustRegion(; concrete_jac, linsolve, precs,
radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff))
Expand Down Expand Up @@ -489,9 +481,7 @@ function FastShortcutNLLSPolyalg(
linsolve, precs, disable_geodesic = Val(true), autodiff, kwargs...),
TrustRegion(; concrete_jac, linsolve, precs, autodiff, kwargs...),
GaussNewton(; concrete_jac, linsolve, precs,
linesearch = LineSearch.LineSearchesJL(;
method = LineSearches.BackTracking()),
autodiff, kwargs...),
linesearch = LineSearch.BackTracking(), autodiff, kwargs...),
TrustRegion(; concrete_jac, linsolve, precs,
radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff, kwargs...),
LevenbergMarquardt(; linsolve, precs, autodiff, kwargs...))
Expand Down
63 changes: 41 additions & 22 deletions test/core/rootfind_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ end
# --- NewtonRaphson tests ---

@testitem "NewtonRaphson" setup=[CoreRootfindTesting] tags=[:core] begin
@testset "LineSearch: $(_nameof(lsmethod)) LineSearch AD: $(_nameof(ad))" for lsmethod in (
Static(), StrongWolfe(), BackTracking(), HagerZhang(), MoreThuente()),
ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff())
@testset "LineSearch: $(_nameof(linesearch)) LineSearch AD: $(_nameof(ad))" for ad in (
AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()
),
linesearch in (
Static(; autodiff = ad), StrongWolfe(; autodiff = ad),
BackTracking(; autodiff = ad), LineSearch.BackTracking(; autodiff = ad),
HagerZhang(; autodiff = ad), MoreThuente(; autodiff = ad)
)

linesearch = LineSearchesJL(; method = lsmethod, autodiff = ad)
u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)

@testset "[OOP] u0: $(typeof(u0))" for u0 in u0s
Expand Down Expand Up @@ -463,14 +467,17 @@ end
# --- Broyden tests ---

@testitem "Broyden" setup=[CoreRootfindTesting] tags=[:core] begin
@testset "LineSearch: $(_nameof(lsmethod)) LineSearch AD: $(_nameof(ad)) Init Jacobian: $(init_jacobian) Update Rule: $(update_rule)" for lsmethod in (
Static(), StrongWolfe(), BackTracking(),
HagerZhang(), MoreThuente(), LiFukushimaLineSearch()),
ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()),
@testset "LineSearch: $(_nameof(linesearch)) LineSearch AD: $(_nameof(ad)) Init Jacobian: $(init_jacobian) Update Rule: $(update_rule)" for ad in (
AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()
),
linesearch in (
Static(; autodiff = ad), StrongWolfe(; autodiff = ad),
BackTracking(; autodiff = ad), LineSearch.BackTracking(; autodiff = ad),
HagerZhang(; autodiff = ad), MoreThuente(; autodiff = ad)
),
init_jacobian in (Val(:identity), Val(:true_jacobian)),
update_rule in (Val(:good_broyden), Val(:bad_broyden), Val(:diagonal))

linesearch = LineSearchesJL(; method = lsmethod, autodiff = ad)
u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)

@testset "[OOP] u0: $(typeof(u0))" for u0 in u0s
Expand Down Expand Up @@ -513,12 +520,16 @@ end
# --- Klement tests ---

@testitem "Klement" setup=[CoreRootfindTesting] tags=[:core] begin
@testset "LineSearch: $(_nameof(lsmethod)) LineSearch AD: $(_nameof(ad)) Init Jacobian: $(init_jacobian)" for lsmethod in (
Static(), StrongWolfe(), BackTracking(), HagerZhang(), MoreThuente()),
ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()),
@testset "LineSearch: $(_nameof(linesearch)) LineSearch AD: $(_nameof(ad)) Init Jacobian: $(init_jacobian)" for ad in (
AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()
),
linesearch in (
Static(; autodiff = ad), StrongWolfe(; autodiff = ad),
BackTracking(; autodiff = ad), LineSearch.BackTracking(; autodiff = ad),
HagerZhang(; autodiff = ad), MoreThuente(; autodiff = ad)
),
init_jacobian in (Val(:identity), Val(:true_jacobian), Val(:true_jacobian_diagonal))

linesearch = LineSearchesJL(; method = lsmethod, autodiff = ad)
u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)

@testset "[OOP] u0: $(typeof(u0))" for u0 in u0s
Expand Down Expand Up @@ -562,31 +573,39 @@ end
# --- LimitedMemoryBroyden tests ---

@testitem "LimitedMemoryBroyden" setup=[CoreRootfindTesting] tags=[:core] begin
@testset "LineSearch: $(_nameof(lsmethod)) LineSearch AD: $(_nameof(ad))" for lsmethod in (
Static(), StrongWolfe(), BackTracking(),
HagerZhang(), MoreThuente(), LiFukushimaLineSearch()),
ad in (AutoForwardDiff(), AutoZygote(), AutoFiniteDiff())
@testset "LineSearch: $(_nameof(linesearch)) LineSearch AD: $(_nameof(ad))" for ad in (
AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()
),
linesearch in (
Static(; autodiff = ad), StrongWolfe(; autodiff = ad),
BackTracking(; autodiff = ad), LineSearch.BackTracking(; autodiff = ad),
HagerZhang(; autodiff = ad), MoreThuente(; autodiff = ad),
LiFukushimaLineSearch()
)

linesearch = LineSearchesJL(; method = lsmethod, autodiff = ad)
u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)

@testset "[OOP] u0: $(typeof(u0))" for u0 in u0s
broken = linesearch isa BackTracking && ad isa AutoFiniteDiff && u0 isa Vector

solver = LimitedMemoryBroyden(; linesearch)
sol = benchmark_nlsolve_oop(quadratic_f, u0; solver)
@test SciMLBase.successful_retcode(sol)
@test all(abs.(sol.u .* sol.u .- 2) .< 1e-9)
@test SciMLBase.successful_retcode(sol) broken=broken
@test all(abs.(sol.u .* sol.u .- 2) .< 1e-9) broken=broken

cache = init(NonlinearProblem{false}(quadratic_f, u0, 2.0),
LimitedMemoryBroyden(; linesearch), abstol = 1e-9)
@test (@ballocated solve!($cache)) < 200
end

@testset "[IIP] u0: $(typeof(u0))" for u0 in ([1.0, 1.0],)
broken = linesearch isa BackTracking && ad isa AutoFiniteDiff && u0 isa Vector
ad isa AutoZygote && continue

solver = LimitedMemoryBroyden(; linesearch)
sol = benchmark_nlsolve_iip(quadratic_f!, u0; solver)
@test SciMLBase.successful_retcode(sol)
@test all(abs.(sol.u .* sol.u .- 2) .< 1e-9)
@test SciMLBase.successful_retcode(sol) broken=broken
@test all(abs.(sol.u .* sol.u .- 2) .< 1e-9) broken=broken

cache = init(NonlinearProblem{true}(quadratic_f!, u0, 2.0),
LimitedMemoryBroyden(; linesearch), abstol = 1e-9)
Expand Down
Loading