Skip to content

Commit 36e56b7

Browse files
committed
Revert "lowered names"
This reverts commit ba30991.
1 parent 8faf740 commit 36e56b7

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

src/build_function.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,6 @@ end
478478
function term_to_symbol(t::Term)
479479
if operation(t) isa Sym
480480
s = nameof(operation(t))
481-
elseif operation(t) isa Differential
482-
Symbol("var", repr(t))
483481
else
484482
error("really?")
485483
end

src/systems/diffeqs/first_order_transform.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
function lower_varname(var::Term, idv, order)
2-
D = Differential(idv)
3-
term = var
4-
for _ in 1:order
5-
term = D(term)
6-
end
7-
return term
2+
order == 0 && return var
3+
name = Symbol(nameof(var.op), , string(idv)^order)
4+
#name = Symbol(var.name, :ˍ, string(idv.name)^order)
5+
return Sym{symtype(var.op)}(name)(var.args[1])
86
end
97

108
function flatten_differential(O::Term)

src/systems/reaction/reactionsystem.jl

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,8 @@ function assemble_diffusion(rs, noise_scaling; combinatoric_ratelaws=true)
223223
eqs
224224
end
225225

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}())
232228
end
233229

234230
# 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).
300296
- Optional: `stateset`, set of states which if the rxvars are within mean rx is non-mass action.
301297
"""
302298
function ismassaction(rx, rs; rxvars = get_variables(rx.rate),
303-
haveivdep,
299+
haveivdep = any(var -> isequal(rs.iv,convert(Variable,var)), rxvars),
304300
stateset = Set(states(rs)))
305301
# if no dependencies must be zero order
306-
haveivdep && return false
307302
(length(rxvars)==0) && return true
308-
rx.only_use_rate && return false
303+
(haveivdep || rx.only_use_rate) && return false
309304
@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
313306
end
314307
return true
315308
end
@@ -327,34 +320,27 @@ end
327320
#push!(rates, rate)
328321
net_stoch = [Pair(var2op(p[1]),p[2]) for p in netstoich]
329322
#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)
343324
end
344325

345326
function assemble_jumps(rs; combinatoric_ratelaws=true)
346327
meqs = MassActionJump[]; ceqs = ConstantRateJump[]; veqs = VariableRateJump[]
347328
stateset = Set(states(rs))
348329
#rates = []; rstoich = []; nstoich = []
349-
rxvars = []
330+
rxvars = Operation[]
331+
ivname = rs.iv.name
350332

351333
isempty(equations(rs)) && error("Must give at least one reaction before constructing a JumpSystem.")
352-
353-
presence_dict = Dict(rs.states .=> 1)
354334
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
358344
if ismassaction(rx, rs; rxvars=rxvars, haveivdep=haveivdep, stateset=stateset)
359345
push!(meqs, makemajump(rx, combinatoric_ratelaw=combinatoric_ratelaws))
360346
else

0 commit comments

Comments
 (0)