Skip to content

Commit deaf660

Browse files
committed
init
1 parent 59294a5 commit deaf660

File tree

9 files changed

+78
-53
lines changed

9 files changed

+78
-53
lines changed

test/dsl/dsl_options.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,12 @@ let
488488
@test sol[:Y][end] 3.0
489489

490490
# Tests that observables can be used for plot indexing.
491-
@test_broken false # plot(sol; idxs=X).series_list[1].plotattributes[:y][end] ≈ 10.0
491+
plot(sol; idxs=X).series_list[1].plotattributes[:y][end] 10.0
492492
@test plot(sol; idxs=rn.X).series_list[1].plotattributes[:y][end] 10.0
493493
@test plot(sol; idxs=:X).series_list[1].plotattributes[:y][end] 10.0
494494
@test plot(sol; idxs=[X, Y]).series_list[2].plotattributes[:y][end] 3.0
495495
@test plot(sol; idxs=[rn.X, rn.Y]).series_list[2].plotattributes[:y][end] 3.0
496-
@test_broken false # plot(sol; idxs=[:X, :Y]).series_list[2].plotattributes[:y][end] ≈ 3.0
496+
@test_broken plot(sol; idxs=[:X, :Y]).series_list[2].plotattributes[:y][end] 3.0 # (https://github.com/SciML/ModelingToolkit.jl/issues/2778)
497497
end
498498

499499
# Compares programmatic and DSL system with observables.

test/reactionsystem_core/coupled_equation_crn_systems.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ end
293293
# Checks for both differential and algebraic equations.
294294
# Checks for problems, integrators, and solutions yielded by coupled systems.
295295
# Checks that metadata, types, and default values are carried through correctly.
296-
@test_broken let # SDEs are currently broken with structural simplify.
296+
@test_broken let # SDEs are currently broken with structural simplify (https://github.com/SciML/ModelingToolkit.jl/issues/2614).
297297
# Creates the model
298298
@parameters a1 [description="Parameter a1"] a2::Rational{Int64} a3=0.3 a4::Rational{Int64}=4//10 [description="Parameter a4"]
299299
@parameters b1 [description="Parameter b1"] b2::Int64 b3 = 3 b4::Int64=4 [description="Parameter b4"]
@@ -558,14 +558,12 @@ let
558558

559559
# Checks that SteadyState simulation of the system achieves the correct steady state.
560560
# Currently broken due to MTK.
561-
@test_broken begin
562-
ssprob = SteadyStateProblem(coupled_rs, u0, ps; structural_simplify = true)
563-
sssol = solve(oprob, DynamicSS(Vern7()); abstol = 1e-8, reltol = 1e-8)
564-
@test osol[X][end] 2.0
565-
@test osol[A][end] 0.0 atol = 1e-8
566-
@test osol[D(A)][end] 0.0 atol = 1e-8
567-
@test osol[B][end] 1.0
568-
end
561+
ssprob = SteadyStateProblem(coupled_rs, u0, ps; structural_simplify = true)
562+
sssol = solve(ssprob, DynamicSS(Vern7()); abstol = 1e-8, reltol = 1e-8)
563+
@test sssol[X][end] 2.0
564+
@test sssol[A][end] 0.0 atol = 1e-8
565+
@test sssol[D(A)][end] 0.0 atol = 1e-8
566+
@test sssol[B][end] 1.0
569567

570568
# Checks that the steady state can be found by solving a nonlinear problem.
571569
# Here `B => 0.1` has to be provided as well (and it shouldn't for the 2nd order ODE), hence the

test/reactionsystem_core/events.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ let
362362
sol = solve(jprob, SSAStepper(); seed)
363363

364364
# Checks that all `e` parameters have been updated properly.
365-
# Note that periodic discrete events are currently broken for jump processes.
365+
# Note that periodic discrete events are currently broken for jump processes (and unlikely to be fixed soon due to have events are implemented).
366366
@test sol.ps[:e1] == 1
367-
@test_broken sol.ps[:e2] == 1
367+
@test_broken sol.ps[:e2] == 1 # (https://github.com/SciML/JumpProcesses.jl/issues/417)
368368
@test sol.ps[:e3] == 1
369369
end
370370

@@ -424,21 +424,22 @@ let
424424
osol_events = solve(oprob_events, Tsit5())
425425
@test osol == osol_events
426426

