Skip to content

Commit 06cad10

Browse files
Merge pull request #1048 from AayushSabharwal/as/fix-downstream
test: make ensemble multi prob test independent of variable order
2 parents e071cac + 28e99e0 commit 06cad10

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

test/downstream/ensemble_multi_prob.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ModelingToolkit, OrdinaryDiffEq, Test
2+
using SymbolicIndexingInterface
23
using ModelingToolkit: t_nounits as t, D_nounits as D
34
@variables x(t), y(t)
45

@@ -16,10 +17,12 @@ prob3 = ODEProblem(sys3, [3.0, 3.0], (0.0, 1.0))
1617
# test that when passing a vector of problems, trajectories and the prob_func are chosen appropriately
1718
ensemble_prob = EnsembleProblem([prob1, prob2, prob3])
1819
sol = solve(ensemble_prob, Tsit5(), EnsembleThreads())
20+
xidx = variable_index(sys1, x)
21+
yidx = variable_index(sys1, y)
1922
for i in 1:3
20-
@test sol[1, :, i] == sol.u[i][x]
21-
@test sol[2, :, i] == sol.u[i][y]
23+
@test sol[xidx, :, i] == sol.u[i][x]
24+
@test sol[yidx, :, i] == sol.u[i][y]
2225
end
2326
# Ensemble is a recursive array
24-
@test only.(sol(0.0, idxs = [x])) == sol[1, 1, :]
25-
@test only.(sol(1.0, idxs = [x])) [sol[i][1, end] for i in 1:3]
27+
@test only.(sol(0.0, idxs = [x])) == sol[xidx, 1, :]
28+
@test only.(sol(1.0, idxs = [x])) [sol[i][xidx, end] for i in 1:3]

test/downstream/solution_interface.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ prob = ODEProblem(sys, [u0; p], tspan)
103103
sol = solve(prob, Rodas4())
104104

105105
@test_throws ArgumentError sol[x]
106-
@test in(sol[lorenz1.x], [getindex.(sol.u, 1) for i in 1:length(unknowns(sol.prob.f.sys))])
106+
@test in(sol[lorenz1.x], [getindex.(sol.u, i) for i in 1:length(unknowns(sol.prob.f.sys))])
107107
@test_throws KeyError sol[:x]
108108

109109
### Non-symbolic indexing tests
@@ -331,13 +331,14 @@ end
331331
@test _idxs == [1]
332332
@test _ss isa SciMLBase.SavedSubsystem
333333
_idxs, _ss = SciMLBase.get_save_idxs_and_saved_subsystem(prob, x)
334-
@test _idxs == 1
334+
xidx = variable_index(prob, x)
335+
@test _idxs == xidx
335336
@test _ss isa SciMLBase.SavedSubsystem
336337
_idxs, _ss = SciMLBase.get_save_idxs_and_saved_subsystem(prob, [x])
337-
@test _idxs == [1]
338+
@test _idxs == [xidx]
338339
@test _ss isa SciMLBase.SavedSubsystem
339340
_idxs, _ss = SciMLBase.get_save_idxs_and_saved_subsystem(prob, [x, q])
340-
@test _idxs == [1]
341+
@test _idxs == [xidx]
341342
@test _ss isa SciMLBase.SavedSubsystem
342343
_idxs, _ss = SciMLBase.get_save_idxs_and_saved_subsystem(prob, [q])
343344
@test _idxs == Int[]

0 commit comments

Comments
 (0)