ERROR: LoadError: Need an adjoint for constructor EnsembleSolution

I wish to use to optimize a parameter in parallel ensemble simulation, but it shows adjoint error as below:

ERROR: LoadError: Need an adjoint for constructor EnsembleSolution{Float64,2,Array{ODESolution{Float64,1,Array{Float64,1},Nothing,Nothing,Array{Float64,1},Array{Array{Float64,1},1},ODEProblem{Float64,Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,var"#189#190",UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,var"#189#190",UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Float64,1},Array{Float64,1},Array{Array{Float64,1},1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}},DiffEqBase.DEStats},1}}. Gradient is of type Array{Float64,2}

Does it mean Flux training is not compatible with EnsembleProblem? I’d be grateful of any insight into this problem solution.
The code is as below:

using DifferentialEquations, Flux

pa = [1.0]

function model1(input) 
  prob = ODEProblem((u, p, t) -> 1.01u * pa[1], 0.5, (0.0, 1.0))
  function prob_func(prob, i, repeat)
    remake(prob, u0 = rand() * prob.u0)
  ensemble_prob = EnsembleProblem(prob, prob_func = prob_func)
  sim = solve(ensemble_prob, Tsit5(), EnsembleThreads(), trajectories = 100)

Input_time_series = zeros(5, 100)
# loss function
loss(x, y) = Flux.mse(model1(x), y)

data = Iterators.repeated((Input_time_series, 0), 1)

cb = function () # callback function to observe training
  println("Tracked Parameters: ", params(pa))

opt = ADAM(0.1)
println("Starting to train")
Flux.@epochs 10 Flux.train!(loss, params(pa), data, opt; cb = cb)

Is this just a repost of Training on EnsembleProblem: ERROR: LoadError: Need an adjoint for constructor EnsembleSolution?

Yes, with minor simplification in problem description and code.
I have requested to deleted the previous post.
Sorry about the inconvenience

Hi ChrisRackauckas,
If I might, I wish to request for your kind help on this issue. This bug has baffled me for a while. I’m not sure whether it’s because my code is buggy, or there’s literally no adjoint method provided to EnsembleProblem?

It’s not you it’s me. It’s not a bug, just not implemented. I thought I’d get to it yesterday but didn’t quite yet. I’ll make sure to get something working here today though. I think only EnsembleSerial will work because Zygote won’t be able to differentiate multithreading or multiprocessing, but I want to figure out a way around that because it’s not too hard. So say, work-in-progress.

Thanks so much for your offer to help. I’m looking forward to your insights.

Big step forward: Zygote is now compatible with parallelism.

I won’t update here anymore, but you can track the issue here:

1 Like

Thanks for the updates.
I have updated Zygote version, but running my code still shows the same error. Should I revise my code somehow, besides using the newest version of Zygote?


That doesn’t fix the issue yet, and it requires the unreleased Zygote version.

The issue will be closed when this is completed. Major progress, but not done yet Close!

1 Like