Skip to content

Commit a8bf231

Browse files
feat: add BCR jacobian benchmark
1 parent b4705a4 commit a8bf231

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

benchmarks/Symbolics/BCR.jmd

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: BCR Symbolic Jacobian
3+
author: Aayush Sabharwal, Bowen Zhu, Chris Rackauckas
4+
---
5+
6+
The following benchmark is of 1122 ODEs with 24388 terms that describe a stiff
7+
chemical reaction network modeling the BCR signaling network from [Barua et
8+
al.](https://doi.org/10.4049/jimmunol.1102003). We use
9+
[`ReactionNetworkImporters`](https://github.com/isaacsas/ReactionNetworkImporters.jl)
10+
to load the BioNetGen model files as a
11+
[Catalyst](https://github.com/SciML/Catalyst.jl) model, and then use
12+
[ModelingToolkit](https://github.com/SciML/ModelingToolkit.jl) to convert the
13+
Catalyst network model to ODEs.
14+
15+
The resultant large model is used to benchmark the time taken to compute a symbolic
16+
jacobian, generate a function to calculate it and call the function.
17+
18+
19+
```julia
20+
using OrdinaryDiffEq, Catalyst, ReactionNetworkImporters,
21+
Plots, TimerOutputs, LinearAlgebra, ModelingToolkit, BenchmarkTools,
22+
LinearSolve, Symbolics, SymbolicUtils.Code, SparseArrays
23+
24+
datadir = joinpath(dirname(pathof(ReactionNetworkImporters)),"../data/bcr")
25+
const to = TimerOutput()
26+
tf = 100000.0
27+
28+
# generate ModelingToolkit ODEs
29+
prnbng = loadrxnetwork(BNGNetwork(), joinpath(datadir, "bcr.net"))
30+
show(to)
31+
rn = complete(prnbng.rn; split = false)
32+
obs = [eq.lhs for eq in observed(rn)]
33+
osys = convert(ODESystem, rn)
34+
35+
rhs = [eq.rhs for eq in full_equations(osys)]
36+
vars = unknowns(osys)
37+
pars = parameters(osys)
38+
@timeit to "Calculate jacobian" jac = Symbolics.jacobian(rhs, vars);
39+
jac = sparse(jac)
40+
41+
args = (vars, pars, ModelingToolkit.get_iv(osys))
42+
# out of place versions run into an error saying the expression is too large
43+
# due to the `SymbolicUtils.Code.create_array` call.
44+
@timeit to "Build jacobian - no CSE" _, jac_nocse_iip = build_function(jac, args...; cse = false, expression = Val{false});
45+
@timeit to "Build jacobian - CSE" _, jac_cse_iip = build_function(jac, args...; cse = true, expression = Val{false});
46+
47+
defs = defaults(osys)
48+
u = Float64[Symbolics.fixpoint_sub(var, defs) for var in vars]
49+
buffer = SparseMatrixCSC{Float64, Int}(undef, length(u), length(u))
50+
p = Float64[Symbolics.fixpoint_sub(par, defs) for par in pars]
51+
tt = 0.0
52+
53+
@timeit to "Compile jacobian - CSE" jac_cse_iip(buffer, u, p, tt)
54+
@timeit to "Compute jacobian - CSE" jac_cse_iip(buffer, u, p, t)
55+
56+
@timeit to "Compile jacobian - no CSE" jac_nocse_iip(buffer, u, p, tt)
57+
@timeit to "Compute jacobian - no CSE" jac_nocse_iip(buffer, u, p, t)
58+
59+
show(to)
60+
```

benchmarks/Symbolics/Project.toml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
[deps]
2-
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3-
JuliaSimCompiler = "8391cb6b-4921-5777-4e45-fd9aab8cb88d"
4-
JuliaSimCompilerRuntime = "9cbdfd5a-25c0-4dde-8b55-206f91b28bd9"
2+
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"
3+
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
54
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
6-
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
7-
Multibody = "e1cad5d1-98ef-44f9-a79a-9ca4547f95b9"
85
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
9-
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
10-
PreferenceTools = "ba661fbb-e901-4445-b070-854aec6bfbc5"
11-
SciMLBenchmarks = "31c91b34-3c75-11e9-0341-95557aab0344"
6+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
7+
ReactionNetworkImporters = "b4db0fb7-de2a-5028-82bf-5021f5cfa881"
128
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
139
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
14-
XSteam = "95ff35a0-be81-11e9-2ca3-5b4e338e8476"
10+
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
1511

1612
[compat]
17-
CairoMakie = "0.11.11"
18-
ModelingToolkit = "9.20.0"
19-
ModelingToolkitStandardLibrary = "2"
20-
Polynomials = "4.0.8"
21-
PreferenceTools = "0.1.2"
22-
SciMLBenchmarks = "0.1.3"
23-
SymbolicUtils = "3.11"
24-
Symbolics = "6.23"
13+
SymbolicUtils = "3.15"
14+
Symbolics = "6.29.1"
15+
ModelingToolkit = "9"

0 commit comments

Comments
 (0)