Skip to content

assertions fail to trigger for discrete-time debug system #3500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
baggepinnen opened this issue Mar 26, 2025 · 0 comments
Open

assertions fail to trigger for discrete-time debug system #3500

baggepinnen opened this issue Mar 26, 2025 · 0 comments
Assignees
Labels
bug Something isn't working discrete-time

Comments

@baggepinnen
Copy link
Contributor

MWE: This should trigger the assertion in Float2Bool2 since the input u = x is not exaclty 1.0 or 0.0

using ModelingToolkit
using OrdinaryDiffEq
t = ModelingToolkit.t_nounits
k = ShiftIndex(t)

function Float2Bool2(; name, strict=false)
    vars = @variables begin
        u(t)::Float64
        y(t)::Bool
    end
    equations = [
        y ~ u != 0
    ]
    if strict
        DiscreteSystem(equations, t, vars, []; name, assertions=[(u == 1.0) | (u == 0.0)])
    else
        DiscreteSystem(equations, t, vars, []; name)
    end
end

function Model2(; name)
    @variables begin
        x(t) = 1
    end
    systems = @named begin
        conversion = Float2Bool2(strict=true)
    end
    equations = [
        x(k) ~ 0.99x(k-1)
        conversion.u ~ x
    ]
    DiscreteSystem(equations, t; name, systems)
end

@mtkbuild sys = Model2()
dsys = debug_system(sys; functions = []);
prob = DiscreteProblem(dsys, [], (0,10))
sol = solve(prob, FunctionMap())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discrete-time
Projects
None yet
Development

No branches or pull requests

2 participants