@@ -2260,11 +2260,11 @@ macro mtkbuild(exprs...)
2260
2260
end
2261
2261
2262
2262
"""
2263
- debug_system(sys::AbstractSystem; error_nonfinite = true)
2263
+ debug_system(sys::AbstractSystem; functions = [log, sqrt, (^), /, inv, asin, acos], error_nonfinite = true)
2264
2264
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
2268
2268
does not throw an exception (like `1/0`). For example:
2269
2269
2270
2270
```julia-repl
@@ -2278,15 +2278,18 @@ ERROR: Function /(1, sin(P(t))) output non-finite value Inf with input
2278
2278
sin(P(t)) => 0.0
2279
2279
```
2280
2280
"""
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
2282
2285
if has_systems (sys) && ! isempty (get_systems (sys))
2283
2286
error (" debug_system(sys) only works on systems with no sub-systems! Consider flattening it with flatten(sys) or structural_simplify(sys) first." )
2284
2287
end
2285
2288
if has_eqs (sys)
2286
- @set! sys. eqs = debug_sub .(equations (sys); kw... )
2289
+ @set! sys. eqs = debug_sub .(equations (sys), Ref (functions) ; kw... )
2287
2290
end
2288
2291
if has_observed (sys)
2289
- @set! sys. observed = debug_sub .(observed (sys); kw... )
2292
+ @set! sys. observed = debug_sub .(observed (sys), Ref (functions) ; kw... )
2290
2293
end
2291
2294
return sys
2292
2295
end
0 commit comments