I am going to solve a system of SDE using diffeqpy and use EnsembleProblem
.
I don’t know why I am getting remake not defined error
.
The code run properly without EnsembleProblem
.
So I guess the problem should be in prob_func
, but what is that?
Here is the script:
import numpy as np
import pylab as pl
from math import pi
from time import time
from sys import exit
try:
from diffeqpy import de
from julia import Main
except:
from julia.api import Julia
jl = Julia(compiled_modules=False)
from julia import Main
from diffeqpy import de
julia_f = Main.eval("""
function f!(du, u, p, t)
for i = 1:p[1]
du[i] = 2.0 + sum(sin.(u .- u[i]))
end
return du
end
""" )
julia_g = Main.eval("""
function g!(du, u, p, t)
for i = 1:p[1]
du[i] = p[2]
end
du
end
""")
prob_f = Main.eval("""
function prob_func(prob, i, repeat)
remake(prob, u0 = rand() .* prob.u0)
end
""")
#-------------------------------------------------------------------#
K = 2.0 # coupling
N = 3 # number of nodes
dt = 0.01 # time step
t_final = 50.0 # simulation time
t_trans = 10.0 # transition time
mu = 2.0 # mean value of initial frequencies
sigma = 0.0 # std of initial frequencies
kind = 2
noise_amp = 0.001
if __name__ == "__main__":
start = time()
np.random.seed(1)
theta_0 = np.random.uniform(-pi, pi, size=N)
tspan = (0.0, t_final)
p = [N, noise_amp]
prob = de.SDEProblem(julia_f, julia_g, theta_0, tspan, p)
# sol = de.solve(prob, de.SOSRA())
ensemble_prob = de.EnsembleProblem(prob, prob_func=prob_f)
sol = de.solve(ensemble_prob,
de.SOSRA(),
de.EnsembleThreads(),
trajectories=2)
RuntimeError Traceback (most recent call last)
~/git/workshop_julia/DiffEquations/diffeqpy/synchrony_test/test_ensemble.py in <module>
77 de.SOSRA(),
78 de.EnsembleThreads(),
---> 79 trajectories=2)
RuntimeError: Julia exception: TaskFailedException:
UndefVarError: remake not defined