|
114 | 114 | retcode::ReturnCode.T |
115 | 115 | force_stop::Bool |
116 | 116 | force_reinit::Bool |
| 117 | + kwargs |
117 | 118 | end |
118 | 119 |
|
119 | 120 | store_inverse_jacobian(::ApproximateJacobianSolveCache{INV}) where {INV} = INV |
@@ -211,10 +212,10 @@ function SciMLBase.__init( |
211 | 212 |
|
212 | 213 | return ApproximateJacobianSolveCache{INV, GB, iip, maxtime !== nothing}( |
213 | 214 | fu, u, u_cache, p, du, J, alg, prob, initialization_cache, |
214 | | - descent_cache, linesearch_cache, trustregion_cache, |
215 | | - update_rule_cache, reinit_rule_cache, inv_workspace, 0, 0, 0, |
216 | | - alg.max_resets, maxiters, maxtime, alg.max_shrink_times, 0, timer, |
217 | | - 0.0, termination_cache, trace, ReturnCode.Default, false, false) |
| 215 | + descent_cache, linesearch_cache, trustregion_cache, update_rule_cache, |
| 216 | + reinit_rule_cache, inv_workspace, 0, 0, 0, alg.max_resets, |
| 217 | + maxiters, maxtime, alg.max_shrink_times, 0, timer, 0.0, |
| 218 | + termination_cache, trace, ReturnCode.Default, false, false, kwargs) |
218 | 219 | end |
219 | 220 | end |
220 | 221 |
|
@@ -282,16 +283,38 @@ function __step!(cache::ApproximateJacobianSolveCache{INV, GB, iip}; |
282 | 283 | @static_timeit cache.timer "descent" begin |
283 | 284 | if cache.trustregion_cache !== nothing && |
284 | 285 | hasfield(typeof(cache.trustregion_cache), :trust_region) |
285 | | - δu, descent_success, descent_intermediates = __internal_solve!( |
| 286 | + descent_result = __internal_solve!( |
286 | 287 | cache.descent_cache, J, cache.fu, cache.u; new_jacobian, |
287 | | - trust_region = cache.trustregion_cache.trust_region) |
| 288 | + trust_region = cache.trustregion_cache.trust_region, cache.kwargs...) |
288 | 289 | else |
289 | | - δu, descent_success, descent_intermediates = __internal_solve!( |
290 | | - cache.descent_cache, J, cache.fu, cache.u; new_jacobian) |
| 290 | + descent_result = __internal_solve!( |
| 291 | + cache.descent_cache, J, cache.fu, cache.u; new_jacobian, cache.kwargs...) |
291 | 292 | end |
292 | 293 | end |
293 | 294 |
|
294 | | - if descent_success |
| 295 | + if !descent_result.linsolve_success |
| 296 | + if new_jacobian && cache.steps_since_last_reset == 0 |
| 297 | + # Extremely pathological case. Jacobian was just reset and linear solve |
| 298 | + # failed. Should ideally never happen in practice unless true jacobian init |
| 299 | + # is used. |
| 300 | + cache.retcode = LinearSolveFailureCode |
| 301 | + cache.force_stop = true |
| 302 | + return |
| 303 | + else |
| 304 | + # Force a reinit because the problem is currently un-solvable |
| 305 | + if !haskey(cache.kwargs, :verbose) || cache.kwargs[:verbose] |
| 306 | + @warn "Linear Solve Failed but Jacobian Information is not current. \ |
| 307 | + Retrying with reinitialized Approximate Jacobian." |
| 308 | + end |
| 309 | + cache.force_reinit = true |
| 310 | + __step!(cache; recompute_jacobian = true) |
| 311 | + return |
| 312 | + end |
| 313 | + end |
| 314 | + |
| 315 | + δu, descent_intermediates = descent_result.δu, descent_result.extras |
| 316 | + |
| 317 | + if descent_result.success |
295 | 318 | if GB === :LineSearch |
296 | 319 | @static_timeit cache.timer "linesearch" begin |
297 | 320 | needs_reset, α = __internal_solve!(cache.linesearch_cache, cache.u, δu) |
|
0 commit comments