Skip to content

Commit

Permalink
Merge pull request #47 from sebapersson/Refactor_tests
Browse files Browse the repository at this point in the history
Refactor tests
  • Loading branch information
sebapersson authored May 23, 2024
2 parents 4b45cc0 + 7ef46f7 commit e9c833b
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 297 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ The key differences between SBMLToolkit and SBMLImporter are:

## Supported SBML Features

SBMLImporter supports many SBML features for SBML models (level 2 or higher). Currently, excluding FBA models, it successfully passes 1257 out of 1785 test cases. The failed test cases cover features currently not supported. If SBMLImporter lacks support for a feature you would like, please file an issue on GitHub. Currently unsupported features are:
SBMLImporter supports many SBML features for SBML models (level 2 or higher). Currently, excluding FBA models, it successfully passes 1265 out of 1785 test cases. The failed test cases cover features currently not supported. If SBMLImporter lacks support for a feature you would like, please file an issue on GitHub. Currently unsupported features are:

* Models with empty SBML reactions.
* Delay (creating a delay-differential-equations).
* Events with delay.
* Events with priority.
Expand Down
3 changes: 1 addition & 2 deletions docs/src/Support.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [Supported SBML Features](@id support)

SBMLImporter supports many SBML features for models of level 2 or higher. Currently, excluding FBA models it successfully passes 1257 out of 1785 test cases. The failed test cases cover features currently not supported. Key features supported include:
SBMLImporter supports many SBML features for models of level 2 or higher. Currently, excluding FBA models it successfully passes 1265 out of 1785 test cases. The failed test cases cover features currently not supported. Key features supported include:

- Events.
- Rate rules.
Expand All @@ -17,7 +17,6 @@ Species can be specified in either concentrations or amounts. The unit is determ

Currently SBMLImporter does not support the following features:

* Models with empty SBML reactions.
* Delay (creating a delay-differential-equations).
* Events with delay.
* Events with priority.
Expand Down
3 changes: 3 additions & 0 deletions src/Build_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function build_SBML_model(path_SBML::String; ifelse_to_callback::Bool = true,
model_as_string = true, inline_assignment_rules::Bool = true,
mass_action::Bool = false)::ModelSBML
if model_as_string == false
if !isfile(path_SBML)
throw(SBMLSupport("$path_SBML is not the path to a SBML file"))
end
f = open(path_SBML, "r")
model_str = read(f, String)
close(f)
Expand Down
13 changes: 7 additions & 6 deletions test/Large_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sbml_string = String(take!(Downloads.download(sbml_url, IOBuffer())))
b1 = @elapsed parsed_rn, cb = load_SBML(sbml_string; model_as_string = true)

# Usually takes around 4s locally, but better to brace for GitHub CI
@test b1 20
@test b1 40

# Large fceri-γ model with ≈ 58,000 reactions. Should take around 4min locally, but it
# is always good to brace for GitHub CI
Expand All @@ -24,17 +24,18 @@ b2 = @elapsed parsed_rn, cb = load_SBML(path_SBML)

# Test that SBMLImporter correctly enforces mass action
path_SBML = joinpath(@__DIR__, "Models", "egfr_net.xml")
b3 = @elapsed model, cb = load_SBML(path_SBML; mass_action=true)
dprob = DiscreteProblem(model.rn, model.u₀, (0.0,0.0), model.p)
b3 = @elapsed model, cb = load_SBML(path_SBML; mass_action = true)
dprob = DiscreteProblem(model.rn, model.u₀, (0.0, 0.0), model.p)
dprob = remake(dprob, u0 = Int64.(dprob.u0));
jprob = JumpProblem(model.rn, dprob, RSSA(), save_positions=(false,false))
jprob = JumpProblem(model.rn, dprob, RSSA(), save_positions = (false, false))
@test b3 20
@test length(jprob.massaction_jump.net_stoch) == 3749

# Lots of edge cases
sbml_url = "https://www.ebi.ac.uk/biomodels/model/download/BIOMD0000000627.3?filename=BIOMD0000000627_url.xml"
sbml_string = String(take!(Downloads.download(sbml_url, IOBuffer())))
mdl, cb = load_SBML(sbml_string; inline_assignment_rules=true, ifelse_to_callback=true, check_massaction=false,
model_as_string=true)
mdl, cb = load_SBML(sbml_string; inline_assignment_rules = true, ifelse_to_callback = true,
check_massaction = false,
model_as_string = true)
sys = structural_simplify(convert(ODESystem, mdl.rn))
@test length(states(sys)) == 66
371 changes: 118 additions & 253 deletions test/Semantic_tests.jl

Large diffs are not rendered by default.

34 changes: 4 additions & 30 deletions test/Stochastic_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,7 @@ using Downloads
using Catalyst
using JumpProcesses

function get_sbml_urls(base_url::String)
levels = ["2", "3"]
sublevels = ["1", "2", "3", "4", "5"]
sbml_urls = Vector{String}(undef, 0)

