Symbolics.jl icon indicating copy to clipboard operation
Symbolics.jl copied to clipboard

Inconsistent use of kwarg slurping breaks MTK callback conditions

Open wsphillips opened this issue 3 years ago • 0 comments

The following MWE errors in ModelingToolkit.jl because symbolic callback conditions internally passed to build_function are ::Num and call the method here, without kwarg slurping, which differs from the rhss form that's more commonly used in MTK.

using ModelingToolkit, OrdinaryDiffEq

@parameters k t1 t2
@variables t A(t) B(t)

cond1 = (t == t1)
affect1 = [A ~ A + 1]
cb1 = cond1 => affect1
cond2 = (t == t2)
affect2 = [k ~ 1.0]
cb2 = cond2 => affect2

∂ₜ = Differential(t)
eqs = [∂ₜ(A) ~ -k * A]
@named osys = ODESystem(eqs, t, [A], [k, t1, t2], discrete_events = [cb1, cb2])
u0 = [A => 1.0]
p = [k => 0.0, t1 => 1.0, t2 => 2.0]
tspan = (0.0, 4.0)

# Method error for any kwarg supported by ODEProblem, but not by build_function for op::Any
ODEProblem(osys, u0, tspan, p; jac=true)

CC: @YingboMa @isaacsas

wsphillips avatar Aug 10 '22 21:08 wsphillips