不支持对局部变量的 'const' 声明(Julia 中的 reaction_network)

Unsupported 'const' declaration on local variable (reaction_network in Julia)

我是 Julia(版本 1.0.2)的新手,目前正在尝试 DiffEqBiological 包中的 @reaction_network(也是当前版本,我在这里找不到版本号):

tspan = (0.0, 50.0);
y0 = [100.0 50.0 0.0 0.0] #[substrate enzyme complex product]
S, E = y0[1], y0[2]
for r in 0.1:0.1:1.0
    println("Creating Michaelis-Menten reaction model...")
    r1, r2, r3 = r, r, r;
    michaelismenten = @reaction_network rType begin
        r1, S + E ⟶ C
        r2, C ⟶ S + E
        r3, C ⟶ P + E
    end

    y = ODEProblem(michaelismenten, y0, tspan)
    sol = solve(y, CVODE_BDF(), reltol=1e-8, abstol=1e-8)
end

当我尝试编译它时,出现语法错误:unsupported 'const' declaration on local variable around C:\Users\...\.julia\packages\DiffEqBiological\nujlA\src\reaction_network.jl:447。 我非常努力地寻找错误,也许我的知识太少,无法真正理解类似的问题,因为我尝试了答案,但仍然得到相同的错误消息。 我尝试了通常的

r = 0.1
michaelismenten = @reaction_network rType begin
            r, S + E ⟶ C
            r, C ⟶ S + E
            r, C ⟶ P + E
        end
y = ODEProblem(michaelismenten, y0, tspan)
sol = solve(y, CVODE_BDF(), reltol=1e-8, abstol=1e-8)

这完全没问题。一旦我添加 for 循环来改变我的反应速度,我就会收到这个错误,这意味着这个代码

for i = 1:10
    r = i/10 # here I thought that Julia maybe did not like the 0.1:0.1:1.0 from above
    michaelismenten = @reaction_network rType begin
                    r, S + E ⟶ C
                    r, C ⟶ S + E
                    r, C ⟶ P + E
                end
end

已经抛出同样的错误。这就是为什么,我认为我在 for 循环上做错了,我想用它来改变反应率 r 以便我能够通过

为我的情节制作动画
anim = @animate for r = 0.1:0.1:1.0
     # create michaelismenten and solve in this for-loop before plotting (see above)
     plot(sol)
end
gif(anim, "$S_$E_RRE.gif", fps = 15)

我希望有人能帮我找到解决问题的方法。请帮助我通过格式化使我提出的问题更清楚。

稍微总结一下评论:

我挣扎了很久,但这段代码现在可以工作了(对于那些对解决方案感兴趣的人;))。谢谢 zundertj 的帮助!你在我脑中触发了一些想法,导致了这个解决方案!

using Plots
using DifferentialEquations
using Distributions
using DiffEqBiological

function solveRRE(michaelismenten, y0, tspan, p)
    # create and solve problem
    println("Creating ODEProblem...")
    y = ODEProblem(michaelismenten, y0, tspan, p)
    println("Solving Reaction Rate Equation...")
    sol = solve(y, CVODE_BDF(), reltol=1e-8, abstol=1e-8)
    return sol
end

tspan = (0.0, 50.0);
y0 = [100.0 50.0 0.0 0.0] #[substrate enzyme complex product]
S, E = y0[1], y0[2]

michaelismenten = @reaction_network rType begin
    r, S + E ⟶ C
    r, C ⟶ S + E
    r, C ⟶ P + E
end r
anim = @animate for i in 0.1:0.1:1.0
    p = i
    sol = solveRRE(michaelismenten, y0, tspan, p)
    plot(sol)
end
gif(anim, "RRE.gif", fps = 15)

另一个可能发生的错误是 Windows/Linux 上没有安装 ffmpeg。有关进一步的说明,这个网站帮助了我很多: https://video.stackexchange.com/questions/20495/how-do-i-set-up-and-use-ffmpeg-in-windows

谁能告诉我,如何关闭此主题已解决?提前致谢!