Hello,
I would like to know if it is possible to have assert statements on parameters of an MTK component.
For general @assert a >1
cases it hit the error where symbolic expression appears in Boolean context.
Toy Example:
using ModelingToolkit, DifferentialEquations,Plots
using ModelingToolkit: t_nounits as t, D_nounits as D
function test(η ::Number)
@assert abs(η) < 1
return η
end
@register_symbolic test(η ::Number)
@component function myfun(;name)
para = @parameters begin
η
end
vars = @variables begin
x(t)
end
eqs = [
D(x) ~ -test(η)
]
ODESystem(eqs, t, vars, para;name)
end
@named model = myfun()
sys = structural_simplify(model)
u0 = [sys.x => 1]
tspan = (0,10)
para = [sys.η => 0.5]
prob = ODEProblem(sys,u0,tspan,para)
sol = solve(prob)
Error:
ERROR: LoadError: TypeError: non-boolean (Num) used in boolean context
A symbolic expression appeared in a Boolean context. This error arises in situations where Julia expects a Bool, like
if boolean_condition use ifelse(boolean_condition, then branch, else branch)
x && y use x & y
boolean_condition ? a : b use ifelse(boolean_condition, a, b)
Is there a way around this?