Skip to content

Commit 81450a1

Browse files
Add reusable homotopy solver caches (#1100)
* Eliminate dense continuation step allocations Avoid temporary reshape wrappers for dense AutoForwardDiff Jacobians and same-buffer restructure calls, with direct warmed allocation regressions. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> * Cache ForwardDiff Jacobian destinations Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> * Avoid per-step continuation solution allocations Run reusable continuation correctors to completion without materializing a solution on every step, while retaining full solution construction for custom, bounded, and wrapper caches. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> * Add reusable homotopy solver caches Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> * Add allocation-free nonlinear cache driver Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> * Guard the cache driver iterator contract Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> --------- Co-authored-by: ChrisRackauckas-Claude <accounts@chrisrackauckas.com>
1 parent 43fc81a commit 81450a1

23 files changed

Lines changed: 554 additions & 119 deletions

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "NonlinearSolve"
22
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
3-
version = "4.23.2"
3+
version = "4.24.0"
44
authors = ["SciML"]
55

66
[deps]
@@ -98,7 +98,7 @@ NLSolvers = "0.5"
9898
NLsolve = "4.5"
9999
NaNMath = "1"
100100
NonlinearProblemLibrary = "0.1.2"
101-
NonlinearSolveBase = "2.37"
101+
NonlinearSolveBase = "2.40"
102102
NonlinearSolveFirstOrder = "2"
103103
NonlinearSolveQuasiNewton = "1.12"
104104
NonlinearSolveSpectralMethods = "1.6"

docs/src/devdocs/algorithm_helpers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ NonlinearSolveFirstOrder.GenericTrustRegionScheme
6262
```@docs
6363
NonlinearSolveBase.callback_into_cache!
6464
NonlinearSolveBase.concrete_jac
65+
NonlinearSolveBase.solve_cache!
6566
NonlinearSolveBase.assert_extension_supported_termination_condition
6667
NonlinearSolveBase.construct_extension_function_wrapper
6768
NonlinearSolveBase.construct_extension_jac

lib/NonlinearSolveBase/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "NonlinearSolveBase"
22
uuid = "be0214bd-f91f-a760-ac4e-3421ce2b2da0"
3-
version = "2.39.0"
3+
version = "2.40.0"
44
authors = ["Avik Pal <avikpal@mit.edu> and contributors"]
55

66
[deps]

lib/NonlinearSolveBase/src/NonlinearSolveBase.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ include("solve.jl")
106106
include("forward_diff.jl")
107107

108108
# Unexported Public API
109-
@compat(public, (L2_NORM, Linf_NORM, NAN_CHECK, UNITLESS_ABS2, get_tolerance))
109+
@compat(
110+
public,
111+
(L2_NORM, Linf_NORM, NAN_CHECK, UNITLESS_ABS2, get_tolerance, solve_cache!)
112+
)
110113

111114
@compat(public, (get_abstol, get_reltol))
112115
@compat(public, (AbstractNonlinearTerminationMode, AbstractSafeNonlinearTerminationMode))

lib/NonlinearSolveBase/src/arclength.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,10 @@ function CommonSolve.solve(
829829
# and discovers the winner) instead of re-failing the cheaper ladder members
830830
# on every warm-started step.
831831
reinit_retaining!(corr_cache, xpred)
832-
last_sol = CommonSolve.solve!(corr_cache)
832+
last_sol = _solve_without_solution!(corr_cache)
833833

834-
if SciMLBase.successful_retcode(last_sol)
835-
xnew = last_sol.u
834+
if _solve_result_successful(last_sol)
835+
xnew = _solve_result_u(last_sol)
836836
# realized chord, built in the (currently free) secant scratch
837837
@. tscratch = xnew - xcur
838838
nchord = _theta_norm(tscratch, wu, wλ, n)
@@ -892,7 +892,8 @@ function CommonSolve.solve(
892892
# sweep — see `_effort_growth_factor`), giving the arclength driver an effort
893893
# signal alongside the purely geometric bend-angle test.
894894
if alg.adaptive
895-
nit = last_sol.stats === nothing ? -1 : Int(last_sol.stats.nsteps)
895+
result_stats = _solve_result_stats(last_sol)
896+
nit = result_stats === nothing ? -1 : Int(result_stats.nsteps)
896897
if _effort_wants_shrink(nit, budget)
897898
ds / 2 >= min_ds && (ds = ds / 2)
898899
streak = 0
@@ -913,7 +914,8 @@ function CommonSolve.solve(
913914
else
914915
return build_solution_less_specialize(
915916
prob, alg, u, nothing;
916-
retcode = last_sol.retcode, original = last_sol,
917+
retcode = _solve_result_retcode(last_sol),
918+
original = _solve_result_original(last_sol),
917919
store_original = alg.store_original
918920
)
919921
end

lib/NonlinearSolveBase/src/forward_diff.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ get_u(cache::NonlinearSolveForwardDiffCache) = get_u(cache.cache)
1111
get_fu(cache::NonlinearSolveForwardDiffCache) = get_fu(cache.cache)
1212
set_fu!(cache::NonlinearSolveForwardDiffCache, fu) = set_fu!(cache.cache, fu)
1313
SciMLBase.set_u!(cache::NonlinearSolveForwardDiffCache, u) = SciMLBase.set_u!(cache.cache, u)
14+
function _solve_without_solution!(cache::NonlinearSolveForwardDiffCache)
15+
return CommonSolve.solve!(cache)
16+
end
1417
function NonlinearSolveBase.get_abstol(cache::NonlinearSolveForwardDiffCache)
1518
return NonlinearSolveBase.get_abstol(cache.cache)
1619
end

0 commit comments

Comments
 (0)