Skip to content

Commit e35caf7

Browse files
authored
Merge pull request #48 from ChrisRackauckas/patch-1
Check Catalyst 13
2 parents 0e89f6f + c3ca652 commit e35caf7

35 files changed

+333
-419
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/" # Location of package manifests
6+
schedule:
7+
interval: "weekly"

.github/workflows/Documentation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1515
- uses: julia-actions/setup-julia@latest
1616
with:
1717
version: '1'
@@ -20,5 +20,5 @@ jobs:
2020
- name: Build and deploy
2121
env:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
23-
#DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
23+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
2424
run: julia --project=docs/ docs/make.jl

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
arch:
1717
- x64
1818
steps:
19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v3
2020
- uses: julia-actions/setup-julia@v1
2121
with:
2222
version: ${{ matrix.version }}
2323
arch: ${{ matrix.arch }}
24-
- uses: actions/cache@v1
24+
- uses: actions/cache@v3
2525
env:
2626
cache-name: cache-artifacts
2727
with:
@@ -34,6 +34,6 @@ jobs:
3434
- uses: julia-actions/julia-buildpkg@v1
3535
- uses: julia-actions/julia-runtest@v1
3636
- uses: julia-actions/julia-processcoverage@v1
37-
- uses: codecov/codecov-action@v1
37+
- uses: codecov/codecov-action@v3
3838
with:
3939
file: lcov.info

Project.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MomentClosure"
22
uuid = "01a1b25a-ecf0-48c5-ae58-55bfd5393600"
33
authors = ["Augustinas Sukys"]
4-
version = "0.2.0"
4+
version = "0.3.0"
55

66
[deps]
77
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"
@@ -19,17 +19,17 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1919
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
2020

2121
[compat]
22-
Catalyst = "11, 12"
22+
Catalyst = "13"
2323
Combinatorics = "1"
2424
Cumulants = "1"
2525
DataStructures = "0.18"
26-
Distributions = "0.23, 0.24, 0.25"
26+
Distributions = "0.25"
2727
DocStringExtensions = "0.8, 0.9"
28-
Latexify = "0.15.14"
29-
ModelingToolkit = "6.5, 7, 8"
28+
Latexify = "0.15.14, 0.16"
29+
ModelingToolkit = "8"
3030
SciMLBase = "1.8.3"
31-
SymbolicUtils = "0.19"
32-
Symbolics = "3, 4"
31+
SymbolicUtils = "1"
32+
Symbolics = "5"
3333
TupleTools = "1.2.0"
3434
julia = "1.6"
3535

docs/src/assets/derivative_matching_cumulant.svg

Lines changed: 41 additions & 128 deletions
Loading

docs/src/tutorials/LMA_example.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@ using Catalyst
2020
# how the nonlinear reactions are to be transformed using LMA
2121

2222
rn_nonlinear = @reaction_network begin
23+
@parameters σ_b σ_u ρ_b ρ_u
2324
σ_b, g + p 0
2425
σ_u*(1-g), 0 g + p
2526
ρ_u, g g + p
2627
ρ_b*(1-g), 0 p
2728
1, p 0
28-
end σ_b σ_u ρ_b ρ_u
29+
end
2930

3031
rn_linear = @reaction_network begin
32+
@parameters σ_b_LMA σ_u ρ_b ρ_u
3133
σ_b_LMA, g 0 # typing ̄σ_b is not allowed it seems
3234
σ_u*(1-g), 0 g
3335
ρ_u, g g+p
3436
(ρ_b*(1-g)), 0 p
3537
1, p 0
36-
end σ_b_LMA σ_u ρ_b ρ_u
38+
end
3739
```
3840
We can now apply the LMA to find the effective parameter $\bar{σ}_b$ and generate the corresponding moment equations of the linear GRN using MomentClosure's [`linear_mapping_approximation`](@ref):
3941
```julia
@@ -45,7 +47,7 @@ using MomentClosure
4547
@variables g(t)
4648
binary_vars = [speciesmap(rn_nonlinear)[g]]
4749

48-
LMA_eqs, effective_params = linear_mapping_approximation(rn_nonlinear, rn_linear, binary_vars, combinatoric_ratelaw=false)
50+
LMA_eqs, effective_params = linear_mapping_approximation(rn_nonlinear, rn_linear, binary_vars, combinatoric_ratelaws=false)
4951
display(effective_params)
5052
```
5153
```julia
@@ -79,7 +81,7 @@ u₀map = deterministic_IC(u₀, LMA_eqs)
7981
oprob_LMA = ODEProblem(LMA_eqs, u₀map, tspan, p)
8082
sol_LMA = solve(oprob_LMA, CVODE_BDF(), saveat=dt)
8183

