Skip to content

Commit fd94d63

Browse files
feat: improve error message when system contains array equations
1 parent f4d4faf commit fd94d63

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/systems/abstractsystem.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,9 @@ function check_eqs_u0(eqs, dvs, u0; check_length = true, kwargs...)
28592859
if u0 !== nothing
28602860
if check_length
28612861
if !(length(eqs) == length(dvs) == length(u0))
2862+
if any(eq -> Symbolics.isarraysymbolic(eq.lhs), eqs)
2863+
throw(ArgumentError("The system has array equations. Call `structural_simplify` to handle such equations."))
2864+
end
28622865
throw(ArgumentError("Equations ($(length(eqs))), unknowns ($(length(dvs))), and initial conditions ($(length(u0))) are of different lengths."))
28632866
end
28642867
elseif length(dvs) != length(u0)

test/odesystem.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,3 +1394,18 @@ end
13941394
prob = @test_nowarn ODEProblem(sys, nothing, (0.0, 1.0))
13951395
@test_nowarn solve(prob)
13961396
end
1397+
1398+
@testset "Issue #2597" begin
1399+
@mtkmodel Foo begin
1400+
@variables begin
1401+
x(t)[1:2]
1402+
end
1403+
@equations begin
1404+
D.(x) ~ .-x
1405+
end
1406+
end
1407+
@named foo = Foo()
1408+
foo = complete(foo)
1409+
@test_throws ["array equations", "structural_simplify"] ODEProblem(
1410+
foo, Dict(foo.x => [1.0, 1]), (0.0, 1.0))
1411+
end

0 commit comments

Comments
 (0)