Skip to content

Commit

Permalink
Merge pull request #974 from SciML/tests___update___mtk_indexing_tests
Browse files Browse the repository at this point in the history
Update upstream mtk tests
  • Loading branch information
TorkelE authored Jul 7, 2024
2 parents caf6cbb + 9f69a96 commit 33254f3
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 381 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SciMLNLSolve = "e9a6253c-8580-4d32-9898-8661bb511710"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
Expand All @@ -84,4 +85,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[targets]
test = ["BifurcationKit", "DiffEqCallbacks", "DomainSets", "Graphviz_jll", "HomotopyContinuation", "Logging", "NonlinearSolve", "OrdinaryDiffEq", "Plots", "Random", "SafeTestsets", "SciMLBase", "SciMLNLSolve", "StableRNGs", "Statistics", "SteadyStateDiffEq", "StochasticDiffEq", "StructuralIdentifiability", "Test", "Unitful"]
test = ["BifurcationKit", "DiffEqCallbacks", "DomainSets", "Graphviz_jll", "HomotopyContinuation", "Logging", "NonlinearSolve", "OrdinaryDiffEq", "Plots", "Random", "SafeTestsets", "SciMLBase", "SciMLNLSolve", "StableRNGs", "StaticArrays", "Statistics", "SteadyStateDiffEq", "StochasticDiffEq", "StructuralIdentifiability", "Test", "Unitful"]
36 changes: 19 additions & 17 deletions test/extensions/homotopy_continuation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,32 @@ let
u0 = [:X1 => 2.0, :X2 => 2.0, :X3 => 2.0, :X2_2X3 => 2.0]

# Computes the single steady state, checks that when given to the ODE rhs, all are evaluated to 0.
hc_ss = hc_steady_states(rs, ps; u0=u0, show_progress=false)
hc_ss = hc_steady_states(rs, ps; u0 = u0, show_progress = false, seed = 0x000004d1)
hc_ss = Pair.(unknowns(rs), hc_ss[1])
@test maximum(abs.(f_eval(rs, hc_ss, ps, 0.0))) 0.0 atol=1e-12
@test maximum(abs.(f_eval(rs, hc_ss, ps, 0.0))) 0.0 atol = 1e-12

# Checks that not giving a `u0` argument yields an error for systems with conservation laws.
@test_throws Exception hc_steady_states(rs, ps; show_progress=false)
@test_throws Exception hc_steady_states(rs, ps; show_progress = false)
end

# Tests for network with multiple steady state.
# Tests for Symbol parameter input.
# Tests that passing kwargs to HC.solve does not error.
# Tests that passing kwargs to HC.solve does not error and have an effect (i.e. modifying the seed
# slightly modified the output in some way).
let
wilhelm_2009_model = @reaction_network begin
k1, Y --> 2X
k2, 2X --> X + Y
k3, X + Y --> Y
k4, X --> 0
end
ps = [:k3 => 1.0, :k2 => 2.0, :k4 => 1.5, :k1=>8.0]
ps = [:k3 => 1.0, :k2 => 2.0, :k4 => 1.5, :k1 => 8.0]

hc_ss_1 = hc_steady_states(wilhelm_2009_model, ps; seed=0x000004d1, show_progress=false)
@test sort(hc_ss_1, by=sol->sol[1]) [[0.0, 0.0], [0.5, 2.0], [4.5, 6.0]]
hc_ss_1 = hc_steady_states(wilhelm_2009_model, ps; seed = 0x000004d1, show_progress = false)
@test sort(hc_ss_1, by = sol->sol[1]) [[0.0, 0.0], [0.5, 2.0], [4.5, 6.0]]

hc_ss_2 = hc_steady_states(wilhelm_2009_model, ps; seed=0x000004d2, show_progress=false)
hc_ss_3 = hc_steady_states(wilhelm_2009_model, ps; seed=0x000004d2, show_progress=false)
hc_ss_2 = hc_steady_states(wilhelm_2009_model, ps; seed = 0x000004d2, show_progress = false)
hc_ss_3 = hc_steady_states(wilhelm_2009_model, ps; seed = 0x000004d2, show_progress = false)
@test hc_ss_1 != hc_ss_2
@test hc_ss_2 == hc_ss_3
end
Expand All @@ -69,7 +70,7 @@ let
ps = (:kY1 => 1.0, :kY2 => 3, :kZ1 => 1.0, :kZ2 => 4.0)
u0_1 = (:Y1 => 1.0, :Y2 => 3, :Z1 => 10, :Z2 =>40.0)

ss_1 = sort(hc_steady_states(rs_1, ps; u0=u0_1, show_progress=false), by=sol->sol[1])
ss_1 = sort(hc_steady_states(rs_1, ps; u0 = u0_1, show_progress = false, seed = 0x000004d1), by = sol->sol[1])
@test ss_1 [[0.2, 0.1, 3.0, 1.0, 40.0, 10.0]]

rs_2 = @reaction_network begin
Expand All @@ -81,7 +82,7 @@ let
end
u0_2 = [:B2 => 1.0, :B1 => 3.0, :A2 => 10.0, :A1 =>40.0]

ss_2 = sort(hc_steady_states(rs_2, ps; u0=u0_2, show_progress=false), by=sol->sol[1])
ss_2 = sort(hc_steady_states(rs_2, ps; u0 = u0_2, show_progress = false, seed = 0x000004d1), by = sol->sol[1])
@test ss_1 ss_2
end

Expand All @@ -96,14 +97,15 @@ let
d, X --> 0
end
ps = [:v => 5.0, :K => 2.5, :n => 3, :d => 1.0]
sss = hc_steady_states(rs, ps; filter_negative=false, show_progress=false)
sss = hc_steady_states(rs, ps; filter_negative = false, show_progress = false, seed = 0x000004d1)

