@@ -9,19 +9,19 @@ using Plots: Plots, plot
99@testset " Basic indexing" begin
1010 @parameters a b c d
1111 @variables s1 (t) s2 (t)
12-
12+
1313 eqs = [D (s1) ~ a * s1 / (1 + s1 + s2) - b * s1,
1414 D (s2) ~ + c * s2 / (1 + s1 + s2) - d * s2]
15-
15+
1616 @mtkcompile population_model = System (eqs, t)
17-
17+
1818 # Tests on ODEProblem.
1919 u0 = [s1 => 2.0 , s2 => 1.0 ]
2020 p = [a => 2.0 , b => 1.0 , c => 1.0 , d => 1.0 ]
2121 tspan = (0.0 , 1000000.0 )
2222 oprob = ODEProblem (population_model, [u0; p], tspan)
2323 sol = solve (oprob, Rodas4 ())
24-
24+
2525 @test sol[s1] == sol[population_model. s1] == sol[:s1 ]
2626 @test sol[s2] == sol[population_model. s2] == sol[:s2 ]
2727 @test sol[s1][end ] ≈ 1.0
@@ -57,93 +57,94 @@ using Plots: Plots, plot
5757 noisy_population_model = complete (noisy_population_model)
5858 sprob = SDEProblem (noisy_population_model, [u0; p], (0.0 , 100.0 ))
5959 sol = solve (sprob, ImplicitEM ())
60-
60+
6161 @test sol[s1] == sol[noisy_population_model. s1] == sol[:s1 ]
6262 @test sol[s2] == sol[noisy_population_model. s2] == sol[:s2 ]
6363 @test_throws Exception sol[a]
6464 @test_throws Exception sol[noisy_population_model. a]
6565 @test_throws Exception sol[:a ]
6666 @test_nowarn sol (0.5 , idxs = noisy_population_model. s1)
6767 # ## Tests on layered model (some things should not work). ###
68-
68+
6969 @parameters σ ρ β
7070 @variables x (t) y (t) z (t)
71-
71+
7272 eqs = [D (x) ~ σ * (y - x),
7373 D (y) ~ x * (ρ - z) - y,
7474 D (z) ~ x * y - β * z]
75-
75+
7676 @named lorenz1 = System (eqs, t)
7777 @named lorenz2 = System (eqs, t)
78-
78+
7979 @parameters γ
8080 @variables a (t) α (t)
8181 connections = [0 ~ lorenz1. x + lorenz2. y + a * γ,
8282 α ~ 2 lorenz1. x + a * γ]
8383 @mtkcompile sys = System (connections, t, [a, α], [γ], systems = [lorenz1, lorenz2])
84-
84+
8585 u0 = [lorenz1. x => 1.0 ,
8686 lorenz1. y => 0.0 ,
8787 lorenz1. z => 0.0 ,
8888 lorenz2. x => 0.0 ,
8989 lorenz2. y => 1.0 ,
9090 lorenz2. z => 0.0 ]
91-
91+
9292 p = [lorenz1. σ => 10.0 ,
9393 lorenz1. ρ => 28.0 ,
9494 lorenz1. β => 8 / 3 ,
9595 lorenz2. σ => 10.0 ,
9696 lorenz2. ρ => 28.0 ,
9797 lorenz2. β => 8 / 3 ,
9898 γ => 2.0 ]
99-
99+
100100 tspan = (0.0 , 100.0 )
101101 prob = ODEProblem (sys, [u0; p], tspan)
102102 sol = solve (prob, Rodas4 ())
103-
103+
104104 @test_throws ArgumentError sol[x]
105- @test in (sol[lorenz1. x], [getindex .(sol. u, i) for i in 1 : length (unknowns (sol. prob. f. sys))])
105+ @test in (sol[lorenz1. x], [getindex .(sol. u, i)
106+ for i in 1 : length (unknowns (sol. prob. f. sys))])
106107 @test_throws KeyError sol[:x ]
107-
108+
108109 # ## Non-symbolic indexing tests
109110 @test sol[:, 1 ] isa AbstractVector
110111 @test sol[:, 1 : 2 ] isa AbstractDiffEqArray
111112 @test sol[:, [1 , 2 ]] isa AbstractDiffEqArray
112-
113+
113114 sol1 = sol (0.0 : 1.0 : 10.0 )
114115 @test sol1. u isa Vector
115116 @test first (sol1. u) isa Vector
116117 @test length (sol1. u) == 11
117118 @test length (sol1. t) == 11
118-
119+
119120 sol2 = sol (0.1 )
120121 @test sol2 isa Vector
121122 @test length (sol2) == length (unknowns (sys))
122123 @test first (sol2) isa Real
123-
124+
124125 sol3 = sol (0.0 : 1.0 : 10.0 , idxs = [lorenz1. x, lorenz2. x])
125-
126+
126127 sol7 = sol (0.0 : 1.0 : 10.0 , idxs = [2 , 1 ])
127128 @test sol7. u isa Vector
128129 @test first (sol7. u) isa Vector
129130 @test length (sol7. u) == 11
130131 @test length (sol7. t) == 11
131132 @test collect (sol7[t]) ≈ sol3. t
132133 @test collect (sol7[t, 1 : 5 ]) ≈ sol3. t[1 : 5 ]
133-
134+
134135 sol8 = sol (0.1 , idxs = [2 , 1 ])
135136 @test sol8 isa Vector
136137 @test length (sol8) == 2
137138 @test first (sol8) isa Real
138-
139+
139140 sol9 = sol (0.0 : 1.0 : 10.0 , idxs = 2 )
140141 @test sol9. u isa Vector
141142 @test first (sol9. u) isa Real
142143 @test length (sol9. u) == 11
143144 @test length (sol9. t) == 11
144145 @test collect (sol9[t]) ≈ sol3. t
145146 @test collect (sol9[t, 1 : 5 ]) ≈ sol3. t[1 : 5 ]
146-
147+
147148 sol10 = sol (0.1 , idxs = 2 )
148149 @test sol10 isa Real
149150end
194195
195196 @mtkcompile sys = System ([D (x) ~ x + p * y, 1 ~ sin (y) + cos (x)], t)
196197 xidx = variable_index (sys, x)
197- prob = DAEProblem (sys, [D (x) => x + p * y, D (y) => 1 / sqrt (1 - (1 - cos (x))^ 2 ), x => 1.0 , y => asin (1 - cos (x)), p => 2.0 ],
198+ prob = DAEProblem (sys,
199+ [D (x) => x + p * y, D (y) => 1 / sqrt (1 - (1 - cos (x))^ 2 ),
200+ x => 1.0 , y => asin (1 - cos (x)), p => 2.0 ],
198201 (0.0 , 1.0 ); build_initializeprob = false )
199202 dae_sol = solve (prob, DFBDF (); save_idxs = [x])
200203
@@ -225,10 +228,11 @@ end
225228 @testset " ODE with callbacks" begin
226229 @variables x (t) y (t)
227230 @parameters p q (t) r (t) s (t) u (t)
228- evs = [
229- ModelingToolkit. SymbolicDiscreteCallback (0.1 , [q ~ Pre (q) + 1 , s ~ Pre (s) - 1 ]; discrete_parameters = [q, s], iv = t)
230- ModelingToolkit. SymbolicDiscreteCallback (0.1 , [r ~ 2 Pre (r), u ~ Pre (u) / 2 ]; discrete_parameters = [r, u], iv = t)
231- ]
231+ evs = [ModelingToolkit. SymbolicDiscreteCallback (
232+ 0.1 , [q ~ Pre (q) + 1 , s ~ Pre (s) - 1 ];
233+ discrete_parameters = [q, s], iv = t)
234+ ModelingToolkit. SymbolicDiscreteCallback (0.1 , [r ~ 2 Pre (r), u ~ Pre (u) / 2 ];
235+ discrete_parameters = [r, u], iv = t)]
232236 @mtkcompile sys = System ([D (x) ~ x + p * y, D (y) ~ 2 p + x], t, [x, y],
233237 [p, q, r, s, u], discrete_events = evs)
234238 @test length (unknowns (sys)) == 2
243247 sidx = parameter_index (sys, s)
244248 uidx = parameter_index (sys, u)
245249
246- prob = ODEProblem (sys, [x => 1.0 , y => 1.0 , p => 0.5 , q => 0.0 , r => 1.0 , s => 10.0 , u => 4096.0 ], (0.0 , 5.0 ))
250+ prob = ODEProblem (
251+ sys, [x => 1.0 , y => 1.0 , p => 0.5 , q => 0.0 , r => 1.0 , s => 10.0 , u => 4096.0 ],
252+ (0.0 , 5.0 ))
247253
248254 @test SciMLBase. SavedSubsystem (sys, prob. p, [x, y, q, r, s, u]) === nothing
249255
@@ -268,13 +274,16 @@ end
268274 @testset " SavedSubsystemWithFallback" begin
269275 @variables x (t) y (t)
270276 @parameters p q (t) r (t) s (t) u (t)
271- evs = [
272- ModelingToolkit. SymbolicDiscreteCallback (0.1 , [q ~ Pre (q) + 1 , s ~ Pre (s) - 1 ]; discrete_parameters = [q, s], iv = t)
273- ModelingToolkit. SymbolicDiscreteCallback (0.1 , [r ~ 2 Pre (r), u ~ Pre (u) / 2 ]; discrete_parameters = [r, u], iv = t)
274- ]
277+ evs = [ModelingToolkit. SymbolicDiscreteCallback (
278+ 0.1 , [q ~ Pre (q) + 1 , s ~ Pre (s) - 1 ];
279+ discrete_parameters = [q, s], iv = t)
280+ ModelingToolkit. SymbolicDiscreteCallback (0.1 , [r ~ 2 Pre (r), u ~ Pre (u) / 2 ];
281+ discrete_parameters = [r, u], iv = t)]
275282 @mtkcompile sys = System ([D (x) ~ x + p * y, D (y) ~ 2 p + x^ 2 ], t, [x, y],
276283 [p, q, r, s, u], discrete_events = evs)
277- prob = ODEProblem (sys, [x => 1.0 , y => 1.0 , p => 0.5 , q => 0.0 , r => 1.0 , s => 10.0 , u => 4096.0 ], (0.0 , 5.0 ))
284+ prob = ODEProblem (
285+ sys, [x => 1.0 , y => 1.0 , p => 0.5 , q => 0.0 , r => 1.0 , s => 10.0 , u => 4096.0 ],
286+ (0.0 , 5.0 ))
278287 ss = SciMLBase. SavedSubsystem (sys, prob. p, [x, q, s, r])
279288 @test SciMLBase. get_saved_state_idxs (ss) == [variable_index (sys, x)]
280289 sswf = SciMLBase. SavedSubsystemWithFallback (ss, sys)
@@ -314,13 +323,16 @@ end
314323 @testset " get_save_idxs_and_saved_subsystem" begin
315324 @variables x (t) y (t)
316325 @parameters p q (t) r (t) s (t) u (t)
317- evs = [
318- ModelingToolkit. SymbolicDiscreteCallback (0.1 , [q ~ Pre (q) + 1 , s ~ Pre (s) - 1 ]; discrete_parameters = [q, s], iv = t)
319- ModelingToolkit. SymbolicDiscreteCallback (0.1 , [r ~ 2 Pre (r), u ~ Pre (u) / 2 ]; discrete_parameters = [r, u], iv = t)
320- ]
326+ evs = [ModelingToolkit. SymbolicDiscreteCallback (
327+ 0.1 , [q ~ Pre (q) + 1 , s ~ Pre (s) - 1 ];
328+ discrete_parameters = [q, s], iv = t)
329+ ModelingToolkit. SymbolicDiscreteCallback (0.1 , [r ~ 2 Pre (r), u ~ Pre (u) / 2 ];
330+ discrete_parameters = [r, u], iv = t)]
321331 @mtkcompile sys = System ([D (x) ~ x + p * y, D (y) ~ 2 p + x^ 2 ], t, [x, y],
322332 [p, q, r, s, u], discrete_events = evs)
323- prob = ODEProblem (sys, [x => 1.0 , y => 1.0 , p => 0.5 , q => 0.0 , r => 1.0 , s => 10.0 , u => 4096.0 ], (0.0 , 5.0 ))
333+ prob = ODEProblem (
334+ sys, [x => 1.0 , y => 1.0 , p => 0.5 , q => 0.0 , r => 1.0 , s => 10.0 , u => 4096.0 ],
335+ (0.0 , 5.0 ))
324336
325337 _idxs, _ss = @inferred SciMLBase. get_save_idxs_and_saved_subsystem (prob, nothing )
326338 @test _idxs === _ss === nothing
0 commit comments