Skip to content

Commit d0601a8

Browse files
authored
Merge pull request #480 from SciML/myb/test
More robust MTK tests
2 parents 190e33a + f490749 commit d0601a8

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Catalyst"
22
uuid = "479239e8-5488-4da2-87a7-35f2df7eef83"
3-
version = "10.5"
3+
version = "10.5.1"
44

55
[deps]
66
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
@@ -41,6 +41,7 @@ NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
4141
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
4242
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
4343
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
44+
SciMLNLSolve = "e9a6253c-8580-4d32-9898-8661bb511710"
4445
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
4546
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
4647
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
@@ -49,4 +50,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4950
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
5051

5152
[targets]
52-
test = ["Graphviz_jll", "LinearAlgebra", "NonlinearSolve", "OrdinaryDiffEq", "Random", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "StochasticDiffEq", "Test", "Unitful"]
53+
test = ["Graphviz_jll", "LinearAlgebra", "NonlinearSolve", "OrdinaryDiffEq", "Random", "SafeTestsets", "SciMLNLSolve", "StableRNGs", "Statistics", "SteadyStateDiffEq", "StochasticDiffEq", "Test", "Unitful"]

test/reactionsystem_components.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ModelingToolkit, Catalyst, LinearAlgebra, OrdinaryDiffEq, Test, NonlinearSolve
1+
using ModelingToolkit, Catalyst, LinearAlgebra, OrdinaryDiffEq, Test
2+
using SciMLNLSolve
23

34
# Repressilator model
45
@parameters t α₀ α K n δ β μ
@@ -89,22 +90,24 @@ sol = solve(oprob, Tsit5())
8990
@named ssrepressilator = ReactionSystem(t; systems=[nsys,sys₁,sys₂,sys₃])
9091
@named nlrepressilator = convert(NonlinearSystem, ssrepressilator, include_zero_odes=false)
9192
sys2 = structural_simplify(nlrepressilator)
92-
@test length(equations(sys2)) == 6
93+
@test length(equations(sys2)) <= 6
9394
nlprob = NonlinearProblem(sys2, u₀, pvals)
94-
sol = solve(nlprob, NewtonRaphson(), tol=1e-9)
95+
sol = solve(nlprob, NLSolveJL(), tol=1e-9)
9596
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
96-
@test sol[sys₁.m] sol[sys₂.m] sol[sys₃.m]
97+
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
98+
@test sol[sys₁.m] sol[sys₃.m] atol=1e-7
9799
@test sol[sys₁.R] sol[sys₂.R] sol[sys₃.R]
98100

99101
# flattening
100102
fsys = Catalyst.flatten(ssrepressilator)
101103
@named nlrepressilator = convert(NonlinearSystem, fsys, include_zero_odes=false)
102104
sys2 = structural_simplify(nlrepressilator)
103-
@test length(equations(sys2)) == 6
105+
@test length(equations(sys2)) <= 6
104106
nlprob = NonlinearProblem(sys2, u₀, pvals)
105-
sol = solve(nlprob, NewtonRaphson(), tol=1e-9)
107+
sol = solve(nlprob, NLSolveJL(), tol=1e-9)
106108
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
107-
@test sol[sys₁.m] sol[sys₂.m] sol[sys₃.m]
109+
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
110+
@test sol[sys₁.m] sol[sys₃.m] atol=1e-7
108111
@test sol[sys₁.R] sol[sys₂.R] sol[sys₃.R]
109112

110113
# test constraints
@@ -115,11 +118,12 @@ connections = [sys₁.R ~ sys₃.P,
115118
@named repressilator2 = ReactionSystem(t; constraints=csys, systems=[sys₁,sys₂,sys₃])
116119
@named nlrepressilator = convert(NonlinearSystem, repressilator2, include_zero_odes=false)
117120
sys2 = structural_simplify(nlrepressilator)
118-
@test length(equations(sys2)) == 6
121+
@test length(equations(sys2)) <= 6
119122
nlprob = NonlinearProblem(sys2, u₀, pvals)
120-
sol = solve(nlprob, NewtonRaphson(), tol=1e-9)
123+
sol = solve(nlprob, NLSolveJL(), tol=1e-9)
121124
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
122-
@test sol[sys₁.m] sol[sys₂.m] sol[sys₃.m]
125+
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
126+
@test sol[sys₁.m] sol[sys₃.m] atol=1e-7
123127
@test sol[sys₁.R] sol[sys₂.R] sol[sys₃.R]
124128

125129
# test constraint system variables are accessible through Base.getproperty
@@ -232,11 +236,12 @@ repressilator2 = Catalyst.flatten(repressilator2)
232236
repressilator2 = extend(csys, repressilator2)
233237
@named nlrepressilator = convert(NonlinearSystem, repressilator2, include_zero_odes=false)
234238
sys2 = structural_simplify(nlrepressilator)
235-
@test length(equations(sys2)) == 6
239+
@test length(equations(sys2)) <= 6
236240
nlprob = NonlinearProblem(sys2, u₀, pvals)
237-
sol = solve(nlprob, NewtonRaphson(), tol=1e-9)
241+
sol = solve(nlprob, NLSolveJL(), tol=1e-9)
238242
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
239-
@test sol[sys₁.m] sol[sys₂.m] sol[sys₃.m]
243+
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
244+
@test sol[sys₁.m] sol[sys₃.m] atol=1e-7
240245
@test sol[sys₁.R] sol[sys₂.R] sol[sys₃.R]
241246

242247

0 commit comments

Comments
 (0)