Skip to content

Commit aa4d713

Browse files
committed
add check for Bool verbose
1 parent 764550d commit aa4d713

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

src/integrator_interface.jl

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -612,14 +612,23 @@ function check_error(integrator::DEIntegrator)
612612
verbose = opts.verbose
613613
# This implementation is intended to be used for ODEIntegrator and
614614
# SDEIntegrator.
615+
615616
if isnan(integrator.dt)
616-
@SciMLMessage("NaN dt detected. Likely a NaN value in the state, parameters, or derivative value caused this outcome.", verbose, :dt_NaN)
617+
if verbose isa Bool
618+
@warn "NaN dt detected. Likely a NaN value in the state, parameters, or derivative value caused this outcome."
619+
else
620+
@SciMLMessage("NaN dt detected. Likely a NaN value in the state, parameters, or derivative value caused this outcome.", verbose, :dt_NaN)
621+
end
617622
return ReturnCode.DtNaN
618623
end
619624
if integrator.iter > opts.maxiters
620-
@SciMLMessage("Interrupted. Larger maxiters is needed. If you are using an integrator for non-stiff ODEs or an automatic switching algorithm (the default), you may want to consider using a method for stiff equations. See the solver pages for more details (e.g. https://docs.sciml.ai/DiffEqDocs/stable/solvers/ode_solve/#Stiff-Problems).",
625+
if verbose isa Bool
626+
@warn "Interrupted. Larger maxiters is needed. If you are using an integrator for non-stiff ODEs or an automatic switching algorithm (the default), you may want to consider using a method for stiff equations. See the solver pages for more details (e.g. https://docs.sciml.ai/DiffEqDocs/stable/solvers/ode_solve/#Stiff-Problems)."
627+
else
628+
@SciMLMessage("Interrupted. Larger maxiters is needed. If you are using an integrator for non-stiff ODEs or an automatic switching algorithm (the default), you may want to consider using a method for stiff equations. See the solver pages for more details (e.g. https://docs.sciml.ai/DiffEqDocs/stable/solvers/ode_solve/#Stiff-Problems).",
621629
verbose,
622630
:max_iters)
631+
end
623632
return ReturnCode.MaxIters
624633
end
625634

@@ -635,36 +644,61 @@ function check_error(integrator::DEIntegrator)
635644
(!step_accepted || (hasproperty(opts, :tstops) ?
636645
integrator.t + integrator.dt < integrator.tdir * first(opts.tstops) :
637646
true))
638-
@SciMLMessage(verbose, :dt_min_unstable) do
647+
if verbose isa Bool
639648
if isdefined(integrator, :EEst)
640649
EEst = ", and step error estimate = $(integrator.EEst)"
641650
else
642651
EEst = ""
643652
end
644-
"dt($(integrator.dt)) <= dtmin($(opts.dtmin)) at t=$(integrator.t)$EEst. Aborting. There is either an error in your model specification or the true solution is unstable."
645-
end
653+
@warn "dt($(integrator.dt)) <= dtmin($(opts.dtmin)) at t=$(integrator.t)$EEst. Aborting. There is either an error in your model specification or the true solution is unstable."
654+
else
655+
@SciMLMessage(verbose, :dt_min_unstable) do
656+
if isdefined(integrator, :EEst)
657+
EEst = ", and step error estimate = $(integrator.EEst)"
658+
else
659+
EEst = ""
660+
end
661+
"dt($(integrator.dt)) <= dtmin($(opts.dtmin)) at t=$(integrator.t)$EEst. Aborting. There is either an error in your model specification or the true solution is unstable."
662+
end
663+
end
646664
return ReturnCode.DtLessThanMin
647665
elseif !step_accepted && integrator.t isa AbstractFloat &&
648666
abs(integrator.dt) <= abs(eps(integrator.t))
649-
650-
@SciMLMessage(verbose, :dt_epsilon) do
667+
if verbose isa Bool
651668
if isdefined(integrator, :EEst)
652669
EEst = ", and step error estimate = $(integrator.EEst)"
653670
else
654671
EEst = ""
655672
end
656-
"At t=$(integrator.t), dt was forced below floating point epsilon $(integrator.dt)$EEst. Aborting. There is either an error in your model specification or the true solution is unstable (or the true solution can not be represented in the precision of $(eltype(integrator.u)))."
673+
@warn "At t=$(integrator.t), dt was forced below floating point epsilon $(integrator.dt)$EEst. Aborting. There is either an error in your model specification or the true solution is unstable (or the true solution can not be represented in the precision of $(eltype(integrator.u)))."
674+
else
675+
@SciMLMessage(verbose, :dt_epsilon) do
676+
if isdefined(integrator, :EEst)
677+
EEst = ", and step error estimate = $(integrator.EEst)"
678+
else
679+
EEst = ""
680+
end
681+
"At t=$(integrator.t), dt was forced below floating point epsilon $(integrator.dt)$EEst. Aborting. There is either an error in your model specification or the true solution is unstable (or the true solution can not be represented in the precision of $(eltype(integrator.u)))."
682+
end
657683
end
658684
return ReturnCode.Unstable
659685
end
660686
end
661687
if step_accepted &&
662688
opts.unstable_check(integrator.dt, integrator.u, integrator.p, integrator.t)
663-
@SciMLMessage("Instability detected. Aborting", verbose, :instability)
689+
if verbose isa Bool
690+
@warn "Instability detected. Aborting"
691+
else
692+
@SciMLMessage("Instability detected. Aborting", verbose, :instability)
693+
end
664694
return ReturnCode.Unstable
665695
end
666696
if last_step_failed(integrator)
667-
@SciMLMessage("Newton steps could not converge and algorithm is not adaptive. Use a lower dt.", verbose, :newton_convergence)
697+
if verbose isa Bool
698+
@warn "Newton steps could not converge and algorithm is not adaptive. Use a lower dt."
699+
else
700+
@SciMLMessage("Newton steps could not converge and algorithm is not adaptive. Use a lower dt.", verbose, :newton_convergence)
701+
end
668702
return ReturnCode.ConvergenceFailure
669703
end
670704
return ReturnCode.Success

0 commit comments

Comments
 (0)