From ca788528b7046163100b1821f16907721c98c9f5 Mon Sep 17 00:00:00 2001 From: Herman Sletmoen Date: Wed, 8 Jan 2025 17:39:46 +0100 Subject: [PATCH] Format --- src/debugging.jl | 14 +++++++++----- src/systems/abstractsystem.jl | 3 ++- test/odesystem.jl | 8 +++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/debugging.jl b/src/debugging.jl index f6652183cb..a1a168d8dd 100644 --- a/src/debugging.jl +++ b/src/debugging.jl @@ -6,10 +6,12 @@ struct LoggedFun{F} args::Any error_nonfinite::Bool end -LoggedFunctionException(lf::LoggedFun, args, msg) = LoggedFunctionException( - "Function $(lf.f)($(join(lf.args, ", "))) " * msg * " with input" * - join("\n " .* string.(lf.args .=> args)) # one line for each "var => val" for readability -) +function LoggedFunctionException(lf::LoggedFun, args, msg) + LoggedFunctionException( + "Function $(lf.f)($(join(lf.args, ", "))) " * msg * " with input" * + join("\n " .* string.(lf.args .=> args)) # one line for each "var => val" for readability + ) +end Base.showerror(io::IO, err::LoggedFunctionException) = print(io, err.msg) Base.nameof(lf::LoggedFun) = nameof(lf.f) SymbolicUtils.promote_symtype(::LoggedFun, Ts...) = Real @@ -30,7 +32,9 @@ function logged_fun(f, args...; error_nonfinite = true) # remember to update err term(LoggedFun(f, args, error_nonfinite), args..., type = Real) end -debug_sub(eq::Equation, funcs; kw...) = debug_sub(eq.lhs, funcs; kw...) ~ debug_sub(eq.rhs, funcs; kw...) +function debug_sub(eq::Equation, funcs; kw...) + debug_sub(eq.lhs, funcs; kw...) ~ debug_sub(eq.rhs, funcs; kw...) +end function debug_sub(ex, funcs; kw...) iscall(ex) || return ex f = operation(ex) diff --git a/src/systems/abstractsystem.jl b/src/systems/abstractsystem.jl index 796ff73eba..e6c07bcf9c 100644 --- a/src/systems/abstractsystem.jl +++ b/src/systems/abstractsystem.jl @@ -2278,7 +2278,8 @@ ERROR: Function /(1, sin(P(t))) output non-finite value Inf with input sin(P(t)) => 0.0 ``` """ -function debug_system(sys::AbstractSystem; functions = [log, sqrt, (^), /, inv, asin, acos], kw...) +function debug_system( + sys::AbstractSystem; functions = [log, sqrt, (^), /, inv, asin, acos], kw...) if !(functions isa Set) functions = Set(functions) # more efficient "in" lookup end diff --git a/test/odesystem.jl b/test/odesystem.jl index cc2fe89ff3..94f676461b 100644 --- a/test/odesystem.jl +++ b/test/odesystem.jl @@ -931,11 +931,9 @@ testdict = Dict([:name => "test"]) @named sys = ODESystem(eqs, t, metadata = testdict) @test get_metadata(sys) == testdict -@variables P(t) = NaN Q(t) = NaN -@named sys = ODESystem([ - D(Q) ~ 1 / sin(P) - D(P) ~ log(-cos(Q)) -], t, [P, Q], []) +@variables P(t)=NaN Q(t)=NaN +eqs = [D(Q) ~ 1 / sin(P), D(P) ~ log(-cos(Q))] +@named sys = ODESystem(eqs, t, [P, Q], []) sys = complete(debug_system(sys)) prob = ODEProblem(sys, [], (0.0, 1.0)) @test_throws "log(-cos(Q(t))) errors" prob.f([1, 0], prob.p, 0.0)