82-
plot(sol_LMA, vars=(0, [2]), label="LMA", ylabel="⟨p⟩", xlabel="time", fmt="svg")
84+
plot(sol_LMA, idxs=[2], label="LMA", ylabel="⟨p⟩", xlabel="time", fmt="svg")
8385
```
8486
![LMA feedback loop mean protein number](../assets/LMA_feedback_loop_mean_protein_number.svg)
8587

@@ -141,11 +143,12 @@ As pointed out by the authors in [1], a more efficient way is to expand the gene
141143
However, TaylorSeries only supports elementary function operations at the time and hence evaluating the Kummer's function $M(\cdot,\cdot,\cdot)$ requires some more work (these specialised numerics are readily available in more established scientific computing frameworks such as Mathematica but there's no fun in that). We can extend the TaylorSeries framework by constructing a function `t_pFq` that implements a recurrence relation between the Taylor coefficients for the generalized hypergeometric function `pFq` as defined in [HypergeometricFunctions.jl](https://github.com/JuliaMath/HypergeometricFunctions.jl). This can be done as follows (note that our construction is valid only for a single-variable Taylor series [`Taylor1`](https://juliadiff.org/TaylorSeries.jl/stable/api/#TaylorSeries.Taylor1)):
142144
```julia
143145
using TaylorSeries, HypergeometricFunctions
146+
using HypergeometricFunctions: pFqweniger
144147

145148
# please let me know if a simpler and more efficient way to do this exists!
146149
function t_pFq::AbstractVector, β::AbstractVector, a::Taylor1)
147150
order = a.order
148-
aux = pFq(α, β, constant_term(a))
151+
aux = pFqweniger(α, β, constant_term(a))
149152
c = Taylor1(aux, order)
150153

151154
iszero(order) && return c
@@ -170,13 +173,13 @@ oprob_LMA = remake(oprob_LMA, tspan=tspan)
170173
sol_LMA = solve(oprob_LMA, CVODE_BDF(), saveat=dt)
171174

172175
# rebuild the symbolic expression for the effective parameter as a function of raw moments
173-
μ_sym = LMA_eqs.odes.states
174-
p_sub = Pair.(LMA_eqs.odes.ps, p)
176+
μ_sym = [LMA_eqs.odes.states...]
177+
p_sub = Dict.(Pair.(LMA_eqs.odes.ps, p)...)
175178
avg_σ_b_sym = collect(values(effective_params))[1]
176179
fn = build_function(substitute(avg_σ_b_sym, p_sub), μ_sym)
177180
avg_σ_b = eval(fn)
178181
# evaluate the time-averaged value of the effective parameter
179-
σ_b_avg = sum(avg_σ_b.(sol_LMA[:])) * dt / T
182+
@time σ_b_avg = sum(avg_σ_b.(sol_LMA.u)) * dt / T
180183
```
181184
We proceed with the very last steps of the LMA to obtain the probability distribution:
182185
```julia

docs/src/tutorials/P53_system_example.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,22 @@ with parameters
4040

4141
We begin by loading all the packages we will need
4242
```julia
43-
using Catalyst, MomentClosure, OrdinaryDiffEq, DiffEqJump,
43+
using Catalyst, MomentClosure, OrdinaryDiffEq, JumpProcesses,
4444
DiffEqBase.EnsembleAnalysis, Plots, Plots.PlotMeasures
4545
```
4646
and then build the model using Catalyst and set its parameters as follows:
4747
```julia
4848
# → for mass-actions rate
4949
# ⇒ for non mass-actions rate
5050
rn = @reaction_network begin
51+
@parameters k₁ k₂ k₃ k₄ k₅ k₆ k₇
5152
(k₁), 0 x
5253
(k₂), x 0
5354
(k₃*x*y/(x+k₇)), x 0
5455
(k₄*x), 0 y₀
5556
(k₅), y₀ y
5657
(k₆), y 0
57-
end k₁ k₂ k₃ k₄ k₅ k₆ k₇
58+
end
5859

5960
# parameters [k₁, k₂, k₃, k₄, k₅, k₆, k₇]
6061
p = [90, 0.002, 1.7, 1.1, 0.93, 0.96, 0.01]
@@ -106,7 +107,7 @@ h2 = histogram(data[2], normalize=true, xlabel="y₀", ylabel="P(y₀)")
106107
h3 = histogram(data[3], normalize=true, xlabel="y", ylabel="P(y)")
107108
using Plots.PlotMeasures
108109
plot(h1, h2, h3, legend=false, layout=(1,3), size = (1050, 250),
109-
left_margin = 5mm, bottom_margin = 7mm, guidefontsize=10)
110+
left_margin = 5PlotMeasures.mm, bottom_margin = 7PlotMeasures.mm, guidefontsize=10)
110111
```
111112
![P53-Mdm2 distribution](../assets/p53-Mdm2_distribution.svg)
112113

@@ -120,15 +121,15 @@ closures = ["normal", "log-normal", "gamma"]
120121
plts = [plot() for i in 1:length(closures)]
121122

122123
for q in 3:6
123-
eqs = generate_central_moment_eqs(rn, 2, q, combinatoric_ratelaw=false)
124+
eqs = generate_central_moment_eqs(rn, 2, q, combinatoric_ratelaws=false)
124125
for (closure, plt) in zip(closures, plts)
125126
closed_eqs = moment_closure(eqs, closure)
126127

