Skip to content

Commit d14ad58

Browse files
committed
up
1 parent fd4543d commit d14ad58

File tree

2 files changed

+8
-46
lines changed

2 files changed

+8
-46
lines changed

ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ gives
3232
```
3333
3434
Notes:
35+
- Homotopy-based steady state finding only works when all rates are rational polynomials (e.g. constant, linear, mm, or hill functions).
3536
```
3637
"""
3738
function Catalyst.hc_steady_states(rs::ReactionSystem, ps; filter_negative=true, neg_thres=-1e-20, u0=[], kwargs...)
@@ -42,8 +43,9 @@ function Catalyst.hc_steady_states(rs::ReactionSystem, ps; filter_negative=true,
4243
end
4344

4445
# For a given reaction system, parameter values, and initial conditions, find the polynomial that HC solves to find steady states.
45-
function steady_state_polynomial(rs::ReactionSystem, ps, u0)
46-
ns = convert(NonlinearSystem, rs; remove_conserved = true, expand_functions = true)
46+
function steady_state_polynomial(rs_in::ReactionSystem, ps, u0)
47+
rs = ModelingToolkit.@set rs_in.rxs = [expand_registered_functions(rx) for rx in rn.rxs]
48+
ns = convert(NonlinearSystem, rs; remove_conserved = true)
4749
pre_varmap = [symmap_to_varmap(rs,u0)..., symmap_to_varmap(rs,ps)...]
4850
conservationlaw_errorcheck(rs, pre_varmap)
4951
p_vals = ModelingToolkit.varmap_to_vars(pre_varmap, parameters(ns); defaults = ModelingToolkit.defaults(ns))
@@ -102,27 +104,4 @@ function filter_negative_f(sols; neg_thres=-1e-20)
102104
(neg_thres < sol[idx] < 0) && (sol[idx] = 0)
103105
end
104106
return filter(sol -> all(>=(0), sol), sols)
105-
end
106-
107-
### Archived ###
108-
109-
# # Unfolds a function (like mm or hill).
110-
# function deregister(fs::Vector{T}, expr) where T
111-
# for f in fs
112-
# expr = deregister(f, expr)
113-
# end
114-
# return expr
115-
# end
116-
# # Provided by Shashi Gowda.
117-
# deregister(f, expr) = wrap(Rewriters.Postwalk(Rewriters.PassThrough(___deregister(f)))(unwrap(expr)))
118-
# function ___deregister(f)
119-
# (expr) ->
120-
# if istree(expr) && operation(expr) == f
121-
# args = arguments(expr)
122-
# invoke_with = map(args) do a
123-
# t = typeof(a)
124-
# issym(a) || istree(a) ? wrap(a) => symtype(a) : a => typeof(a)
125-
# end
126-
# invoke(f, Tuple{last.(invoke_with)...}, first.(invoke_with)...)
127-
# end
128-
# end
107+
end

src/reactionsystem.jl

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,6 @@ struct ReactionSystem{V <: NetworkProperties} <:
538538
checks && validate(rs)
539539
rs
540540
end
541-
542-
# Copies a reaction system, but with the option of having some fields replaced
543-
function ReactionSystem(rs::ReactionSystem; eqs = rs.eqs, rxs = rs.rxs, iv = rs.iv, sivs = rs.sivs, states = rs.states, species = rs.species, ps = rs.ps, var_to_name = rs.var_to_name, observed = rs.observed, name = rs.name, systems = rs.systems, defaults = rs.defaults, connection_type = rs.connection_type, networkproperties = rs.networkproperties, combinatoric_ratelaws = rs.combinatoric_ratelaws, continuous_events = rs.continuous_events, discrete_events = rs.discrete_events, complete = rs.complete)
544-
new{typeof(networkproperties)}(eqs, rxs, ModelingToolkit.unwrap(iv), ModelingToolkit.unwrap.(sivs), ModelingToolkit.unwrap.(states), ModelingToolkit.unwrap.(species), ModelingToolkit.unwrap.(ps), var_to_name, observed, name, systems, defaults, connection_type, networkproperties, combinatoric_ratelaws, continuous_events, discrete_events, complete)
545-
end
546541
end
547542

548543
function get_speciestype(iv, states, systems)
@@ -1292,17 +1287,14 @@ Keyword args and default values:
12921287
function Base.convert(::Type{<:ODESystem}, rs::ReactionSystem; name = nameof(rs),
12931288
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
12941289
include_zero_odes = true, remove_conserved = false, checks = false,
1295-
expand_functions = false, kwargs...)
1290+
kwargs...)
12961291
spatial_convert_err(rs::ReactionSystem, ODESystem)
12971292
fullrs = Catalyst.flatten(rs)
12981293
remove_conserved && conservationlaws(fullrs)
12991294
ists, ispcs = get_indep_sts(fullrs, remove_conserved)
13001295
eqs = assemble_drift(fullrs, ispcs; combinatoric_ratelaws, remove_conserved,
13011296
include_zero_odes)
13021297
eqs, sts, ps, obs, defs = addconstraints!(eqs, fullrs, ists, ispcs; remove_conserved)
1303-
1304-
# Converts expressions like mm(X,v,K) to v*X/(X+K).
1305-
expand_functions && (eqs = [eq.lhs ~ expand_registered_functions!(eq.rhs) for eq in eqs])
13061298

13071299
ODESystem(eqs, get_iv(fullrs), sts, ps;
13081300
observed = obs,
@@ -1334,7 +1326,7 @@ Keyword args and default values:
13341326
function Base.convert(::Type{<:NonlinearSystem}, rs::ReactionSystem; name = nameof(rs),
13351327
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
13361328
include_zero_odes = true, remove_conserved = false, checks = false,
1337-
expand_functions = false, kwargs...)
1329+
kwargs...)
13381330
spatial_convert_err(rs::ReactionSystem, NonlinearSystem)
13391331
fullrs = Catalyst.flatten(rs)
13401332
remove_conserved && conservationlaws(fullrs)
@@ -1344,9 +1336,6 @@ function Base.convert(::Type{<:NonlinearSystem}, rs::ReactionSystem; name = name
13441336
error_if_constraint_odes(NonlinearSystem, fullrs)
13451337
eqs, sts, ps, obs, defs = addconstraints!(eqs, fullrs, ists, ispcs; remove_conserved)
13461338

1347-
# Converts expressions like mm(X,v,K) to v*X/(X+K).
1348-
expand_functions && (eqs = [eq.lhs ~ expand_registered_functions!(eq.rhs) for eq in eqs])
1349-
13501339
NonlinearSystem(eqs, sts, ps;
13511340
name,
13521341
observed = obs,
@@ -1386,7 +1375,7 @@ function Base.convert(::Type{<:SDESystem}, rs::ReactionSystem;
13861375
noise_scaling = nothing, name = nameof(rs),
13871376
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
13881377
include_zero_odes = true, checks = false, remove_conserved = false,
1389-
expand_functions = false, kwargs...)
1378+
kwargs...)
13901379
spatial_convert_err(rs::ReactionSystem, SDESystem)
13911380

13921381
flatrs = Catalyst.flatten(rs)
@@ -1412,12 +1401,6 @@ function Base.convert(::Type{<:SDESystem}, rs::ReactionSystem;
14121401
eqs, sts, ps, obs, defs = addconstraints!(eqs, flatrs, ists, ispcs; remove_conserved)
14131402
ps = (noise_scaling === nothing) ? ps : vcat(ps, toparam(noise_scaling))
14141403

1415-
# Converts expressions like mm(X,v,K) to v*X/(X+K).
1416-
if expand_functions
1417-
eqs = [eq.lhs ~ expand_registered_functions!(eq.rhs) for eq in eqs]
1418-
noiseeqs = [expand_registered_functions!(neq) for neq in noiseeqs]
1419-
end
1420-
14211404
if any(isbc, get_states(flatrs))
14221405
@info "Boundary condition species detected. As constraint equations are not currently supported when converting to SDESystems, the resulting system will be undetermined. Consider using constant species instead."
14231406
end

0 commit comments

Comments
 (0)