Skip to content

Commit

Permalink
Merge pull request #1050 from SciML/update_dae_tests
Browse files Browse the repository at this point in the history
Fix DAE tests
  • Loading branch information
TorkelE authored Sep 12, 2024
2 parents af5b8c2 + 53019dd commit e3d21b6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions test/compositional_modelling/component_based_model_creation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ let
sys₂.μ => (log(2) / 600), sys₃.α₀ => 5e-4, sys₃.α => 0.5, sys₃.K => 40.0,
sys₃.n => 2, sys₃.δ => (log(2) / 120), sys₃.β => (20 * log(2) / 120),
sys₃.μ => (log(2) / 600)]
u₀ = [sys₁.m => 0.0, sys₁.P => 20.0, sys.R => 0.0, sys.m => 0.0, sys₂.P => 0.0,
sys.R => 0.0, sys.m => 0.0, sys₃.P => 0.0, sys₃.R => 0.0]
u₀ = [sys₁.m => 0.0, sys₁.P => 20.0, sys₂.m => 0.0, sys₂.P => 0.0,
sys₃.m => 0.0, sys₃.P => 0.0]
tspan = (0.0, 100000.0)
oprob = ODEProblem(oderepressilator, u₀, tspan, pvals)
sol = solve(oprob, Tsit5())
Expand Down Expand Up @@ -94,13 +94,15 @@ let
@test all(isapprox.(sol(tvs, idxs = sys₁.P), sol2(tvs, idxs = 4), atol = 1e-4))

# Test conversion to nonlinear system.
u₀_nl = [sys₁.m => 0.0, sys₁.P => 20.0, sys₁.R => 0.0, sys₂.m => 0.0, sys₂.P => 0.0,
sys₂.R => 0.0, sys₃.m => 0.0, sys₃.P => 0.0, sys₃.R => 0.0]
@named nsys = NonlinearSystem(connections, [], [])
@named ssrepressilator = ReactionSystem(t; systems = [nsys, sys₁, sys₂, sys₃])
ssrepressilator = complete(ssrepressilator)
@named nlrepressilator = convert(NonlinearSystem, ssrepressilator, include_zero_odes = false)
sys2 = structural_simplify(nlrepressilator)
@test length(equations(sys2)) <= 6
nlprob = NonlinearProblem(sys2, u₀, pvals)
nlprob = NonlinearProblem(sys2, u₀_nl, pvals)
sol = solve(nlprob, NLSolveJL(), abstol = 1e-9)
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
Expand All @@ -113,7 +115,7 @@ let
@named nlrepressilator = convert(NonlinearSystem, fsys, include_zero_odes = false)
sys2 = structural_simplify(nlrepressilator)
@test length(equations(sys2)) <= 6
nlprob = NonlinearProblem(sys2, u₀, pvals)
nlprob = NonlinearProblem(sys2, u₀_nl, pvals)
sol = solve(nlprob, NLSolveJL(), abstol = 1e-9)
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
Expand All @@ -131,7 +133,7 @@ let
@named nlrepressilator = convert(NonlinearSystem, repressilator2, include_zero_odes = false)
sys2 = structural_simplify(nlrepressilator)
@test length(equations(sys2)) <= 6
nlprob = NonlinearProblem(sys2, u₀, pvals)
nlprob = NonlinearProblem(sys2, u₀_nl, pvals)
sol = solve(nlprob, NLSolveJL(), abstol = 1e-9)
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
Expand Down Expand Up @@ -252,7 +254,7 @@ let
@named nlrepressilator = convert(NonlinearSystem, repressilator2, include_zero_odes = false)
sys2 = structural_simplify(nlrepressilator)
@test length(equations(sys2)) <= 6
nlprob = NonlinearProblem(sys2, u₀, pvals)
nlprob = NonlinearProblem(sys2, u₀_nl, pvals)
sol = solve(nlprob, NLSolveJL(), abstol = 1e-9)
@test sol[sys₁.P] sol[sys₂.P] sol[sys₃.P]
@test sol[sys₁.m] sol[sys₂.m] atol=1e-7
Expand Down
5 changes: 2 additions & 3 deletions test/dsl/dsl_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ let
@test isequal(equations(rn)[4], 3Y + X ~ S + X*d)

# Checks that simulations has the correct output
u0 = Dict([S => 1 + rand(rng), X => 1 + rand(rng), Y => 1 + rand(rng)])
u0 = Dict([S => 1 + rand(rng)])
ps = Dict([p => 1 + rand(rng), d => 1 + rand(rng), k => 1 + rand(rng)])
oprob = ODEProblem(rn, u0, (0.0, 10000.0), ps; structural_simplify=true)
sol = solve(oprob, Tsit5(); abstol=1e-9, reltol=1e-9)
Expand Down Expand Up @@ -895,7 +895,7 @@ let
@test equations(rn)[3] isa Equation

# Checks that simulations has the correct output
u0 = Dict([S => 1 + rand(rng), X => 1 + rand(rng), Y => 1 + rand(rng)])
u0 = Dict([S => 1 + rand(rng), Y => 1 + rand(rng)])
ps = Dict([p => 1 + rand(rng), d => 1 + rand(rng), k => 1 + rand(rng)])
oprob = ODEProblem(rn, u0, (0.0, 10000.0), ps; structural_simplify=true)
sol = solve(oprob, Tsit5(); abstol=1e-9, reltol=1e-9)
Expand Down Expand Up @@ -1025,4 +1025,3 @@ let
@parameters v n
@test isequal(Catalyst.expand_registered_functions(equations(rn4)[1]), D(A) ~ v*(A^n))
end

1 change: 1 addition & 0 deletions test/miscellaneous_tests/reactionsystem_serialisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ let
d, X --> 0, [misc = x -> 2x]
end
@test_throws Exception save_reactionsystem("test_serialisation.jl", rs)
rm("test_serialisation.jl")
end

# Test connection field.
Expand Down

0 comments on commit e3d21b6

Please sign in to comment.