Skip to content

fix: error when simplified discrete system contains algebraic equations #2766

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

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/systems/systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
else
newsys = newsys′
end
if newsys isa DiscreteSystem &&
any(eq -> symbolic_type(eq.lhs) == NotSymbolic(), equations(newsys))
error("""

Check warning on line 31 in src/systems/systems.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/systems.jl#L30-L31

Added lines #L30 - L31 were not covered by tests
Encountered algebraic equations when simplifying discrete system. This is \
not yet supported.
""")
end
if newsys isa ODESystem || has_parent(newsys)
@set! newsys.parent = complete(sys; split)
end
Expand Down
6 changes: 6 additions & 0 deletions test/discrete_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,9 @@ function System(; name, buffer)
end

@test_nowarn @mtkbuild sys = System(; buffer = ones(10))

# Ensure discrete systems with algebraic equations throw
@variables x(t) y(t)
k = ShiftIndex(t)
@named sys = DiscreteSystem([x ~ x^2 + y^2, y ~ x(k - 1) + y(k - 1)], t)
@test_throws ["algebraic equations", "not yet supported"] structural_simplify(sys)
Loading