Reputation: 13
I've a reaction network defined using DiffEqBiological in Julia. At particular times, I want to change the parameters. However, I can't seem to be able to change them. Though not what I want to do, I am able to affect the variables.
I wrote a simplified version of the code where every 20 units of time I change one of the parameters from 0.001 to 0.1, and from 0.1 to 0.001. My code is
using DifferentialEquations, DiffEqBiological
# reaction network
rn = @reaction_network begin
r1, X --> 2X
r2, X --> 0
r3, 2X --> X
end r1 r2 r3
params = [2.0, 1.0, 0.001]
tspan = (0.0, 100.0)
u0 = [1000]
# Callback conditions
E1 = collect(0:40:100)
E2 = collect(20:40:100)
E = union(E1,E2)
function condition1(u,t,integrator)
t in (E1)
end
function condition2(u,t,integrator)
t in (E2)
end
function affect1!(integrator)
integrator.p[3] = 0.001
end
function affect2!(integrator)
integrator.p[3] = 0.1
end
cb1 = DiscreteCallback(condition1,affect1!)
cb2 = DiscreteCallback(condition2,affect2!)
cbs = CallbackSet(cb1,cb2)
# solve JumpProblem
dprob = DiscreteProblem(u0, tspan, params)
jprob = JumpProblem(dprob, Direct(), rn)
sol = solve(jprob,FunctionMap(),callback=cbs,tstops=E)
I don't receive any errors. The solver solves it. However, the callbacks aren't changing the parameter. I'd appreciate all help. I can't figure out why it isn't working. Thanks.
Upvotes: 1
Views: 258
Reputation: 19132
This was an old issue (https://github.com/SciML/DiffEqJump.jl/issues/78) but was solved (https://github.com/SciML/DiffEqJump.jl/pull/120) and should work on recent versions.
Upvotes: 0