Diffeqpy, using ensembling

It is possible to use use ensembling in diffeqpy?
here is my example code:

import numpy as np
import pylab as pl
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


np.random.seed(1)


julia_f = Main.eval("""
function f!(du, u, p, t)
    du = 1.01 * u
    return du
end
""")

prob_func = Main.eval("""
function prob_func(prob, i, repeat)
    remake(prob, u0 = rand() * prob.u0)
    end
""")

# def prob_func(prob, i, repeat):
#     de.remake(prob, u0=rand() * prob.u0)


if __name__ == "__main__":

    tspan = (0.0, 10.0)
    prob = de.ODEProblem(julia_f, 0.5, tspan)
    ensemble_prob = de.EnsembleProblem(
        prob,
        prob_func=prob_func)
    
    sol = de.solve(ensemble_prob,
                   de.Tsit5(),
                   de.EnsembleThreads(),
                   trajectories=2)

output error:

RuntimeError                              Traceback (most recent call last)
~/git/workshop_julia/DiffEquations/diffeqpy/synchrony_test/test_ensemble1.py in <module>
     45                    de.Tsit5(),
     46                    de.EnsembleThreads(),
---> 47                    trajectories=2)

RuntimeError: Julia exception: TaskFailedException:
MethodError: no method matching similar(::Float64)
Closest candidates are:
  similar(!Matched::Sundials.NVector) at /home/abolfazl/.julia/packages/Sundials/Mtc8o/src/nvector_wrapper.jl:71
  similar(!Matched::JuliaInterpreter.Compiled, !Matched::Any) at /home/abolfazl/.julia/packages/JuliaInterpreter/dEBFI/src/types.jl:7
  similar(!Matched::Array{T,1}) where T at array.jl:356

Is there any minimal example for using ensemble in diffeqpy?

Should be simpler and work. Using arrays instead of scalars for ODEs is probably a lot more common too.

1 Like