Skip to content

Commit a8b78be

Browse files
refactor: check if algorithm supports late binding tstops
1 parent b52cf18 commit a8b78be

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/solve.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,19 @@ function Base.showerror(io::IO, e::IncompatibleMassMatrixError)
500500
println(io, TruncatedStacktraces.VERBOSE_MSG)
501501
end
502502

503+
const LATE_BINDING_TSTOPS_ERROR_MESSAGE = """
504+
This solver does not support providing `tstops` as a function.
505+
Consider using a different solver or providing `tstops` as an array
506+
of times.
507+
"""
508+
509+
struct LateBindingTstopsNotSupportedError <: Exception end
510+
511+
function Base.showerror(io::IO, e::LateBindingTstopsNotSupportedError)
512+
println(io, LATE_BINDING_TSTOPS_ERROR_MESSAGE)
513+
println(io, TruncatedStacktraces.VERBOSE_MSG)
514+
end
515+
503516
function init_call(_prob, args...; merge_callbacks = true, kwargshandle = nothing,
504517
kwargs...)
505518
kwargshandle = kwargshandle === nothing ? KeywordArgError : kwargshandle
@@ -555,6 +568,13 @@ function init_up(prob::AbstractDEProblem, sensealg, u0, p, args...; kwargs...)
555568
p = p, kwargs...)
556569
init_call(_prob, args...; kwargs...)
557570
else
571+
tstops = get(kwargs, :tstops, nothing)
572+
if tstops === nothing && has_kwargs(prob)
573+
tstops = get(prob.kwargs, :tstops, nothing)
574+
end
575+
if !(tstops isa Union{Nothing, AbstractArray, Tuple}) && !SciMLBase.allows_late_binding_tstops(alg)
576+
throw(LateBindingTstopsNotSupportedError())
577+
end
558578
_prob = get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
559579
_alg = prepare_alg(alg, _prob.u0, _prob.p, _prob)
560580
check_prob_alg_pairing(_prob, alg) # alg for improved inference
@@ -1084,6 +1104,13 @@ function solve_up(prob::Union{AbstractDEProblem, NonlinearProblem}, sensealg, u0
10841104
p = p, kwargs...)
10851105
solve_call(_prob, args...; kwargs...)
10861106
else
1107+
tstops = get(kwargs, :tstops, nothing)
1108+
if tstops === nothing && has_kwargs(prob)
1109+
tstops = get(prob.kwargs, :tstops, nothing)
1110+
end
1111+
if !(tstops isa Union{Nothing, AbstractArray, Tuple}) && !SciMLBase.allows_late_binding_tstops(alg)
1112+
throw(LateBindingTstopsNotSupportedError())
1113+
end
10871114
_prob = get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
10881115
_alg = prepare_alg(alg, _prob.u0, _prob.p, _prob)
10891116
check_prob_alg_pairing(_prob, alg) # use alg for improved inference

0 commit comments

Comments
 (0)