Skip to content

Commit 3518b39

Browse files
test: test that redundant observed expressions are not evaluated
1 parent 629c26b commit 3518b39

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/code_generation.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,33 @@ end
110110
@test val[] == 2
111111
end
112112
end
113+
114+
@testset "Do not codegen redundant expressions" begin
115+
@variables v1(t) = 1
116+
@variables v2(t) [guess = 0]
117+
118+
mutable struct Data
119+
count::Int
120+
end
121+
function update!(d::Data, t)
122+
d.count += 1 # Count the number of times the data gets updated.
123+
end
124+
function (d::Data)(t)
125+
update!(d, t)
126+
rand(1:10)
127+
end
128+
129+
@parameters (d1::Data)(..) = Data(0)
130+
@parameters (d2::Data)(..) = Data(0)
131+
132+
eqs = [
133+
D(v1) ~ d1(t),
134+
v2 ~ d2(t) # Some of the data parameters are not actually needed to solve the system.
135+
]
136+
137+
@mtkbuild sys = System(eqs, t)
138+
prob = ODEProblem(sys, [], (0.0, 1.0))
139+
sol = solve(prob, Tsit5())
140+
141+
@test sol.ps[d2].count == 0
142+
end

0 commit comments

Comments
 (0)