1
- using ModelingToolkit, Catalyst, LinearAlgebra, OrdinaryDiffEq, Test, NonlinearSolve
1
+ using ModelingToolkit, Catalyst, LinearAlgebra, OrdinaryDiffEq, Test
2
+ using SciMLNLSolve
2
3
3
4
# Repressilator model
4
5
@parameters t α₀ α K n δ β μ
@@ -89,22 +90,24 @@ sol = solve(oprob, Tsit5())
89
90
@named ssrepressilator = ReactionSystem (t; systems= [nsys,sys₁,sys₂,sys₃])
90
91
@named nlrepressilator = convert (NonlinearSystem, ssrepressilator, include_zero_odes= false )
91
92
sys2 = structural_simplify (nlrepressilator)
92
- @test length (equations (sys2)) = = 6
93
+ @test length (equations (sys2)) < = 6
93
94
nlprob = NonlinearProblem (sys2, u₀, pvals)
94
- sol = solve (nlprob, NewtonRaphson (), tol= 1e-9 )
95
+ sol = solve (nlprob, NLSolveJL (), tol= 1e-9 )
95
96
@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
97
99
@test sol[sys₁. R] ≈ sol[sys₂. R] ≈ sol[sys₃. R]
98
100
99
101
# flattening
100
102
fsys = Catalyst. flatten (ssrepressilator)
101
103
@named nlrepressilator = convert (NonlinearSystem, fsys, include_zero_odes= false )
102
104
sys2 = structural_simplify (nlrepressilator)
103
- @test length (equations (sys2)) = = 6
105
+ @test length (equations (sys2)) < = 6
104
106
nlprob = NonlinearProblem (sys2, u₀, pvals)
105
- sol = solve (nlprob, NewtonRaphson (), tol= 1e-9 )
107
+ sol = solve (nlprob, NLSolveJL (), tol= 1e-9 )
106
108
@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
108
111
@test sol[sys₁. R] ≈ sol[sys₂. R] ≈ sol[sys₃. R]
109
112
110
113
# test constraints
@@ -115,11 +118,12 @@ connections = [sys₁.R ~ sys₃.P,
115
118
@named repressilator2 = ReactionSystem (t; constraints= csys, systems= [sys₁,sys₂,sys₃])
116
119
@named nlrepressilator = convert (NonlinearSystem, repressilator2, include_zero_odes= false )
117
120
sys2 = structural_simplify (nlrepressilator)
118
- @test length (equations (sys2)) = = 6
121
+ @test length (equations (sys2)) < = 6
119
122
nlprob = NonlinearProblem (sys2, u₀, pvals)
120
- sol = solve (nlprob, NewtonRaphson (), tol= 1e-9 )
123
+ sol = solve (nlprob, NLSolveJL (), tol= 1e-9 )
121
124
@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
123
127
@test sol[sys₁. R] ≈ sol[sys₂. R] ≈ sol[sys₃. R]
124
128
125
129
# test constraint system variables are accessible through Base.getproperty
@@ -232,11 +236,12 @@ repressilator2 = Catalyst.flatten(repressilator2)
232
236
repressilator2 = extend (csys, repressilator2)
233
237
@named nlrepressilator = convert (NonlinearSystem, repressilator2, include_zero_odes= false )
234
238
sys2 = structural_simplify (nlrepressilator)
235
- @test length (equations (sys2)) = = 6
239
+ @test length (equations (sys2)) < = 6
236
240
nlprob = NonlinearProblem (sys2, u₀, pvals)
237
- sol = solve (nlprob, NewtonRaphson (), tol= 1e-9 )
241
+ sol = solve (nlprob, NLSolveJL (), tol= 1e-9 )
238
242
@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
240
245
@test sol[sys₁. R] ≈ sol[sys₂. R] ≈ sol[sys₃. R]
241
246
242
247
0 commit comments