I tried different algorithms, and actually DirectCR was the best one between RSSA and DirectCR by a substantial margin. The results I reported are for DirectCR.
@ChrisRackauckas, my first approach was actually with Catalyst.jl as I thought it would save me a lot of work. Unfortunately, it did not scale. Problem set up with as little as 100 nodes was really slow, and it crashed when solved. For future reference this is the script:
using LightGraphs
using DifferentialEquations
using Plots
using GraphPlot
using LinearAlgebra
using Distributions
using Catalyst
using ModelingToolkit
@info "Initializing system..."
degree = 5
kdist = Poisson(degree)
N = Int(20)
ks = 1
while sum(ks) % 2 != 0
global ks = rand(kdist, N)
end
g = random_configuration_model(N, ks)
i₀ = rand(1:N, round(Int, N*0.1))
x₀ = [ones(N); zeros(N); zeros(N)]
x₀[i₀] .= 0
x₀[i₀ .+ N] .= 1
tspan = (0.0, 100.0)
p = [0.25, 0.05, degree, adjacency_matrix(g)]
function agg_sol(sol, N)
agg = reshape(@view(sol[:, :]), (N, 3, :))
agg = mean(agg; dims=1)
agg = dropdims(agg; dims=1)
agg = permutedims(agg, (2, 1))
return agg
end
@info "Initializing variables..."
@parameters t
@variables β γ k A[1:N, 1:N] x[1:3N](t)
@info "Collecting reactions..."
rx = []
for i in 1:N
push!(rx, Reaction(
x[i]*(β/k)*dot(A[:, i], x[(N+1):2N]),
[x[i]],
[x[N+i]];
only_use_rate=true)
)
end
for i in 1:N
push!(rx, Reaction(
γ,
[x[N+i]],
[x[2N+i]];
only_use_rate=false)
)
end
@info "Building reaction system..."
rs = ReactionSystem(rx, t, x, reduce(vcat, [[β, γ, k], vec(A)]))
@info "Converting to jump system..."
jump_sys = convert(JumpSystem, rs; combinatoric_ratelaws=false)
@info "Building discrete problem..."
discrete_prob = DiscreteProblem(
jump_sys,
Pair.(x, x₀),
tspan,
Pair.(
reduce(vcat, [[β, γ, k], vec(A)]),
reduce(vcat, [p[1:3], vec(adjacency_matrix(g))])
)
)
@info "Building jump problem..."
jump_prob = JumpProblem(jump_sys, discrete_prob, DirectCR())
@info "Solving problem..."
jump_sol = solve(jump_prob, SSAStepper())
With that being said, Catalyst.jl was really useful in model exploration. It helped to figure out how to describe the problem in DiffEqJump.jl. The equations output and the Graphviz plots convinced me that I had set up the problem correctly.
@isaacsas I will try to help with the documentation. It is good practice to get more acquainted with the code base. Will get back to it from Monday.