Skip to content

Commit

Permalink
Merge pull request #480 from SciML/myb/test
Browse files Browse the repository at this point in the history
More robust MTK tests
  • Loading branch information
isaacsas authored Feb 14, 2022
2 parents 190e33a + f490749 commit d0601a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Catalyst"
uuid = "479239e8-5488-4da2-87a7-35f2df7eef83"
version = "10.5"
version = "10.5.1"

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

[targets]
test = ["Graphviz_jll", "LinearAlgebra", "NonlinearSolve", "OrdinaryDiffEq", "Random", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "StochasticDiffEq", "Test", "Unitful"]
test = ["Graphviz_jll", "LinearAlgebra", "NonlinearSolve", "OrdinaryDiffEq", "Random", "SafeTestsets", "SciMLNLSolve", "StableRNGs", "Statistics", "SteadyStateDiffEq", "StochasticDiffEq", "Test", "Unitful"]
31 changes: 18 additions & 13 deletions test/reactionsystem_components.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ModelingToolkit, Catalyst, LinearAlgebra, OrdinaryDiffEq, Test, NonlinearSolve
using ModelingToolkit, Catalyst, LinearAlgebra, OrdinaryDiffEq, Test
using SciMLNLSolve

# Repressilator model
@parameters t α₀ α K n δ β μ
Expand Down Expand Up @@ -89,22 +90,24 @@ sol = solve(oprob, Tsit5())
@named ssrepressilator = ReactionSystem(t; systems=[nsys,sys₁,sys₂,sys₃])
@named nlrepressilator = convert(NonlinearSystem, ssrepressilator, include_zero_odes=false)
sys2 = structural_simplify(nlrepressilator)
@test length(equations(sys2)) == 6
@test length(equations(sys2)) <= 6
nlprob = NonlinearProblem(sys2, u₀, pvals)
sol = solve(nlprob, NewtonRaphson(), tol=1e-9)
sol = solve(nlprob, NLSolveJL(), tol=1e-9)
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
@test sol[sys₁.m] sol[sys₂.m] sol[sys₃.m]
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
@test sol[sys₁.m] sol[sys₃.m] atol=1e-7
@test sol[sys₁.R] sol[sys₂.R] sol[sys₃.R]

# flattening
fsys = Catalyst.flatten(ssrepressilator)
@named nlrepressilator = convert(NonlinearSystem, fsys, include_zero_odes=false)
sys2 = structural_simplify(nlrepressilator)
@test length(equations(sys2)) == 6
@test length(equations(sys2)) <= 6
nlprob = NonlinearProblem(sys2, u₀, pvals)
sol = solve(nlprob, NewtonRaphson(), tol=1e-9)
sol = solve(nlprob, NLSolveJL(), tol=1e-9)
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
@test sol[sys₁.m] sol[sys₂.m] sol[sys₃.m]
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
@test sol[sys₁.m] sol[sys₃.m] atol=1e-7
@test sol[sys₁.R] sol[sys₂.R] sol[sys₃.R]

# test constraints
Expand All @@ -115,11 +118,12 @@ connections = [sys₁.R ~ sys₃.P,
@named repressilator2 = ReactionSystem(t; constraints=csys, systems=[sys₁,sys₂,sys₃])
@named nlrepressilator = convert(NonlinearSystem, repressilator2, include_zero_odes=false)
sys2 = structural_simplify(nlrepressilator)
@test length(equations(sys2)) == 6
@test length(equations(sys2)) <= 6
nlprob = NonlinearProblem(sys2, u₀, pvals)
sol = solve(nlprob, NewtonRaphson(), tol=1e-9)
sol = solve(nlprob, NLSolveJL(), tol=1e-9)
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
@test sol[sys₁.m] sol[sys₂.m] sol[sys₃.m]
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
@test sol[sys₁.m] sol[sys₃.m] atol=1e-7
@test sol[sys₁.R] sol[sys₂.R] sol[sys₃.R]

# test constraint system variables are accessible through Base.getproperty
Expand Down Expand Up @@ -232,11 +236,12 @@ repressilator2 = Catalyst.flatten(repressilator2)
repressilator2 = extend(csys, repressilator2)
@named nlrepressilator = convert(NonlinearSystem, repressilator2, include_zero_odes=false)
sys2 = structural_simplify(nlrepressilator)
@test length(equations(sys2)) == 6
@test length(equations(sys2)) <= 6
nlprob = NonlinearProblem(sys2, u₀, pvals)
sol = solve(nlprob, NewtonRaphson(), tol=1e-9)
sol = solve(nlprob, NLSolveJL(), tol=1e-9)
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
@test sol[sys₁.m] sol[sys₂.m] sol[sys₃.m]
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
@test sol[sys₁.m] sol[sys₃.m] atol=1e-7
@test sol[sys₁.R] sol[sys₂.R] sol[sys₃.R]


Expand Down

0 comments on commit d0601a8

Please sign in to comment.