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

Adjoint Sensitivity Out of Place Support #113

Open
AhmedAlreweny opened this issue Nov 13, 2019 · 5 comments
Open

Adjoint Sensitivity Out of Place Support #113

AhmedAlreweny opened this issue Nov 13, 2019 · 5 comments

Comments

@AhmedAlreweny
Copy link

AhmedAlreweny commented Nov 13, 2019

I am solving the 1D KS equation using FDM. I transformed the PDE into a set of ODEs inside a function that I called DerSen.jl. I used RK4 to solve the ODEs and the solution I got is correct.

 using DifferentialEquations

p=c    # parameters
u0=U[:,1]    #Float
tspan=(0.0,Tspan)
prob=ODEProblem(DerSen,u0,tspan,p)
sol = solve(prob,RK4(),saveat=Δt)
U=convert(Array,sol)
t_vec=sol.t

I would like to go further and compute the adjoint sensitivity of this model. My code is as follows:

using Sundials, DiffEqBase
g(u,p,t) = (sum(u).^2) ./ 2
function dg(out,u,p,t)
  for i=1:Nx
     out[i]=sum(U[i,:])
  end
end
res = adjoint_sensitivities(sol,Vern9(),g,nothing,dg,abstol=1e-8,
                                 reltol=1e-8,iabstol=1e-8,ireltol=1e-8)

and I get this error massage that I don't understand

LoadError: MethodError: no method matching similar(::Float64)
Closest candidates are:
similar(!Matched::JuliaInterpreter.Compiled, !Matched::Any) at C:\Users*.juliapro\JuliaPro_v1.2.0-1\packages\JuliaInterpreter\MXq3U\src\types.jl:7
similar(!Matched::DataFrames.StackedVector, !Matched::Type, !Matched::Union{Integer, AbstractUnitRange}...) at C:\Users*
.juliapro\JuliaPro_v1.2.0-1\packages\DataFrames\yH0f6\src\abstractdataframe\reshape.jl:401
similar(!Matched::Sundials.NVector) at C:\Users*
*.juliapro\JuliaPro_v1.2.0-1\packages\Sundials\fVIue\src\nvector_wrapper.jl:69
...

@ChrisRackauckas
Copy link
Member

The adjoint method is currently only for in-place functions of mutable vectors. It seems you have a scalar ODE which won't work.

FWIW, there's no speed advantage to adjoint methods when you have a scalar ODE anyways.

@AhmedAlreweny
Copy link
Author

The adjoint method is currently only for in-place functions of mutable vectors. It seems you have a scalar ODE which won't work.

FWIW, there's no speed advantage to adjoint methods when you have a scalar ODE anyways.

Thanks! The same thing goes for the forward sensitivity using ODELocalSensitivityProblem ?

@ChrisRackauckas
Copy link
Member

The same thing goes for the forward sensitivity using ODELocalSensitivityProblem ?

About compatibility? Yes, it needs in-place for now. But ForwardDiff.jl will likely be faster when it's just scalars.

@AhmedAlreweny
Copy link
Author

The same thing goes for the forward sensitivity using ODELocalSensitivityProblem ?

About compatibility? Yes, it needs in-place for now. But ForwardDiff.jl will likely be faster when it's just scalars.

Very clear now! Thanks a lot.

@ChrisRackauckas ChrisRackauckas changed the title Adjoint Sensitivity for Finite difference scheme Adjoint Sensitivity Out of Place Support Nov 17, 2019
@ChrisRackauckas
Copy link
Member

Just to be clear, it's not fundamental to the implementation, it's just not something that has been handled yet.

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