Skip to content

Commit 7e5958f

Browse files
Merge pull request #2766 from AayushSabharwal/as/error-disc-algeq
fix: error when simplified discrete system contains algebraic equations
2 parents 3f67126 + 7f29017 commit 7e5958f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/systems/systems.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ function structural_simplify(
2626
else
2727
newsys = newsys′
2828
end
29+
if newsys isa DiscreteSystem &&
30+
any(eq -> symbolic_type(eq.lhs) == NotSymbolic(), equations(newsys))
31+
error("""
32+
Encountered algebraic equations when simplifying discrete system. This is \
33+
not yet supported.
34+
""")
35+
end
2936
if newsys isa ODESystem || has_parent(newsys)
3037
@set! newsys.parent = complete(sys; split)
3138
end

test/discrete_system.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,9 @@ function System(; name, buffer)
265265
end
266266

267267
@test_nowarn @mtkbuild sys = System(; buffer = ones(10))
268+
269+
# Ensure discrete systems with algebraic equations throw
270+
@variables x(t) y(t)
271+
k = ShiftIndex(t)
272+
@named sys = DiscreteSystem([x ~ x^2 + y^2, y ~ x(k - 1) + y(k - 1)], t)
273+
@test_throws ["algebraic equations", "not yet supported"] structural_simplify(sys)

0 commit comments

Comments
 (0)