I tried rerunning my code after the latest 4.2 update to the DifferentialEquations
package. I use the reaction_network
DSL from DiffEqBiological
package, from these I generate and solve SDEs with non-diagonal noise. However I generated an error
DimensionMismatch("array could not be broadcast to match destination")
more detailed (bu not all, quite long):
[1] check_broadcast_shape(::Tuple{Base.OneTo{Int64}}, ::Tuple{Base.OneTo{Int64}}) at ./broadcast.jl:83
[2] check_broadcast_indices at ./broadcast.jl:89 [inlined]
[3] broadcast_c! at ./broadcast.jl:210 [inlined]
[4] broadcast! at ./broadcast.jl:206 [inlined]
[5] perform_step!(::StochasticDiffEq.SDEIntegrator{StochasticDiffEq.ImplicitEM{0,true
I have been searching some. Trying to figure out what it is, these are my results.
This works fine:
model = @reaction_network rn begin
(1,1), X ↔ Y
end
prob_sde = SDEProblem(model,[200.,300.],(0.,10.));
sol = solve(prob_sde,ImplicitEM());
while this is not:
model = @reaction_network rn beginbegin
(1,1), X ↔ Y
(10,0.1), ∅ ↔ X
end
prob_sde = SDEProblem(model,[200.,300.],(0.,10.));
sol = solve(prob_sde,ImplicitEM());
Solving the corresponding ODEs is no problem.
Next I try implementing it normally:
function f(du,u,p,t)
du[1] = u[2] - u[1] + 10 - 0.1*u[1]
du[2] = u[1] - u[2]
end
function g(du,u,p,t)
du[1,1] = -sqrt(u[1])
du[1,2] = sqrt(u[2])
du[1,3] = sqrt(10)
du[1,4] = -sqrt(0.1*u[1])
du[2,1] = sqrt(u[1])
du[2,2] = -sqrt(u[2])
du[2,3] = 0
du[2,4] = 0
end
prob_sde = SDEProblem(f,g,[200.,300.],(0.,10.),noise_rate_prototype=zeros(2,4))
sol = solve(prob_sde,ImplicitEM());
plot(sol)
This does not work. I also get the same error when I copy from the documentation:
f(du,u,p,t) = du .= 1.01u
function g(du,u,p,t)
du[1,1] = 0.3u[1]
du[1,2] = 0.6u[1]
du[1,3] = 0.9u[1]
du[1,4] = 0.12u[2]
du[2,1] = 1.2u[1]
du[2,2] = 0.2u[2]
du[2,3] = 0.3u[2]
du[2,4] = 1.8u[2]
end
prob = SDEProblem(f,g,ones(2),(0.0,1.0),noise_rate_prototype=zeros(2,4))
sol = solve(prob_sde,ImplicitEM());
plot(sol)
I am not sure whenever this is an issue with the package and should be raised there, or if it is me doing things in the wrong way, in which it might be good to keep it here for others to see properly.