127128
u₀map = deterministic_IC(u₀, closed_eqs)
128129
oprob = ODEProblem(closed_eqs, u₀map, tspan, p)
129130

130131
sol = solve(oprob, Tsit5(), saveat=0.1)
131-
plt = plot!(plt, sol, vars=(0, 1), lw=3, label = "q = "*string(q))
132+
plt = plot!(plt, sol, idxs=[1], lw=3, label = "q = "*string(q))
132133
end
133134
end
134135

@@ -139,13 +140,13 @@ end
139140
```
140141
Normal closure:
141142
```julia
142-
plot(plts[1], size=(750, 450), leftmargin=2mm)
143+
plot(plts[1], size=(750, 450), leftmargin=2PlotMeasures.mm)
143144
```
144145
![P53-Mdm2 normal means 2nd order expansion](../assets/p53-Mdm2_normal_2nd_order.svg)
145146

146147
Log-normal closure:
147148
```julia
148-
plot(plts[2], size=(750, 450), leftmargin=2mm)
149+
plot(plts[2], size=(750, 450), leftmargin=2PlotMeasures.mm)
149150
```
150151
![P53-Mdm2 log-normal means 2nd order expansion](../assets/p53-Mdm2_log-normal_2nd_order.svg)
151152

@@ -157,7 +158,7 @@ plot(plts[2], xlims=(0., 50.), lw=3)
157158

158159
Gamma closure:
159160
```julia
160-
plot(plts[3], size=(750, 450), leftmargin=2mm)
161+
plot(plts[3], size=(750, 450), leftmargin=2PlotMeasures.mm)
161162
```
162163
![P53-Mdm2 gamma means 2nd order expansion](../assets/p53-Mdm2_gamma_2nd_order.svg)
163164

@@ -168,7 +169,7 @@ We can also plot the variance predictions:
168169
# rerunning the same calculations as they are reasonably fast
169170
plt = plot()
170171
for q in [4,6]
171-
eqs = generate_central_moment_eqs(rn, 2, q, combinatoric_ratelaw=false)
172+
eqs = generate_central_moment_eqs(rn, 2, q, combinatoric_ratelaws=false)
172173
for closure in closures
173174
closed_eqs = moment_closure(eqs, closure)
174175

@@ -177,7 +178,7 @@ for q in [4,6]
177178
sol = solve(oprob, Tsit5(), saveat=0.1)
178179

179180
# index of M₂₀₀ can be checked with `u₀map` or `closed_eqs.odes.states`
180-
plt = plot!(plt, sol, vars=(0, 4), lw=3, label = closure*" q = "*string(q))
181+
plt = plot!(plt, sol, idxs=[4], lw=3, label = closure*" q = "*string(q))
181182
end
182183
end
183184

@@ -200,7 +201,7 @@ q_vals = [4, 6]
200201

201202
for (q, plt_m, plt_v) in zip(q_vals, plt_means, plt_vars)
202203

203-
eqs = generate_central_moment_eqs(rn, 3, q, combinatoric_ratelaw=false)
204+
eqs = generate_central_moment_eqs(rn, 3, q, combinatoric_ratelaws=false)
204205
for closure in closures
205206

206207
closed_eqs = moment_closure(eqs, closure)
@@ -209,8 +210,8 @@ for (q, plt_m, plt_v) in zip(q_vals, plt_means, plt_vars)
209210
oprob = ODEProblem(closed_eqs, u₀map, tspan, p)
210211

211212
sol = solve(oprob, Tsit5(), saveat=0.1)
212-
plt_m = plot!(plt_m, sol, vars=(0, 1), label = closure)
213-
plt_v = plot!(plt_v, sol, vars=(0, 4), label = closure)
213+
plt_m = plot!(plt_m, sol, idxs=[1], label = closure)
214+
plt_v = plot!(plt_v, sol, idxs=[4], label = closure)
214215

215216
end
216217

@@ -270,7 +271,7 @@ Finally, we can check whether better estimates can be obtained using even higher
270271
plt = plot()
271272
closures = ["zero", "normal", "log-normal", "gamma"]
272273

273-
eqs = generate_central_moment_eqs(rn, 5, 6, combinatoric_ratelaw=false)
274+
eqs = generate_central_moment_eqs(rn, 5, 6, combinatoric_ratelaws=false)
274275
# faster to store than recompute in case we want to try different solvers/params
275276
oprobs = Dict()
276277

@@ -281,7 +282,7 @@ for closure in closures
281282
oprobs[closure] = ODEProblem(closed_eqs, u₀map, tspan, p)
282283
sol = solve(oprobs[closure], Tsit5(), saveat=0.1)
283284

284-
plt = plot!(plt, sol, vars=(0, 1), label = closure)
285+
plt = plot!(plt, sol, idxs=[1], label = closure)
285286
end
286287

287288
plt = plot!(plt, xlabel = "Time [h]", ylabel = "Mean p53 molecule number")

0 commit comments

Comments
 (0)