@test length(sss) == 4
for ss in sss
@test f_eval(rs,sss[1], last.(ps), 0.0)[1] 0.0 atol=1e-12
@test f_eval(rs,sss[1], last.(ps), 0.0)[1] 0.0 atol = 1e-12
end

@test_throws Exception hc_steady_states(rs, [:v => 5.0, :K => 2.5, :n => 2.7, :d => 1.0]; show_progress=false)
ps = [:v => 5.0, :K => 2.5, :n => 2.7, :d => 1.0]
@test_throws Exception hc_steady_states(rs, ps; show_progress = false, seed = 0x000004d1)
end


Expand All @@ -124,7 +126,7 @@ let

# Checks that homotopy continuation correctly find the system's single steady state.
ps = [:p => 2.0, :d => 1.0, :k => 5.0]
hc_ss = hc_steady_states(rs, ps)
hc_ss = hc_steady_states(rs, ps; show_progress = false, seed = 0x000004d1)
@test hc_ss [[2.0, 0.2, 10.0]]
end

Expand All @@ -137,7 +139,7 @@ let
p_start = [:p => 1.0, :d => 0.2]

# Computes bifurcation diagram.
@test_throws Exception hc_steady_states(incomplete_network, p_start)
@test_throws Exception hc_steady_states(incomplete_network, p_start; show_progress = false, seed = 0x000004d1)
end

# Tests that non-autonomous system throws an error
Expand All @@ -146,5 +148,5 @@ let
(k,t), 0 <--> X
end
ps = [:k => 1.0]
@test_throws Exception hc_steady_states(rs, ps)
@test_throws Exception hc_steady_states(rs, ps; show_progress = false, seed = 0x000004d1)
end
14 changes: 8 additions & 6 deletions test/extensions/structural_identifiability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ end
### Other Tests ###

# Checks that identifiability can be assessed for coupled CRN/DAE systems.
# `remove_conserved = false` is used to remove info print statement from log.
let
rs = @reaction_network begin
@parameters k c1 c2
Expand All @@ -329,19 +330,20 @@ let
@unpack p, d, k, c1, c2 = rs

# Tests identifiability assessment when all unknowns are measured.
gi_1 = assess_identifiability(rs; measured_quantities = [:X, :V, :C], loglevel)
li_1 = assess_local_identifiability(rs; measured_quantities = [:X, :V, :C], loglevel)
ifs_1 = find_identifiable_functions(rs; measured_quantities = [:X, :V, :C], loglevel)
remove_conserved = false
gi_1 = assess_identifiability(rs; measured_quantities = [:X, :V, :C], loglevel, remove_conserved)
li_1 = assess_local_identifiability(rs; measured_quantities = [:X, :V, :C], loglevel, remove_conserved)
ifs_1 = find_identifiable_functions(rs; measured_quantities = [:X, :V, :C], loglevel, remove_conserved)
@test sym_dict(gi_1) == Dict([:X => :globally, :C => :globally, :V => :globally, :k => :globally,
:c1 => :nonidentifiable, :c2 => :nonidentifiable, :p => :globally, :d => :globally])
@test sym_dict(li_1) == Dict([:X => 1, :C => 1, :V => 1, :k => 1, :c1 => 0, :c2 => 0, :p => 1, :d => 1])
@test issetequal(ifs_1, [d, p, k, c1 + c2])

# Tests identifiability assessment when only variables are measured.
# Checks that a parameter in an equation can be set as known.
gi_2 = assess_identifiability(rs; measured_quantities = [:V, :C], known_p = [:c1], loglevel)
li_2 = assess_local_identifiability(rs; measured_quantities = [:V, :C], known_p = [:c1], loglevel)
ifs_2 = find_identifiable_functions(rs; measured_quantities = [:V, :C], known_p = [:c1], loglevel)
gi_2 = assess_identifiability(rs; measured_quantities = [:V, :C], known_p = [:c1], loglevel, remove_conserved)
li_2 = assess_local_identifiability(rs; measured_quantities = [:V, :C], known_p = [:c1], loglevel, remove_conserved)
ifs_2 = find_identifiable_functions(rs; measured_quantities = [:V, :C], known_p = [:c1], loglevel, remove_conserved)
@test sym_dict(gi_2) == Dict([:X => :nonidentifiable, :C => :globally, :V => :globally, :k => :nonidentifiable,
:c1 => :globally, :c2 => :nonidentifiable, :p => :nonidentifiable, :d => :globally])
@test sym_dict(li_2) == Dict([:X => 0, :C => 1, :V => 1, :k => 0, :c1 => 1, :c2 => 0, :p => 0, :d => 1])
Expand Down
2 changes: 1 addition & 1 deletion test/simulation_and_solving/solve_nonlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let
# Creates NonlinearProblem.
u0 = [steady_state_network_3.X => rand(), steady_state_network_3.Y => rand() + 1.0, steady_state_network_3.Y2 => rand() + 3.0, steady_state_network_3.XY2 => 0.0]
p = [:p => rand()+1.0, :d => 0.5, :k1 => 1.0, :k2 => 2.0, :k3 => 3.0, :k4 => 4.0]
nl_prob_1 = NonlinearProblem(steady_state_network_3, u0, p; remove_conserved = true)
nl_prob_1 = NonlinearProblem(steady_state_network_3, u0, p; remove_conserved = true, remove_conserved_warn = false)
nl_prob_2 = NonlinearProblem(steady_state_network_3, u0, p)

# Solves it using standard algorithm and simulation based algorithm.
Expand Down
Loading

0 comments on commit 33254f3

Please sign in to comment.