Skip to content

Commit d9b4b4a

Browse files
authored
Merge pull request #1869 from SciML/myb/io
Only force unbound causal inputs to be states
2 parents 90d610b + 9254f1e commit d9b4b4a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/variables.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ setoutput(x, v) = setmetadata(x, VariableOutput, v)
3131
setio(x, i, o) = setoutput(setinput(x, i), o)
3232
isinput(x) = isvarkind(VariableInput, x)
3333
isoutput(x) = isvarkind(VariableOutput, x)
34-
isirreducible(x) = isvarkind(VariableIrreducible, x) || isinput(x)
34+
# Before the solvability check, we already have handled IO varibales, so
35+
# irreducibility is independent from IO.
36+
isirreducible(x) = isvarkind(VariableIrreducible, x)
3537
state_priority(x) = convert(Float64, getmetadata(x, VariableStatePriority, 0.0))::Float64
3638

3739
"""

test/input_output_handling.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,20 @@ m_outputs = [y₂]
301301
sys_simp, input_idxs = structural_simplify(sys, (; inputs = m_inputs, outputs = m_outputs))
302302
@test isequal(states(sys_simp), collect(x[1:2]))
303303
@test length(input_idxs) == 2
304+
305+
# https://github.com/SciML/ModelingToolkit.jl/issues/1577
306+
@parameters t
307+
@named c = Constant(; k = 2)
308+
@named gain = Gain(1;)
309+
@named int = Integrator(; k = 1)
310+
@named fb = Feedback(;)
311+
@named model = ODESystem([
312+
connect(c.output, fb.input1),
313+
connect(fb.input2, int.output),
314+
connect(fb.output, gain.input),
315+
connect(gain.output, int.input),
316+
],
317+
t,
318+
systems = [int, gain, c, fb])
319+
sys = structural_simplify(model)
320+
@test length(states(sys)) == length(equations(sys)) == 1

0 commit comments

Comments
 (0)