Problem with Distrubuted package

I just try to launch an example from the tutorial and immediately get the error:

using Distributed
using DifferentialEquations
using Plots

addprocs()

@everywhere using DifferentialEquations
# Linear ODE which starts at 0.5 and solves from t=0.0 to t=1.0
prob = ODEProblem((u,p,t)->1.01u,0.5,(0.0,1.0))

@everywhere function prob_func(prob,i,repeat) # i is the unique id 1:trajectories for the problem
  remake(prob,u0=rand()*prob.u0)
end

ensemble_prob = EnsembleProblem(prob,prob_func=prob_func)
sim = solve(ensemble_prob,Tsit5(),EnsembleDistributed(),trajectories=100)

The error:

On worker 2:
UndefVarError: #460#461 not defined
Stacktrace:
  [1] deserialize_datatype
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:1288
  [2] handle_deserialize
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:835
  [3] deserialize
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:782
  [4] handle_deserialize
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:842
  [5] deserialize
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:782
  [6] #5
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:941
  [7] ntupleany
    @ ./ntuple.jl:43
  [8] deserialize_tuple
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:941
  [9] handle_deserialize
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:825
 [10] deserialize
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:782
 [11] #5
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:941
 [12] ntupleany
    @ ./ntuple.jl:43
 [13] deserialize_tuple
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:941
 [14] handle_deserialize
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:825
 [15] deserialize
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Serialization/src/Serialization.jl:782 [inlined]
 [16] deserialize_msg
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/messages.jl:87
 [17] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [18] invokelatest
    @ ./essentials.jl:706 [inlined]
 [19] message_handler_loop
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:169
 [20] process_tcp_streams
    @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:126
 [21] #99
    @ ./task.jl:411

Stacktrace:
  [1] (::Base.var"#837#839")(x::Task)
    @ Base ./asyncmap.jl:177
  [2] foreach(f::Base.var"#837#839", itr::Vector{Any})
    @ Base ./abstractarray.jl:2141
  [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64})
    @ Base ./asyncmap.jl:177
  [4] wrap_n_exec_twice
    @ ./asyncmap.jl:153 [inlined]
  [5] #async_usemap#822
    @ ./asyncmap.jl:103 [inlined]
  [6] #asyncmap#821
    @ ./asyncmap.jl:81 [inlined]
  [7] pmap(f::Function, p::CachingPool, c::UnitRange{Int64}; distributed::Bool, batch_size::Int64, on_error::Nothing, retry_delays::Vector{Any}, retry_check::Nothing)
    @ Distributed /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/pmap.jl:126
  [8] solve_batch(prob::EnsembleProblem{ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, typeof(prob_func), typeof(SciMLBase.DEFAULT_OUTPUT_FUNC), typeof(SciMLBase.DEFAULT_REDUCTION), Nothing}, alg::Tsit5, ensemblealg::EnsembleDistributed, II::UnitRange{Int64}, pmap_batch_size::Int64; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ SciMLBase ~/.julia/packages/SciMLBase/1aTqd/src/ensemble/basic_ensemble_solve.jl:178
  [9] solve_batch
    @ ~/.julia/packages/SciMLBase/1aTqd/src/ensemble/basic_ensemble_solve.jl:168 [inlined]
 [10] macro expansion
    @ ./timing.jl:287 [inlined]
 [11] __solve(prob::EnsembleProblem{ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, typeof(prob_func), typeof(SciMLBase.DEFAULT_OUTPUT_FUNC), typeof(SciMLBase.DEFAULT_REDUCTION), Nothing}, alg::Tsit5, ensemblealg::EnsembleDistributed; trajectories::Int64, batch_size::Int64, pmap_batch_size::Int64, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ SciMLBase ~/.julia/packages/SciMLBase/1aTqd/src/ensemble/basic_ensemble_solve.jl:108
 [12] #solve#61
    @ ~/.julia/packages/DiffEqBase/oe7VF/src/solve.jl:96 [inlined]
 [13] top-level scope
    @ In[5]:2
 [14] eval
    @ ./boot.jl:360 [inlined]
 [15] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1094

Has anybody encounter with it?
I run the code in jupyter notebook and use 1.6.1 julia version

Use a function not an anonymous function for the ODE.

I replaced the anonymous function with

f(u,p,t) = 1.01*u
prob = ODEProblem(f,0.5,(0.0,1.0))

but nothing changed

Did you @everywhere the definition of f?

1 Like

I added it:

@everywhere f(u,p,t) = 1.01*u

result is still the same. I’ll try to update julia, because the code worked a few weeks ago

In my environment (Windows 10 Home, Julia v1.6.2, the latest version of DifferentialEquations.jl), the code runs fine as is.

Jupyter notebook: public/EnsembleProblem example.ipynb at main · genkuroki/public · GitHub

Package status:

using Pkg
Pkg.status("DifferentialEquations")
Pkg.status("DiffEqBase"; mode=PKGMODE_MANIFEST)
Pkg.status("SciMLBase"; mode=PKGMODE_MANIFEST)

Output:

      Status `D:\.julia\environments\v1.6\Project.toml`
  [0c46a032] DifferentialEquations v6.17.2
      Status `D:\.julia\environments\v1.6\Manifest.toml`
  [2b5f629d] DiffEqBase v6.69.0
      Status `D:\.julia\environments\v1.6\Manifest.toml`
  [0bca4576] SciMLBase v1.18.2

The following code runs fine.

using Distributed
using DifferentialEquations
# using Plots

@show addprocs()

@everywhere using DifferentialEquations
# Linear ODE which starts at 0.5 and solves from t=0.0 to t=1.0
@everywhere f(u,p,t) = 1.01*u
prob = ODEProblem(f,0.5,(0.0,1.0))

@everywhere function prob_func(prob,i,repeat) # i is the unique id 1:trajectories for the problem
  remake(prob,u0=rand()*prob.u0)
end

ensemble_prob = EnsembleProblem(prob,prob_func=prob_func)
sim = solve(ensemble_prob,Tsit5(),EnsembleDistributed(),trajectories=100)

Output:

addprocs() = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

EnsembleSolution Solution of length 100 with uType:
ODESolution{Float64, 1, Vector{Float64}, Nothing, Nothing, Vector{Float64}, ...
1 Like

I updated julia to the version 1.6.2, and now I can launch the code in the Atom. But my jupyter notebook dies when I run the code