Skip to content

DRAFT: use the SciML verbosity system #2726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ using DiffEqBase: check_error!, @def, _vec, _reshape
using FastBroadcast: @.., True, False

using SciMLBase: NoInit, CheckInit, OverrideInit, AbstractDEProblem, _unwrap_val,
ODEAliasSpecifier
ODEAliasSpecifier, @SciMLMessage, ODEVerbosity, Verbosity

import SciMLBase: AbstractNonlinearProblem, alg_order, LinearAliasSpecifier

Expand Down
4 changes: 4 additions & 0 deletions lib/OrdinaryDiffEqCore/src/composite_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ function (AS::AutoSwitchCache)(integrator)
if (!AS.is_stiffalg && AS.count > AS.maxstiffstep)
integrator.dt = dt * AS.dtfac
AS.is_stiffalg = true
SciMLBase.@SciMLMessage("Algorithm was switched to $(nameof(typeof(integrator.alg.algs[Int(AS.current) + 1]))) at t = $(integrator.t).",
integrator.opts.verbose, :alg_switch, :performance)
elseif (AS.is_stiffalg && AS.count < -AS.maxnonstiffstep)
integrator.dt = dt / AS.dtfac
SciMLBase.@SciMLMessage("Algorithm was switched to $(nameof(typeof(integrator.alg.algs[1]))) at t = $(integrator.t).",
integrator.opts.verbose, :alg_switch, :performance)
AS.is_stiffalg = false
end
AS.current = Int(AS.is_stiffalg) + 1
Expand Down
11 changes: 6 additions & 5 deletions lib/OrdinaryDiffEqCore/src/initdt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@
# because it also checks if partials are NaN
# https://discourse.julialang.org/t/incorporating-forcing-functions-in-the-ode-model/70133/26
if isnan(d₁)
if integrator.opts.verbose
@warn("First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.")
end
@SciMLMessage("First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.",
integrator.opts.verbose, :init_NaN, :error_control)

return tdir * dtmin
end
Expand Down Expand Up @@ -249,8 +248,10 @@ end
d₀ = internalnorm(u0 ./ sk, t)

f₀ = f(u0, p, t)
if integrator.opts.verbose && any(x -> any(isnan, x), f₀)
@warn("First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.")

if any(x -> any(isnan, x), f₀)
@SciMLMessage("First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.",
integrator.opts.verbose, :init_NaN, :error_control)
end

inferredtype = Base.promote_op(/, typeof(u0), typeof(oneunit(t)))
Expand Down
2 changes: 1 addition & 1 deletion lib/OrdinaryDiffEqCore/src/integrators/type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mutable struct DEOptions{absType, relType, QT, tType, Controller, F1, F2, F3, F4
callback::F4
isoutofdomain::F5
unstable_check::F7
verbose::Bool
verbose::ODEVerbosity
calck::Bool
force_dtmin::Bool
advance_to_tstop::Bool
Expand Down
15 changes: 8 additions & 7 deletions lib/OrdinaryDiffEqCore/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function DiffEqBase.__init(
internalopnorm = LinearAlgebra.opnorm,
isoutofdomain = ODE_DEFAULT_ISOUTOFDOMAIN,
unstable_check = ODE_DEFAULT_UNSTABLE_CHECK,
verbose = true,
verbose = ODEVerbosity(Verbosity.Default()),
timeseries_errors = true,
dense_errors = false,
advance_to_tstop = false,
Expand Down Expand Up @@ -102,8 +102,9 @@ function DiffEqBase.__init(
prob.f.mass_matrix isa AbstractMatrix &&
all(isequal(0), prob.f.mass_matrix)
# technically this should also warn for zero operators but those are hard to check for
if (dense || !isempty(saveat)) && verbose
@warn("Rosenbrock methods on equations without differential states do not bound the error on interpolations.")
if (dense || !isempty(saveat))
@SciMLMessage("Rosenbrock methods on equations without differential states do not bound the error on interpolations.",
verbose, :rosenbrock_no_differential_states, :error_control)
end
end

Expand All @@ -114,7 +115,8 @@ function DiffEqBase.__init(
end

if !isempty(saveat) && dense
@warn("Dense output is incompatible with saveat. Please use the SavingCallback from the Callback Library to mix the two behaviors.")
@SciMLMessage("Dense output is incompatible with saveat. Please use the SavingCallback from the Callback Library to mix the two behaviors.",
verbose, :dense_output_saveat, :error_control)
end

progress && @logmsg(LogLevel(-1), progress_name, _id=progress_id, progress=0)
Expand Down Expand Up @@ -650,9 +652,8 @@ function handle_dt!(integrator)
error("Automatic dt setting has the wrong sign. Exiting. Please report this error.")
end
if isnan(integrator.dt)
if integrator.opts.verbose
@warn("Automatic dt set the starting dt as NaN, causing instability. Exiting.")
end
@SciMLMessage("Automatic dt set the starting dt as NaN, causing instability. Exiting.",
integrator.opts.verbose, :dt_NaN, :error_control)b
end
elseif integrator.opts.adaptive && integrator.dt > zero(integrator.dt) &&
integrator.tdir < 0
Expand Down
Loading