427-
# Checks for SDE simulations.
427+
# Checks for SDE simulations (note, non-seed dependant test should be created instead).
428428
sprob = SDEProblem(rn, u0, tspan, ps)
429429
sprob_events = SDEProblem(rn_events, u0, tspan, ps)
430430
ssol = solve(sprob, ImplicitEM(); seed, callback)
431431
ssol_events = solve(sprob_events, ImplicitEM(); seed)
432432
@test ssol == ssol_events
433433

434-
# Checks for Jump simulations.
434+
# Checks for Jump simulations. (note, non-seed dependant test should be created instead)
435+
# Note that periodic discrete events are currently broken for jump processes (and unlikely to be fixed soon due to have events are implemented).
435436
callback = CallbackSet(cb_disc_1, cb_disc_2, cb_disc_3)
436437
dprob = DiscreteProblem(rn, u0, tspan, ps)
437438
dprob_events = DiscreteProblem(rn_dics_events, u0, tspan, ps)
438439
jprob = JumpProblem(rn, dprob, Direct(); rng)
439440
jprob_events = JumpProblem(rn_dics_events, dprob_events, Direct(); rng)
440441
sol = solve(jprob, SSAStepper(); seed, callback)
441-
@test_broken let # Broken due to. Even if fixed, seeding might not work due to events.
442+
@test_broken let # (https://github.com/SciML/JumpProcesses.jl/issues/417)
442443
sol_events = solve(jprob_events, SSAStepper(); seed)
443444
@test sol == sol_events
444445
end

test/reactionsystem_core/parameter_type_designation.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ let
8888
nsol = solve(nprob, NewtonRaphson())
8989

9090
# Checks all stored parameters.
91-
for mtk_struct in [oprob, sprob, dprob, jprob, nprob, oinit, sinit, jinit, osol, ssol, jsol, nsol]
91+
for mtk_struct in [oprob, sprob, dprob, jprob, nprob, oinit, sinit, jinit, ninit, osol, ssol, jsol, nsol]
9292
# Checks that all parameters have the correct type.
9393
@test unwrap(mtk_struct.ps[p1]) isa Float64
9494
@test unwrap(mtk_struct.ps[d1]) isa Float64
@@ -114,8 +114,8 @@ let
114114
@test unwrap(mtk_struct.ps[d5]) == Float32(1.5)
115115
end
116116

117-
# Checks all stored variables.
118-
for mtk_struct in [oprob, sprob, dprob, jprob, nprob, oinit, sinit, jinit]
117+
# Checks all stored variables (these should always be `Float64`).
118+
for mtk_struct in [oprob, sprob, dprob, jprob, nprob, oinit, sinit, jinit, ninit]
119119
# Checks that all variables have the correct type.
120120
@test unwrap(mtk_struct[X1]) isa Float64
121121
@test unwrap(mtk_struct[X2]) isa Float64
@@ -130,10 +130,4 @@ let
130130
@test unwrap(mtk_struct[X4]) == 0.4
131131
@test unwrap(mtk_struct[X5]) == 0.5
132132
end
133-
134-
# This test started working now, probably due to a MTK fix. Need to look at where to put it
135-
# back into the test properly though.
136-
@test_broken false
137-
# Indexing currently broken for NonlinearSystem integrators (MTK intend to support this though).
138-
@test unwrap(ninit.ps[p1]) isa Float64
139133
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using SafeTestsets, Test
99

1010
### Run Tests ###
1111
@time begin
12+
@time @safetestset "MTK Structure Indexing" begin include("upstream/mtk_structure_indexing.jl") end
1213

1314
# Tests the `ReactionSystem` structure and its properties.
1415
@time @safetestset "Reaction Structure" begin include("reactionsystem_core/reaction.jl") end

test/simulation_and_solving/simulate_SDEs.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,14 @@ let
224224
@species X1(t) X2(t)
225225
p_syms = @parameters $(η_stored) k1 k2
226226

227-
r1 = Reaction(k1,[X1],[X2],[1],[1]; metadata = [:noise_scaling => η_stored])
228-
r2 = Reaction(k2,[X2],[X1],[1],[1]; metadata = [:noise_scaling => η_stored])
227+
r1 = Reaction(k1, [X1], [X2], [1], [1]; metadata = [:noise_scaling => p_syms[1]])
228+
r2 = Reaction(k2, [X2], [X1], [1], [1]; metadata = [:noise_scaling => p_syms[1]])
229229
@named noise_scaling_network = ReactionSystem([r1, r2], t, [X1, X2], [k1, k2, p_syms[1]])
230+
noise_scaling_network = complete(noise_scaling_network)
230231

