# \`@assert\` handling for symbolically registered functions in MTK

**URL:** https://discourse.julialang.org/t/assert-handling-for-symbolically-registered-functions-in-mtk/122783
**Category:** Modelling & Simulations
**Created:** [November 18, 2024, 5:41pm UTC](https://discourse.julialang.org/t/assert-handling-for-symbolically-registered-functions-in-mtk/122783 "2024-11-18T17:41:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Sushrut\_Deshpande](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sushrut_deshpande/32/52754_2.png) [@Sushrut\_Deshpande](https://discourse.julialang.org/u/Sushrut_Deshpande)
#### Post date: [November 18, 2024, 5:41pm UTC](https://discourse.julialang.org/t/assert-handling-for-symbolically-registered-functions-in-mtk/122783/1 "2024-11-18T17:41:42Z")

</div>

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:

```julia
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:

```julia
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?

---

<div class="post-metadata">

### Author: ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)
#### Post date: [November 18, 2024, 6:39pm UTC](https://discourse.julialang.org/t/assert-handling-for-symbolically-registered-functions-in-mtk/122783/2 "2024-11-18T18:39:13Z")

</div>

Remove the type annotations on test and its registration. So just `test(η)` in both places. The type annotation on the function definition adds nothing when there is only one method and the restriction on the registration prevents all the necessary methods from being defined for you.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [November 18, 2024, 6:45pm UTC](https://discourse.julialang.org/t/assert-handling-for-symbolically-registered-functions-in-mtk/122783/3 "2024-11-18T18:45:57Z")

</div>

> [@Sushrut\_Deshpande](#):
>
> `@register_symbolic test(η ::Number)`

Indeed, `@register_symbolic test(η)` would fix it. It only registers un-specified arugments.