for level in levels
for sublevel in sublevels
sbml_url = base_url * "-sbml-l" * level * "v" * sublevel * ".xml"
try
sbml = String(take!(Downloads.download(sbml_url, IOBuffer())))
push!(sbml_urls, sbml_url)
catch
end
end
end
return sbml_urls
end

function get_model_str(test_case)
base_url = "https://raw.githubusercontent.com/sbmlteam/sbml-test-suite/master/cases/stochastic/$test_case/$test_case"
sbml_urls = get_sbml_urls(base_url)
sbml_url = sbml_urls[end]
sbml_string = String(take!(Downloads.download(sbml_url, IOBuffer())))
model_SBML = SBMLImporter.build_SBML_model(sbml_string, model_as_string = true)
reaction_system = SBMLImporter.reactionsystem_from_SBML(model_SBML, "", false)
return reaction_system, model_SBML
end
include(joinpath(@__DIR__, "common.jl"))

function read_settings(settings_url::String)
settings = String(take!(Downloads.download(settings_url, IOBuffer())))
Expand Down Expand Up @@ -132,16 +106,16 @@ end
@testset "Stochastic tests" begin
for i in 1:39

# 19 has assignment rule
# 33 has continious callback
# 19 has assignment rule
# 33 has continous callback
if i [19, 33]
continue
end

@info "Test case $i"
test_case = repeat("0", 5 - length(string(i))) * string(i)

# i = 5 nast test case were many simulations must be run to get a
# i = 5 nast test case were many simulations must be run to get a
# good mean estimate (as amounts are large)
if i == 5
test_stochastic_testcase(test_case; nsolve = 70000)
Expand Down
6 changes: 3 additions & 3 deletions test/Write_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ isfile(path_model) && rm(path_model)
isfile(path_cb) && rm(path_cb)

path_SBML = joinpath(@__DIR__, "Models", "model_Boehm_JProteomeRes2014.xml")
parsed_rn, cb = load_SBML(path_SBML; write_to_file=true)
parsed_rn, cb = load_SBML(path_SBML; write_to_file = true)
sys_ref = structural_simplify(convert(ODESystem, parsed_rn.rn))
oprob_ref = ODEProblem(sys_ref, parsed_rn.u₀, (0.0, 5.0), parsed_rn.p, jac = true)
sol_ref = solve(oprob_ref, Rodas4P(), saveat=1:5)
sol_ref = solve(oprob_ref, Rodas4P(), saveat = 1:5)

include(path_model)
include(path_cb)

rn, u0map, pmap = get_reaction_system([])
sys_check = structural_simplify(convert(ODESystem, rn))
oprob_check = ODEProblem(sys_ref, u0map, (0.0, 5.0), pmap, jac = true)
sol_check = solve(oprob_check, Rodas4P(), saveat=1:5)
sol_check = solve(oprob_check, Rodas4P(), saveat = 1:5)

@test oprob_check.u0 == oprob_ref.u0
@test oprob_check.p == oprob_ref.p
Expand Down
32 changes: 32 additions & 0 deletions test/common.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function get_sbml_urls(base_url::String)
levels = ["2", "3"]
sublevels = ["1", "2", "3", "4", "5"]
sbml_urls = Vector{String}(undef, 0)
for level in levels
for sublevel in sublevels
sbml_url = base_url * "-sbml-l" * level * "v" * sublevel * ".xml"
try
sbml = String(take!(Downloads.download(sbml_url, IOBuffer())))
push!(sbml_urls, sbml_url)
catch
end
end
end
return sbml_urls
end

# Function to get model-str
function get_model_str(test_case)
base_url = "https://raw.githubusercontent.com/sbmlteam/sbml-test-suite/master/cases/semantic/$test_case/$test_case"
sbml_urls = get_sbml_urls(base_url)
sbml_url = sbml_urls[end]
sbml_string = String(take!(Downloads.download(sbml_url, IOBuffer())))
model_SBML = SBMLImporter.build_SBML_model(sbml_string, model_as_string = true,
inline_assignment_rules = false)

parsed_model_SBML = SBMLImporter._reactionsystem_from_SBML(model_SBML)
model_str = SBMLImporter.reactionsystem_to_string(parsed_model_SBML, false, "",
model_SBML)

return model_str, model_SBML
end
2 changes: 1 addition & 1 deletion test/curated_jump_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sol_catalyst = solve(jprob_catalyst, SSAStepper(); seed = 1234)
# Catalyst mass-action format
path_SBML = joinpath(@__DIR__, "Models", "brusselator.xml")
parsed_rn1, cb1 = load_SBML(path_SBML)
parsed_rn2, cb2 = load_SBML(path_SBML; check_massaction=false)
parsed_rn2, cb2 = load_SBML(path_SBML; check_massaction = false)
@test reactions(parsed_rn1.rn)[1].only_use_rate == false
@test reactions(parsed_rn2.rn)[1].only_use_rate == true
oprob1 = ODEProblem(parsed_rn1.rn, parsed_rn1.u0, (0.0, 10.0), parsed_rn1.p)
Expand Down

0 comments on commit e9c833b

Please sign in to comment.