231232
u0 = [:X1 => 1100.0, :X2 => 3900.0]
232233
p = [:k1 => 2.0, :k2 => 0.5, => 0.0]
233-
@test_broken SDEProblem(noise_scaling_network, u0, (0.0, 1000.0), p).ps[] == 0.0 # Broken due to SII/MTK stuff.
234+
@test SDEProblem(noise_scaling_network, u0, (0.0, 1000.0), p).ps[] == 0.0
234235
end
235236

236237
# Complicated test with many combinations of options.

test/spatial_modelling/lattice_reaction_systems.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ end
280280
# Currently not supported. Won't be until the LatticeReactionSystem internal update is merged.
281281

282282
# Checks that parameter types designated in the non-spatial `ReactionSystem` is handled correctly.
283+
# Broken lattice tests have local branches that fixes them.
283284
@test_broken let
284285
# Declares LatticeReactionSystem with designated parameter types.
285286
rs = @reaction_network begin

test/upstream/mtk_problem_inputs.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ let
172172
@species X3(t)
173173
@parameters k3
174174

175+
# Creates systems (so these are not recreated in each problem call).
176+
osys = convert(ODESystem, rn)
177+
ssys = convert(SDESystem, rn)
178+
nsys = convert(NonlinearSystem, rn)
179+
175180
# Declares valid initial conditions and parameter values
176181
u0_valid = [X1 => 1, X2 => 2]
177182
ps_valid = [k1 => 0.5, k2 => 0.1]
@@ -218,25 +223,26 @@ let
218223
]
219224

220225
# Loops through all potential parameter sets, checking their inputs yield errors.
226+
# Broken tests are due to this issue: https://github.com/SciML/ModelingToolkit.jl/issues/2779
221227
for ps in [ps_valid; ps_invalid], u0 in [u0_valid; u0s_invalid]
222228
# Handles problems with/without tspan separately. Special check ensuring that valid inputs passes.
223-
for XProblem in [ODEProblem, SDEProblem, DiscreteProblem]
229+
for (xsys, XProblem) in zip([osys, ssys, rn], [ODEProblem, SDEProblem, DiscreteProblem])
224230
if (ps == ps_valid) && (u0 == u0_valid)
225-
XProblem(rn, u0, (0.0, 1.0), ps); @test true;
231+
XProblem(xsys, u0, (0.0, 1.0), ps); @test true;
226232
else
227233
# Several of these cases do not throw errors (https://github.com/SciML/ModelingToolkit.jl/issues/2624).
228234
@test_broken false
229235
continue
230-
@test_throws Exception XProblem(rn, u0, (0.0, 1.0), ps)
236+
@test_throws Exception XProblem(xsys, u0, (0.0, 1.0), ps)
231237
end
232238
end
233-
for XProblem in [NonlinearProblem, SteadyStateProblem]
239+
for (xsys, XProblem) in zip([nsys, osys], [NonlinearProblem, SteadyStateProblem])
234240
if (ps == ps_valid) && (u0 == u0_valid)
235-
XProblem(rn, u0, ps); @test true;
241+
XProblem(xsys, u0, ps); @test true;
236242
else
237243
@test_broken false
238244
continue
239-
@test_throws Exception XProblem(rn, u0, ps)
245+
@test_throws Exception XProblem(xsys, u0, ps)
240246
end
241247
end
242248
end

test/upstream/mtk_structure_indexing.jl

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ begin
5050
sint = init(sprob, ImplicitEM(); save_everystep=false)
5151
jint = init(jprob, SSAStepper())
5252
nint = init(nprob, NewtonRaphson(); save_everystep=false)
53-
@test_broken ssint = init(ssprob, DynamicSS(Tsit5()); save_everystep=false) # https://github.com/SciML/SciMLBase.jl/issues/660
53+
@test_broken ssint = init(ssprob, DynamicSS(Tsit5()); save_everystep=false) # https://github.com/SciML/SteadyStateDiffEq.jl/issues/79
5454
integrators = [oint, sint, jint, nint]
5555

5656
# Creates solutions.
@@ -64,14 +64,12 @@ end
6464

