Skip to content

Commit 0dea1b1

Browse files
committed
Merge remote-tracking branch 'origin/hc_extension' into hc_extension
2 parents fe979ed + aa0ab4c commit 0dea1b1

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

docs/src/catalyst_applications/homotopy_continuation.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ two_state_model = @reaction_network begin
5050
(k1,k2), X1 <--> X2
5151
end
5252
```
53-
To find the steady states of these, an initial condition must also be provided (which is used to compute the system's conserved quantities, in this case `X1+X2`):
53+
Catalyst allows the conservation laws of such systems to be computed using the `conservationlaws` function. By using these to reduce the dimensionality of the system, as well specifying the initial amount of each species, HomotopyContinuation can again be used to find steady states. To find the steady states using the Catalyst interface to HomotopyContinuation, an initial condition must be provided (which is used to compute the system's conserved quantities, in this case `X1+X2`):
5454
```@example hc3
5555
ps = [:k1 => 2.0, :k2 => 1.0]
5656
u0 = [:X1 => 1.0, :X2 => 1.0]
57-
hc_steady_states(wilhelm_2009_model, ps; u0=u0)
57+
hc_steady_states(wilhelm_2009_model, ps; u0)
58+
5859
```
5960

6061
## Final notes
61-
- `hc_steady_states` supports any systems where all rates are systems of rational polynomial (such as hill functions with integer hill coefficients).
62+
- `hc_steady_states` supports any systems where all rates are systems of rational polynomials (such as Hill functions with integer Hill coefficients).
63+
6264
- Additional arguments provided to `hc_steady_states` are automatically passed to HomotopyContinuation's `solve` command. Use e.g. `show_progress=false` to disable the progress bar.
6365
---
6466

ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
hc_steady_states(rs::ReactionSystem, ps; filter_negative=true, neg_thres=-1e-20, u0=typeof(ps)(), kwargs...)
55
6-
Uses homotopy continuation to find the steady states of the ODE system corresponding to the provided reaction system.
6+
Uses homotopy continuation via HomotopyContinuation.jl to find the steady states of the ODE system corresponding to the provided reaction system.
77
88
Arguments:
99
- `rs::ReactionSystem`: The reaction system for which we want to find the steady states.
@@ -32,14 +32,13 @@ gives
3232
```
3333
3434
Notes:
35-
- This is a wrapper around the `solve` function provided by HomotopyContinuation.jl, all credit for this functionality to that package's authors.
3635
```
3736
"""
3837
function Catalyst.hc_steady_states(rs::ReactionSystem, ps; filter_negative=true, neg_thres=-1e-20, u0=typeof(ps)(), kwargs...)
3938
ss_poly = steady_state_polynomial(rs, ps, u0)
4039
sols = HC.real_solutions(HC.solve(ss_poly; kwargs...))
4140
reorder_sols!(sols, ss_poly, rs)
42-
return (filter_negative ? filter_negative_f(sols; neg_thres=neg_thres) : sols)
41+
return (filter_negative ? filter_negative_f(sols; neg_thres) : sols)
4342
end
4443

4544
# For a given reaction system, paraemter values, and initial conditions, find the polynomial that HC solves to find steady states.
@@ -58,10 +57,11 @@ end
5857

5958
# If u0s are not given while conservation laws are present, throws an error.
6059
function conservationlaw_errorcheck(rs, pre_varmap)
61-
vars_with_vals = union(first.(pre_varmap), keys(ModelingToolkit.defaults(rs)))
62-
isempty(intersect(species(rs), vars_with_vals)) || return
63-
isempty(conservedequations(rs)) && return
64-
error("The system have conservation laws but no initial conditions were provided. Please provide initial conditions.")
60+
vars_with_vals = Set(p[1] for p in pre_varpmap)
61+
union!(vars_with_vals, keys(ModelingToolkit.defaults(rs))
62+
issubset(species(rs), vars_with_vals) && return
63+
isempty(conservedequations(rs)) ||
64+
error("The system has conservation laws but initial conditions were not provided for all species.")
6565
end
6666

6767
# Unfolds a function (like mm or hill).
@@ -118,7 +118,7 @@ end
118118
# Filters away solutions with negative species concentrations (and for neg_thres < val < 0.0, sets val=0.0).
119119
function filter_negative_f(sols; neg_thres=-1e-20)
120120
for sol in sols, idx in 1:length(sol)
121-
(neg_thres < sol[idx] < 0.0) && (sol[idx] = 0.0)
121+
(neg_thres < sol[idx] < 0) && (sol[idx] = 0)
122122
end
123-
return filter(sol -> all(>=(0.0), sol), sols)
123+
return filter(sol -> all(>=(0), sol), sols)
124124
end

0 commit comments

Comments
 (0)