Skip to content

Commit 90d8f7a

Browse files
committed
create param eval context only once per net
1 parent c40a82f commit 90d8f7a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/massaction_jump_utils.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,18 @@ function get_net_stoich(rs, specmap)
5252
end
5353

5454
# given a ReactionStruct and a species map construct a MassActionJump
55-
function make_majump(rs, specmap, ratemap, params)
55+
function make_majump(rs, specmap, ratemap, params, param_context)
5656
reactant_stoich = get_substrate_stoich(rs, specmap)
5757
net_stoich = get_net_stoich(rs, specmap)
5858
if isempty(net_stoich)
5959
error("Empty net stoichiometry vectors for mass action reactions are not allowed.")
6060
end
6161

62-
# populate dummy context with params as local variables
63-
Dummy = Module()
64-
for (param, index) in ratemap
65-
Base.eval(Dummy, :($param = $(params[index])))
66-
end
67-
6862
if typeof(rs.rate_org) == Symbol
6963
rateconst = params[ratemap[rs.rate_org]]
7064
elseif typeof(rs.rate_org) == Expr
71-
# eval in Dummy, in case Expr depends on params
72-
rateconst = Base.eval(Dummy, rs.rate_org)
65+
# eval in param_context, in case Expr depends on params
66+
rateconst = Base.eval(param_context, rs.rate_org)
7367
elseif typeof(rs.rate_org) <: Number
7468
rateconst = rs.rate_org
7569
else
@@ -86,9 +80,16 @@ function network_to_jumpset(rn, specmap, ratemap, params)
8680
majumpvec = Vector{typeof(empty_majump)}()
8781
cjumpvec = Vector{ConstantRateJump}()
8882

83+
# populate dummy module with params as local variables
84+
# (for eval-ing parameter expressions)
85+
param_context = Module()
86+
for (param, index) in ratemap
87+
Base.eval(param_context, :($param = $(params[index])))
88+
end
89+
8990
for (i,rs) in enumerate(rn.reactions)
9091
if rs.is_pure_mass_action
91-
push!(majumpvec, make_majump(rs, specmap, ratemap, params))
92+
push!(majumpvec, make_majump(rs, specmap, ratemap, params, param_context))
9293
else
9394
push!(cjumpvec, rn.jumps[i])
9495
end

0 commit comments

Comments
 (0)