Skip to content

Commit 6eb7ef7

Browse files
fix: fix incorrect metadata handling in symbolic affect simplification
1 parent 647c9f9 commit 6eb7ef7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/structural_transformation/symbolics_tearing.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,10 @@ function update_simplified_system!(
972972
# Algebraic variables are shifted forward by one, so we backshift them.
973973
unknowns = map(enumerate(unknowns)) do (i, var)
974974
if iscall(var) && operation(var) isa Shift && operation(var).steps == 1
975-
backshift_expr(var, iv)
975+
# We might have shifted a variable with io metadata. That is irrelevant now
976+
# because we handled io variables earlier in `_mtkcompile!` so just ignore
977+
# it here.
978+
setio(backshift_expr(var, iv), false, false)
976979
else
977980
var
978981
end

test/symbolic_events.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,3 +1410,12 @@ end
14101410
sol = solve(prob, FBDF())
14111411
@test SciMLBase.successful_retcode(sol)
14121412
end
1413+
1414+
@testset "Algebraic equation with input variable in symbolic affect" begin
1415+
# Specifically happens when the variable marked as an input is an algebraic variable
1416+
# in the affect system.
1417+
@variables x(t) [input = true] y(t)
1418+
dev = ModelingToolkit.SymbolicDiscreteCallback(1.0, [y ~ Pre(y) + 1])
1419+
@named sys = System([D(y) ~ 2x + 1, x^2 ~ 2y^3], t; discrete_events = [dev])
1420+
sys = @test_nowarn mtkcompile(sys)
1421+
end

0 commit comments

Comments
 (0)