Skip to content

Commit 783cd9a

Browse files
committed
updates
1 parent 0dea1b1 commit 783cd9a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Uses homotopy continuation via HomotopyContinuation.jl to find the steady states
88
Arguments:
99
- `rs::ReactionSystem`: The reaction system for which we want to find the steady states.
1010
- `ps`: The parameter values for which we want to find the steady states.
11-
- `filter_negative=true`: If set to true, solutions with any species concentration <0 is removed from the output.
11+
- `filter_negative=true`: If set to true, solutions with any species concentration <neg_thres is removed from the output.
1212
- `neg_thres=-1e-20`: Determine the minimum values for which a species concentration is to be considred non-negative. Species conentrations ``> neg_thres`` but `< 0.0` are set to `0.0`.
13-
- `u0=typeof(ps)()`: Initial conditions for which we want to find the steady states. For systems with conservation laws this are required to compute conserved quantities.
13+
- `u0=nothing`: Initial conditions for which we want to find the steady states. For systems with conservation laws this are required to compute conserved quantities.
1414
- `kwargs...`: any additional arguments (like `show_progress= true`) are passed into HomotopyContinuation.jl's `solve` call.
1515
1616
Examples
@@ -34,7 +34,7 @@ gives
3434
Notes:
3535
```
3636
"""
37-
function Catalyst.hc_steady_states(rs::ReactionSystem, ps; filter_negative=true, neg_thres=-1e-20, u0=typeof(ps)(), kwargs...)
37+
function Catalyst.hc_steady_states(rs::ReactionSystem, ps; filter_negative=true, neg_thres=-1e-20, u0=nothing, kwargs...)
3838
ss_poly = steady_state_polynomial(rs, ps, u0)
3939
sols = HC.real_solutions(HC.solve(ss_poly; kwargs...))
4040
reorder_sols!(sols, ss_poly, rs)
@@ -44,7 +44,7 @@ end
4444
# For a given reaction system, paraemter values, and initial conditions, find the polynomial that HC solves to find steady states.
4545
function steady_state_polynomial(rs::ReactionSystem, ps, u0)
4646
ns = convert(NonlinearSystem, rs; remove_conserved = true)
47-
pre_varmap = map(pair -> pair::Pair{Num,Float64}, [symmap_to_varmap(rs,u0); symmap_to_varmap(rs,ps)])
47+
pre_varmap = map(pair -> pair, [symmap_to_varmap(rs,u0); symmap_to_varmap(rs,ps)])
4848
conservationlaw_errorcheck(rs, pre_varmap)
4949
p_vals = ModelingToolkit.varmap_to_vars(pre_varmap, parameters(ns); defaults = ModelingToolkit.defaults(ns))
5050
p_dict = Dict(parameters(ns) .=> p_vals)
@@ -58,7 +58,6 @@ end
5858
# If u0s are not given while conservation laws are present, throws an error.
5959
function conservationlaw_errorcheck(rs, pre_varmap)
6060
vars_with_vals = Set(p[1] for p in pre_varpmap)
61-
union!(vars_with_vals, keys(ModelingToolkit.defaults(rs))
6261
issubset(species(rs), vars_with_vals) && return
6362
isempty(conservedequations(rs)) ||
6463
error("The system has conservation laws but initial conditions were not provided for all species.")
@@ -89,8 +88,12 @@ end
8988
make_int_exps(expr) = wrap(Rewriters.Postwalk(Rewriters.PassThrough(___make_int_exps))(unwrap(expr))).val
9089
function ___make_int_exps(expr)
9190
!istree(expr) && return expr
92-
if (operation(expr) == ^) && isinteger(arguments(expr)[2])
93-
return arguments(expr)[1] ^ Int64(arguments(expr)[2])
91+
if (operation(expr) == ^)
92+
if isinteger(arguments(expr)[2])
93+
return arguments(expr)[1] ^ Int64(arguments(expr)[2])
94+
else
95+
error("An non integer ($(arguments(expr)[2])) was found as a variable exponent. Non-integer exponents are not supported for homotopy continuation based steady state finding.")
96+
end
9497
end
9598
end
9699

test/extensions/homotopy_continuation.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ end
7979
# Tests that non-scalar reaction rates work.
8080
# Tests that rational polynomial steady state systems work.
8181
# Test filter_negative=false works.
82+
# tests than non-integer exponents throws an error.
8283
let
8384
rs = @reaction_network begin
8485
0.1 + hill(X,v,K,n), 0 --> X
@@ -92,4 +93,6 @@ let
9293
for ss in sss
9394
@test f(sss[1], last.(ps), 0.0)[1] == 0.0
9495
end
96+
97+
@test_throws Exception hc_steady_states(rs, [:v => 5.0, :K => 2.5, :n => 2.7, :d => 1.0]; show_progress=false)
9598
end

0 commit comments

Comments
 (0)