Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't automatically complete systems on read #167

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mdl = readSBML("my_model.xml", doc -> begin
set_level_and_version(3, 2)(doc)
convert_promotelocals_expandfuns(doc)
end)
rs = ReactionSystem(mdl) # If you want to create a reaction system
rs = complete(ReactionSystem(mdl)) # If you want to create a reaction system
odesys = convert(ODESystem, rs) # Alternatively: ODESystem(mdl)

tspan = (0.0, 1.0)
Expand Down
4 changes: 1 addition & 3 deletions src/systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function SBML.readSBML(sbmlfile::String, ::ODESystemImporter;
include_zero_odes::Bool = true, kwargs...) # Returns an MTK.ODESystem
odesys = convert(ODESystem, readSBML(sbmlfile, ReactionSystemImporter(), kwargs...),
include_zero_odes = include_zero_odes)
complete(odesys)
end

"""
Expand Down Expand Up @@ -96,7 +95,7 @@ function Catalyst.ReactionSystem(model::SBML.Model; kwargs...) # Todo: requires
defaults = defs, name = gensym(:SBML),
continuous_events = get_events(model),
combinatoric_ratelaws = false, kwargs...)
return complete(rs) # Todo: maybe add a `complete=True` kwarg
return rs
end

"""
Expand All @@ -110,7 +109,6 @@ function ModelingToolkit.ODESystem(model::SBML.Model; include_zero_odes::Bool =
kwargs...)
rs = ReactionSystem(model; kwargs...)
odesys = convert(ODESystem, rs; include_zero_odes = include_zero_odes)
complete(odesys)
end

function get_mappings(model::SBML.Model)
Expand Down
14 changes: 7 additions & 7 deletions test/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ end

# Test get_rules
sbml, _, _ = SBMLToolkitTestSuite.read_case("00029") # assignmentRule
m = readmodel(sbml)
m = complete(readmodel(sbml))
a, o, r = SBMLToolkit.get_rules(m)
o_true = [S1 ~ 7 * compartment]
@test isequal(o, o_true)

sbml, _, _ = SBMLToolkitTestSuite.read_case("00031") # rateRule
m = readmodel(sbml)
m = complete(readmodel(sbml))
a, o, r = SBMLToolkit.get_rules(m)
r_true = [default_time_deriv()(S1) ~ 7 * compartment]
@test isequal(r, r_true)

sbml, _, _ = SBMLToolkitTestSuite.read_case("00039") # algebraicRule
m = readmodel(sbml)
m = complete(readmodel(sbml))
a, o, r = SBMLToolkit.get_rules(m)
a_true = [0 ~ S1 + S2 - k1]
@test isequal(a, a_true)

# Test get_var_and_assignment
sbml, _, _ = SBMLToolkitTestSuite.read_case("00031")
m = readmodel(sbml)
m = complete(readmodel(sbml))
var, assignment = SBMLToolkit.get_var_and_assignment(m, m.rules[1])
var_true = S1
assignment_true = 7 * compartment
Expand All @@ -55,20 +55,20 @@ vc = SBMLToolkit.get_volume_correction(m, "S1")
@test isequal(vc, "compartment")

sbml, _, _ = SBMLToolkitTestSuite.read_case("00060") # hOSU="true" species
m = readmodel(sbml)
m = complete(readmodel(sbml))
vc = SBMLToolkit.get_volume_correction(m, "S1")
@test isnothing(vc)

# tests that non-constant parameters become variables
sbml, _, _ = SBMLToolkitTestSuite.read_case("00033")
m = readmodel(sbml)
m = complete(readmodel(sbml))
@named sys = ODESystem(m)
@species k1(IV)
@test isequal(k1, unknowns(sys)[end])

# tests that non-constant compartments become variables
sbml, _, _ = SBMLToolkitTestSuite.read_case("00051") # hOSU="true" species
m = readmodel(sbml)
m = complete(readmodel(sbml))
@named sys = ODESystem(m)
@species C(IV)
@test isequal(C, unknowns(sys)[end])
6 changes: 3 additions & 3 deletions test/wuschel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ m = readSBMLFromString(sbml, doc -> begin
# set_level_and_version(3, 2)(doc) # fails on wuschel
convert_promotelocals_expandfuns(doc)
end)
sys = ODESystem(m)
sys = ODESystem(complete(m))
@test length(equations(sys)) == 1012
@test length(unknowns(sys)) == 1012
#ssys = structural_simplify(sys) # Todo: Figure out why this complains about ExtraVariablesSystemException
prob = ODEProblem(sys, [], (0, 10.0))
ssys = structural_simplify(sys) # Todo: Figure out why this complains about ExtraVariablesSystemException
prob = ODEProblem(ssys, [], (0, 10.0))
solve(prob, Tsit5(), save_everystep = false)
Loading