@@ -2260,11 +2260,11 @@ macro mtkbuild(exprs...)
22602260end
22612261
22622262"""
2263- debug_system(sys::AbstractSystem; error_nonfinite = true)
2263+ debug_system(sys::AbstractSystem; functions = [log, sqrt, (^), /, inv, asin, acos], error_nonfinite = true)
22642264
2265- Replace functions with singularities with a function that errors with symbolic
2266- information. If `error_nonfinite`, debugged functions that output nonfinite values
2267- (like `Inf` or `NaN`) also display errors, even though the raw function itself
2265+ Wrap ` functions` in `sys` so any error thrown in them shows helpful symbolic-numeric
2266+ information about its input . If `error_nonfinite`, functions that output nonfinite
2267+ values (like `Inf` or `NaN`) also display errors, even though the raw function itself
22682268does not throw an exception (like `1/0`). For example:
22692269
22702270```julia-repl
@@ -2278,15 +2278,18 @@ ERROR: Function /(1, sin(P(t))) output non-finite value Inf with input
22782278 sin(P(t)) => 0.0
22792279```
22802280"""
2281- function debug_system (sys:: AbstractSystem ; kw... )
2281+ function debug_system (sys:: AbstractSystem ; functions = [log, sqrt, (^ ), / , inv, asin, acos], kw... )
2282+ if ! (functions isa Set)
2283+ functions = Set (functions) # more efficient "in" lookup
2284+ end
22822285 if has_systems (sys) && ! isempty (get_systems (sys))
22832286 error (" debug_system(sys) only works on systems with no sub-systems! Consider flattening it with flatten(sys) or structural_simplify(sys) first." )
22842287 end
22852288 if has_eqs (sys)
2286- @set! sys. eqs = debug_sub .(equations (sys); kw... )
2289+ @set! sys. eqs = debug_sub .(equations (sys), Ref (functions) ; kw... )
22872290 end
22882291 if has_observed (sys)
2289- @set! sys. observed = debug_sub .(observed (sys); kw... )
2292+ @set! sys. observed = debug_sub .(observed (sys), Ref (functions) ; kw... )
22902293 end
22912294 return sys
22922295end
0 commit comments