@@ -223,12 +223,8 @@ function assemble_diffusion(rs, noise_scaling; combinatoric_ratelaws=true)
223
223
eqs
224
224
end
225
225
226
- var2op (var:: Sym ) = var
227
- var2op (var:: Sym{FnType{Tuple{<:Any}, T}} ) where {T} = Sym {FnType{Tuple{}, T}} (nameof (var))()
228
- var2op (var:: Num ) = var2op (value (var))
229
-
230
- function var2op (var:: Term )
231
- Sym {FnType{Tuple{}, symtype(var)}} (nameof (var. op))()
226
+ function var2op (var)
227
+ Operation (var,Vector {Expression} ())
232
228
end
233
229
234
230
# Calculate the Jump rate law (like ODE, but uses X instead of X(t).
@@ -300,16 +296,13 @@ explicitly on the independent variable (usually time).
300
296
- Optional: `stateset`, set of states which if the rxvars are within mean rx is non-mass action.
301
297
"""
302
298
function ismassaction (rx, rs; rxvars = get_variables (rx. rate),
303
- haveivdep,
299
+ haveivdep = any (var -> isequal (rs . iv, convert (Variable,var)), rxvars) ,
304
300
stateset = Set (states (rs)))
305
301
# if no dependencies must be zero order
306
- haveivdep && return false
307
302
(length (rxvars)== 0 ) && return true
308
- rx. only_use_rate && return false
303
+ (haveivdep || rx. only_use_rate) && return false
309
304
@inbounds for i = 1 : length (rxvars)
310
- @show rxvars[i]
311
- @show rxvars[i] in stateset
312
- rxvars[i] in stateset && return false
305
+ (rxvars[i]. op in stateset) && return false
313
306
end
314
307
return true
315
308
end
@@ -327,34 +320,27 @@ end
327
320
# push!(rates, rate)
328
321
net_stoch = [Pair (var2op (p[1 ]),p[2 ]) for p in netstoich]
329
322
# push!(nstoich, net_stoch)
330
-
331
- # XXX : vv--- this sucks
332
- MassActionJump (Num (rate), reactant_stoch, net_stoch, scale_rates= false , useiszero= false )
333
- end
334
-
335
- function _occursin (x, expr)
336
- f = if isequal (x, expr)
337
- true
338
- elseif SymbolicUtils. istree (expr)
339
- _occursin (x, expr. op) || any (ex -> _occursin (x, ex), arguments (expr))
340
- else
341
- false
342
- end
323
+ MassActionJump (rate, reactant_stoch, net_stoch, scale_rates= false , useiszero= false )
343
324
end
344
325
345
326
function assemble_jumps (rs; combinatoric_ratelaws= true )
346
327
meqs = MassActionJump[]; ceqs = ConstantRateJump[]; veqs = VariableRateJump[]
347
328
stateset = Set (states (rs))
348
329
# rates = []; rstoich = []; nstoich = []
349
- rxvars = []
330
+ rxvars = Operation[]
331
+ ivname = rs. iv. name
350
332
351
333
isempty (equations (rs)) && error (" Must give at least one reaction before constructing a JumpSystem." )
352
-
353
- presence_dict = Dict (rs. states .=> 1 )
354
334
for rx in equations (rs)
355
- gradient_sparsity = vec (jacobian_sparsity ([rx. rate], rs. states))
356
- rxvars = rs. states[gradient_sparsity]
357
- haveivdep = _occursin (rs. iv, substitute (rx. rate, presence_dict))
335
+ empty! (rxvars)
336
+ (rx. rate isa Operation) && get_variables! (rxvars, rx. rate)
337
+ haveivdep = false
338
+ @inbounds for i = 1 : length (rxvars)
339
+ if rxvars[i]. op. name == ivname
340
+ haveivdep = true
341
+ break
342
+ end
343
+ end
358
344
if ismassaction (rx, rs; rxvars= rxvars, haveivdep= haveivdep, stateset= stateset)
359
345
push! (meqs, makemajump (rx, combinatoric_ratelaw= combinatoric_ratelaws))
360
346
else
0 commit comments