Skip to content

Commit a0ea689

Browse files
committed
Fail with grace with the ILS after initialization failure
1 parent 63efb70 commit a0ea689

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/saving.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,10 @@ function LinearizingSavingCallback(ils::IndependentlyLinearizedSolution{T,S};
433433
end,
434434
# We need to finalize the ils and free our caches
435435
finalize = (c, u, t, integ) -> begin
436-
finish!(ils)
436+
# Don't run the `finish!` if ils is in an inconsistent state
437+
if check_error(integ) != ReturnCode.InitialFailure
438+
finish!(ils)
439+
end
437440
caches = nothing
438441
end,
439442
# Don't add tstops to the left and right.

test/saving_tests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,22 @@ if VERSION >= v"1.9" # stack
220220
end
221221
end
222222

223+
224+
@testset "fail gracefully" begin
225+
f_error2(du, u, p, t) = du .= u ./ t .- 1
226+
u0 = [1.0];
227+
du0 = [1.0];
228+
prob = DAEProblem(f_error2, u0, du0, (0.0, 1.0); differential_vars = [true])
229+
ils = IndependentlyLinearizedSolution(unstable_prob, 0)
230+
lsc = LinearizingSavingCallback(ils)
231+
sol = solve(prob, DFBDF(); callback = lsc) # this would if we were not failing with grace
232+
@test sol.retcode == ReturnCode.InitialFailure
233+
@test isempty(ils.ts)
234+
@test isempty(ils.us)
235+
@test isempty(ils.time_mask)
236+
end
237+
238+
223239
# We do not support 2d states yet.
224240
#test_linearization(prob_ode_2Dlinear, Tsit5())
225241
end

0 commit comments

Comments
 (0)