6565
# Tests problem indexing and updating.
6666
let
67-
@test_broken false # A few cases fails for SteadyStateProblem: https://github.com/SciML/SciMLBase.jl/issues/660
68-
@test_broken false # Most cases broken for Ensemble problems: https://github.com/SciML/SciMLBase.jl/issues/661
69-
for prob in deepcopy(problems[1:end-1])
67+
for prob in [deepcopy(problems); deepcopy(eproblems)]
7068
# Get u values (including observables).
7169
@test prob[X] == prob[model.X] == prob[:X] == 4
7270
@test prob[XY] == prob[model.XY] == prob[:XY] == 9
7371
@test prob[[XY,Y]] == prob[[model.XY,model.Y]] == prob[[:XY,:Y]] == [9, 5]
74-
@test_broken prob[(XY,Y)] == prob[(model.XY,model.Y)] == prob[(:XY,:Y)] == (9, 5)
72+
@test_broken prob[(XY,Y)] == prob[(model.XY,model.Y)] == prob[(:XY,:Y)] == (9, 5) # https://github.com/SciML/SciMLBase.jl/issues/709
7573
@test getu(prob, X)(prob) == getu(prob, model.X)(prob) == getu(prob, :X)(prob) == 4
7674
@test getu(prob, XY)(prob) == getu(prob, model.XY)(prob) == getu(prob, :XY)(prob) == 9
7775
@test getu(prob, [XY,Y])(prob) == getu(prob, [model.XY,model.Y])(prob) == getu(prob, [:XY,:Y])(prob) == [9, 5]
@@ -117,8 +115,7 @@ end
117115

118116
# Test remake function.
119117
let
120-
@test_broken false # Currently cannot be run for Ensemble problems: https://github.com/SciML/SciMLBase.jl/issues/661 (as indexing cannot be used to check values).
121-
for prob in deepcopy(problems)
118+
for prob in [deepcopy(problems); deepcopy(eproblems)]
122119
# Remake for all u0s.
123120
rp = remake(prob; u0 = [X => 1, Y => 2])
124121
@test rp[[X, Y]] == [1, 2]
@@ -156,9 +153,7 @@ end
156153
# Test integrator indexing.
157154
let
158155
@test_broken false # NOTE: Multiple problems for `nint` (https://github.com/SciML/SciMLBase.jl/issues/662).
159-
@test_broken false # NOTE: Multiple problems for `jint` (https://github.com/SciML/SciMLBase.jl/issues/654).
160-
@test_broken false # NOTE: Cannot even create a `ssint` (https://github.com/SciML/SciMLBase.jl/issues/660).
161-
for int in deepcopy([oint, sint])
156+
for int in deepcopy([oint, sint, jint])
162157
# Get u values.
163158
@test int[X] == int[model.X] == int[:X] == 4
164159
@test int[XY] == int[model.XY] == int[:XY] == 9
@@ -208,6 +203,7 @@ let
208203
end
209204

210205
# Test solve's save_idxs argument.
206+
# Currently, `save_idxs` is broken with symbolic stuff (https://github.com/SciML/ModelingToolkit.jl/issues/1761).
211207
let
212208
for (prob, solver) in zip(deepcopy([oprob, sprob, jprob]), [Tsit5(), ImplicitEM(), SSAStepper()])
213209
# Save single variable
@@ -241,10 +237,10 @@ let
241237
@test getu(sol, (XY,Y))(sol)[1] == getu(sol, (model.XY,model.Y))(sol)[1] == getu(sol, (:XY,:Y))(sol)[1] == (9, 5)
242238

243239
# Get u values via idxs and functional call.
244-
@test osol(0.0; idxs=X) == osol(0.0; idxs=X) == osol(0.0; idxs=X) == 4
245-
@test osol(0.0; idxs=XY) == osol(0.0; idxs=XY) == osol(0.0; idxs=XY) == 9
246-
@test_broken osol(0.0; idxs=[model.Y,model.XY]) == osol(0.0; idxs=[model.Y,model.XY]) == osol(0.0; idxs=[model.XY,model.X]) == [9, 5]
247-
@test_broken osol(0.0; idxs=(:Y,:XY)) == osol(0.0; idxs=(:Y,:XY)) == osol(0.0; idxs=(:XY,:Y)) == (9, 5)
240+
@test osol(0.0; idxs=X) == osol(0.0; idxs=model.X) == osol(0.0; idxs=:X) == 4
241+
@test osol(0.0; idxs=XY) == osol(0.0; idxs=model.XY) == osol(0.0; idxs=:XY) == 9
242+
@test osol(0.0; idxs = [XY,Y]) == osol(0.0; idxs = [model.XY,model.Y]) == osol(0.0; idxs = [:XY,:Y]) == [9, 5]
243+
@test_broken osol(0.0; idxs = (XY,Y)) == osol(0.0; idxs = (model.XY,model.Y)) == osol(0.0; idxs = (:XY,:Y)) == (9, 5) # https://github.com/SciML/SciMLBase.jl/issues/711
248244

