@@ -60,7 +60,8 @@ residual cost from one evaluation per subalgorithm to one per subalgorithm actua
6060attempted (usually just the retained one). A consequence is that the shared `stats`
6161of a solution produced after mid-solve escalation only reflect the subalgorithms run
6262since the last deferred reinitialization, i.e. effectively the winning subalgorithm's
63- own effort.
63+ own effort. Updating solver options in the same `reinit!` eagerly updates every
64+ subcache so that later escalation observes the new values.
6465"""
6566@concrete struct NonlinearSolvePolyAlgorithm <: AbstractNonlinearSolveAlgorithm
6667 static_length <: Val
@@ -175,7 +176,7 @@ const RETAIN_REPROBE_INTERVAL = 8
175176
176177function InternalAPI. reinit! (
177178 cache:: NonlinearSolvePolyAlgorithmCache , args... ; p = cache. prob. p, u0 = cache. u0,
178- retain_best:: Bool = false
179+ retain_best:: Bool = false , kwargs ...
179180 )
180181 cache. retain_best = retain_best
181182 cache. retain_count = retain_best ? cache. retain_count + 1 : 0
@@ -186,19 +187,21 @@ function InternalAPI.reinit!(
186187 cache. start_current = cache. current
187188 cache. wrapped = false
188189 if retain_best
190+ cache. deferred_u0 = u0
191+ cache. deferred_p = p
192+ end
193+ if retain_best && isempty (kwargs)
189194 # Lazy subcache reinitialization: every subcache `reinit!` evaluates the
190195 # residual at the new `u0` (`Utils.reinit_common!`), so eagerly
191196 # reinitializing all N subcaches costs N residual calls per warm-started
192197 # solve even though a retained solve usually runs only the starting
193198 # subalgorithm. Reinitialize just that one here and defer the rest to the
194199 # moment escalation actually reaches them (`deferred_subcache_reinit!`).
195- cache. deferred_u0 = u0
196- cache. deferred_p = p
197200 subcache = cache. caches[cache. current]
198- InternalAPI. reinit! (subcache, args... ; u = get_u (subcache), p, u0)
201+ InternalAPI. reinit! (subcache, args... ; u = get_u (subcache), p, u0, kwargs ... )
199202 else
200203 foreach (cache. caches) do cache
201- InternalAPI. reinit! (cache, args... ; u = get_u (cache), p, u0)
204+ InternalAPI. reinit! (cache, args... ; u = get_u (cache), p, u0, kwargs ... )
202205 end
203206 end
204207 InternalAPI. reinit! (cache. stats)
@@ -225,6 +228,10 @@ reinit_retaining!(cache, u0) = SciMLBase.reinit!(cache, u0)
225228function reinit_retaining! (cache:: NonlinearSolvePolyAlgorithmCache , u0)
226229 return SciMLBase. reinit! (cache, u0; retain_best = true )
227230end
231+ reinit_retaining! (cache, u0, p) = SciMLBase. reinit! (cache, u0; p)
232+ function reinit_retaining! (cache:: NonlinearSolvePolyAlgorithmCache , u0, p)
233+ return SciMLBase. reinit! (cache, u0; p, retain_best = true )
234+ end
228235
229236function SciMLBase. __init (
230237 prob:: AbstractNonlinearProblem , alg:: NonlinearSolvePolyAlgorithm , args... ;
0 commit comments