Skip to content

Commit 2abf8e0

Browse files
Merge pull request #4687 from SciML/as/fix-ci
test: make tests less dependent on equation ordering
2 parents 6745da8 + 571bc37 commit 2abf8e0

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

lib/ModelingToolkitBase/test/discrete_system.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ RHS2 = RHS
226226

227227
@variables x(t) y(t) u(t)
228228
if @isdefined(ModelingToolkit)
229-
eqs = [x ~ x(k - 1) + u, u ~ 1, y ~ x + u]
229+
eqs = [x ~ x(k - 1) + u, u ~ 1]
230230
@mtkcompile de = System(eqs, t)
231+
@set! de.observed = [ModelingToolkitBase.get_observed(de); [y ~ x + u]]
232+
de = complete(de)
231233
else
232234
eqs = [x ~ x(k - 1) + u]
233235
@mtkcompile de = System(eqs, t) inputs = [u]

test/initialization_jacobian_analysis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ res = analyze_initialization_jacobian(prob; verbose = false)
2020
# Overdetermined initialization with a redundant equation: two consistent initial
2121
# conditions on a single unknown. The analysis must report a redundant equation.
2222
@variables z(t)
23-
@named sys2 = System([D(z) ~ -z], t; initialization_eqs = [z ~ 1.0, z^2 ~ 1.0])
23+
@named sys2 = System([D(z) ~ -z], t; initialization_eqs = [log(exp(z)) ~ 1.0, z^2 ~ 1.0])
2424
sys2 = mtkcompile(sys2)
2525
prob2 = ODEProblem(sys2, [], (0.0, 1.0); guesses = [z => 0.9],
2626
warn_initialize_determined = false)

test/structural_transformation/index_reduction.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ state = TearingState(pendulum)
2626
@test StructuralTransformations.maximal_matching(
2727
graph, eq -> true,
2828
v -> var_to_diff[v] === nothing
29-
) ==
30-
map(
31-
x -> x == 0 ? StructuralTransformations.unassigned : x,
32-
[3, 4, 2, 5, 0, 0, 0, 0, 0]
33-
)
34-
29+
) == map(state.fullvars) do v
30+
if operation(v) isa Differential
31+
return findfirst(eq -> isequal(eq.lhs, v), equations(state))
32+
end
33+
return StructuralTransformations.unassigned
34+
end
3535
eqs2 = [
3636
D(D(x)) ~ T * x,
3737
D(D(y)) ~ T * y - g,

test/structural_transformation/utils.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ eqs = [
2626
0 ~ x^2 + y^2 - L^2,
2727
]
2828
pendulum = System(eqs, t, [x, y, w, z, T], [L, g], name = :pendulum)
29-
state = TearingState(pendulum)
29+
state = TearingState(pendulum; sort_eqs = false)
3030
StateSelection.find_solvables!(state)
3131
sss = state.structure
3232
@unpack graph, solvable_graph, var_to_diff = sss
33-
@test sort(graph.fadjlist) == [[1, 7], [2, 8], [3, 5, 9], [4, 6, 9], [5, 6]]
33+
sym_incidence = [[D(x), w], [D(y), z], [D(w), T, x], [D(z), T, y], [x, y]]
34+
@test all([issetequal(state.fullvars[v], sym_incidence[i]) for (i, v) in enumerate(graph.fadjlist)])
3435
@test length(graph.badjlist) == 9
3536
@test ne(graph) == nnz(incidence_matrix(graph)) == 12
3637
@test nv(solvable_graph) == 9 + 5

0 commit comments

Comments
 (0)