249245
# Get p values.
250246
@test sol.ps[kp] == sol.ps[model.kp] == sol.ps[:kp] == 1.0
@@ -262,11 +258,11 @@ let
262258
@test sol[X] == sol[model.X] == sol[:X]
263259
@test sol[XY] == sol[model.XY][1] == sol[:XY]
264260
@test sol[[XY,Y]] == sol[[model.XY,model.Y]] == sol[[:XY,:Y]]
265-
@test_broken sol[(XY,Y)] == sol[(model.XY,model.Y)] == sol[(:XY,:Y)]
261+
@test_broken sol[(XY,Y)] == sol[(model.XY,model.Y)] == sol[(:XY,:Y)] # https://github.com/SciML/SciMLBase.jl/issues/710
266262
@test getu(sol, X)(sol) == getu(sol, model.X)(sol)[1] == getu(sol, :X)(sol)
267263
@test getu(sol, XY)(sol) == getu(sol, model.XY)(sol)[1] == getu(sol, :XY)(sol)
268264
@test getu(sol, [XY,Y])(sol) == getu(sol, [model.XY,model.Y])(sol) == getu(sol, [:XY,:Y])(sol)
269-
@test_broken getu(sol, (XY,Y))(sol) == getu(sol, (model.XY,model.Y))(sol) == getu(sol, (:XY,:Y))(sol)[1]
265+
@test_broken getu(sol, (XY,Y))(sol) == getu(sol, (model.XY,model.Y))(sol) == getu(sol, (:XY,:Y))(sol)[1] # https://github.com/SciML/SciMLBase.jl/issues/710
270266

271267
# Get p values.
272268
@test sol.ps[kp] == sol.ps[model.kp] == sol.ps[:kp]
@@ -281,8 +277,7 @@ end
281277

282278
# Tests plotting.
283279
let
284-
@test_broken false # Currently broken for `ssol` (https://github.com/SciML/SciMLBase.jl/issues/580)
285-
for sol in deepcopy([osol, jsol])
280+
for sol in deepcopy([osol, ssol, jsol])
286281
# Single variable.
287282
@test length(plot(sol; idxs = X).series_list) == 1
288283
@test length(plot(sol; idxs = XY).series_list) == 1
@@ -386,4 +381,32 @@ let
386381
@test jint.cb.condition.ma_jumps.scaled_rates[1] == 16.0
387382
reset_aggregated_jumps!(jint)
388383
@test jint.cb.condition.ma_jumps.scaled_rates[1] == 6.0
389-
end
384+
end
385+
386+
387+
388+
389+
using ModelingToolkit, OrdinaryDiffEq
390+
using ModelingToolkit: t_nounits as t, D_nounits as D
391+
392+
@parameters p d
393+
@variables X(t)
394+
@variables Y(t)
395+
eqs = [
396+
D(X) ~ p - d*X,
397+
D(Y) ~ p - d*Y
398+
]
399+
@mtkbuild sys = ODESystem(eqs, t)
400+
401+
u0 = [X => 1.0, Y => 1.0]
402+
tspan = (0.0, 100.0)
403+
ps = [p => 1.0, d => 0.1]
404+
405+
prob = ODEProblem(sys, u0, tspan, ps)
406+
sol = solve(prob)
407+
408+
sol(0.0; idxs=[sys.Y,sys.XY])
409+
sol(0.0; idxs=[sys.Y,sys.XY])
410+
411+
@test_broken osol(0.0; idxs=[model.Y,model.XY]) == osol(0.0; idxs=[model.Y,model.XY]) == osol(0.0; idxs=[model.XY,model.X]) == [9, 5]
412+
@test_broken osol(0.0; idxs=(:Y,:XY)) == osol(0.0; idxs=(:Y,:XY)) == osol(0.0; idxs=(:XY,:Y)) == (9, 5)

0 commit comments

Comments
 (0)