Skip to content

Commit b3949ed

Browse files
test: add tests for cycle detection
1 parent 0b7d8fa commit b3949ed

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/downstream/modelingtoolkit_remake.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,29 @@ end
248248
prob2 = remake(prob; u0 = [x => t + 3.0])
249249
@test prob2[x] 3.0
250250
end
251+
252+
@static if length(methods(SciMLBase.detect_cycles)) == 1
253+
function SciMLBase.detect_cycles(
254+
::ModelingToolkit.AbstractSystem, varmap::Dict{Any, Any}, vars)
255+
for sym in vars
256+
if symbolic_type(ModelingToolkit.fixpoint_sub(sym, varmap; maxiters = 10)) !=
257+
NotSymbolic()
258+
return true
259+
end
260+
end
261+
return false
262+
end
263+
end
264+
265+
@testset "Cycle detection" begin
266+
@variables x(t) y(t)
267+
@parameters p q
268+
@mtkbuild sys = ODESystem([D(x) ~ x * p, D(y) ~ y * q], t)
269+
270+
prob = ODEProblem(sys, [x => 1.0, y => 1.0], (0.0, 1.0), [p => 1.0, q => 1.0])
271+
@test_throws SciMLBase.CyclicDependencyError remake(
272+
prob; u0 = [x => 2y + 3, y => 2x + 1])
273+
@test_throws SciMLBase.CyclicDependencyError remake(prob; p = [p => 2q + 1, q => p + 3])
274+
@test_throws SciMLBase.CyclicDependencyError remake(
275+
prob; u0 = [x => 2y + p, y => q + 3], p = [p => x + y, q => p + 3])
276+
end

0 commit comments

Comments
 (0)