Skip to content

Commit 8ca157c

Browse files
authored
Merge pull request #171 from SciML/pl/fix_is_event_assignment
add test for is_event_assignment
2 parents ce6a898 + 20a5430 commit 8ca157c

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SBMLToolkit"
22
uuid = "86080e66-c8ac-44c2-a1a0-9adaadfe4a4e"
33
authors = ["paulflang", "anandijain"]
4-
version = "0.1.29"
4+
version = "0.1.30"
55

66
[deps]
77
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"

src/drafts.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function is_event_assignment(k, model)
2-
for ev in values(model.events)
2+
for ev in last.(model.events)
33
for as in ev.event_assignments
44
if as.variable == k
55
return true

src/systems.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,21 @@ function Catalyst.ReactionSystem(model::SBML.Model; kwargs...) # Todo: requires
8787
# Dict(Catalyst.DEFAULT_IV.val => 0)))
8888
push!(raterules_subs, rhs ~ o.lhs)
8989
end
90+
zero_rates = []
91+
for (k, v) in merge(model.parameters, model.compartments)
92+
if is_event_assignment(k, model)
93+
if v.constant
94+
ErrorException("$k appears in event assignment but should be constant.")
95+
end
96+
push!(zero_rates, D(create_var(k, IV; isbcspecies = true)) ~ 0)
97+
end
98+
end
9099
if haskey(kwargs, :defaults)
91100
defs = ModelingToolkit._merge(defs, kwargs[:defaults])
92101
kwargs = filter(x -> !isequal(first(x), :defaults), kwargs)
93102
end
94-
rs = ReactionSystem([rxs..., algrules..., raterules_subs..., obsrules_rearranged...],
103+
rs = ReactionSystem(
104+
[rxs..., algrules..., raterules_subs..., obsrules_rearranged..., zero_rates...],
95105
IV, first.(u0map), first.(parammap);
96106
defaults = defs, name = gensym(:SBML),
97107
continuous_events = get_events(model),

test/simresults.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const case_ids = [7, # boundary_condition
88
140, # compartment size overridden with assignmentRule
99
170, # Model using parameters and rules only
1010
325, # One reactions and two rate rules with four species in a 2D compartment
11-
679 # Initial value calculated by assignmentRule in compartment of non-unit size # 1208, # Non-hOSU species with rateRule in variable compartment -> require MTK fix.
11+
679, # Initial value calculated by assignmentRule in compartment of non-unit size # 1208, # Non-hOSU species with rateRule in variable compartment -> require MTK fix.
12+
944 # Non-constant parameter as target of event_assignment
1213
]
1314

1415
const logdir = joinpath(@__DIR__, "logs")

0 commit comments

Comments
 (0)