Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
hersle committed Jan 8, 2025
1 parent 94576db commit ca78852
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/debugging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ca78852

Please sign in to comment.