Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: LoadError: Need an adjoint for constructor EnsembleSolution #1270

Closed
yanz4 opened this issue Jul 6, 2020 · 1 comment
Closed

ERROR: LoadError: Need an adjoint for constructor EnsembleSolution #1270

yanz4 opened this issue Jul 6, 2020 · 1 comment

Comments

@yanz4
Copy link

yanz4 commented Jul 6, 2020

I wish to use Flux.training to optimize a parameter in parallel ensemble simulation defined by EnsembleProblem() provided by DifferentialEquations.jl. The output I expect is the gradient output with respect to the tracked parameter. However, it shows that there's no adjoint method provided 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"#16#17",LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,QuadratureAdjoint{0,true,Val{:central},Bool},Tuple{Symbol},NamedTuple{(:sensealg,),Tuple{QuadratureAdjoint{0,true,Val{:central},Bool}}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,var"#16#17",LinearAlgebra.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}

My simplified code is attached as below. I'd be grateful of any insights.

using DifferentialEquations, Flux, DiffEqSensitivity
 

pa = [1.0]

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

end

Input_time_series = zeros(5, 100)

loss(x, y) = Flux.mse(model1(x), y)

data = Iterators.repeated((Input_time_series, 0), 1)
 
gs = Flux.gradient(() -> loss(Input_time_series, 0), params(pa)) 

@CarloLucibello
Copy link
Member

the adjoint should be defined wherever EnsembleProblem is defined, so better move this issue over to DifferentialEquations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants