SciMLSensitivity.jl icon indicating copy to clipboard operation
SciMLSensitivity.jl copied to clipboard

Reverse Mode AD doesn't work if NamedTuples are used as parameters

Open mattborghi opened this issue 4 years ago • 3 comments

Lately, I have been trying to use NamedTuples for passing parameters to a DE problem in order to compute derivatives but this method seems to fail.

For comparison, I make the same calculation using a Vector of parameters instead.

I am using the latest stable versions for the presented packages and Julia v1.5.0.

# load packages
using DifferentialEquations
using DiffEqSensitivity
using Statistics: mean
using Parameters: @unpack
using ForwardDiff
using ReverseDiff
using Zygote

# initialize parameters 
tspan = (0., 1.)
u₀ = 1.
r = 0.05
σ = 0.4

# receives p = [ r, σ] as an array
function fs(u, p, t)
    r = p[1]
    r .* u
end

function gs(u, p, t)
    σ = p[2]
    σ .* u
end

# receives p = (; r, σ) as a NamedTuple
function f(u, p, t)
    @unpack r = p
    r .* u
end

function g(u, p, t)
    @unpack σ = p
    σ .* u
end

# Define problems
prob = SDEProblem{false}(f, g, u₀, tspan)
oop = EnsembleProblem(prob)

probs = SDEProblem{false}(fs, gs, u₀, tspan)
oops = EnsembleProblem(probs)

# define parameters
p = [u₀, r, σ]

the solve method:

  1. receives a Vector as input for p when simple function is used.
  2. receives a NamedTuple as input for p when calculate function is used.
# Define functions to be derivated
simple = function (up, prob = probs, sensealg = TrackerAdjoint(); seed=111)
    Array(solve(
    prob,
    SRIW1();
    u0=[up[1]],
    p=up[2:end],
    saveat=0.1,
    sensealg,
    seed,
    trajectories=1_000,
  ))[:,end,:] |> mean
end

calculate = function (up, prob = prob, sensealg = TrackerAdjoint(); seed=111)
    p = (;r=up[2], σ=up[3])
    Array(solve(
    prob,
    SRIW1();
    u0=[up[1]],
    p,
    saveat=0.1,
    sensealg,
    seed,
    trajectories=1_000,
  ))[:,end,:] |> mean
end

# evaluate the functions
simple(p, oops) # 1.4020033221163284 
calculate(p, oop) # 1.4020033221163284

Just for comparison we calculate Forward Mode AD without problems.

# using ForwardDiff.jl
ForwardDiff.gradient(x -> calculate(x, oop), p)
# 3-element Array{Float64,1}:
# 1.5799924814996311
#  1.581962649205976
#  1.2930442221318288
ForwardDiff.gradient(x -> simple(x, oops), p)
# 3-element Array{Float64,1}:
# 1.5799924814996311
#  1.581962649205976
#  1.2930442221318288

Reverse mode AD using ReverseDiff.jl

Using (1) with different sensealgs gives different results but works. Using (2) fails.

# using ReverseDiff.jl
ReverseDiff.gradient(x -> simple(x, oops, TrackerAdjoint()), p)
# 3-element Array{Float64,1}:
# 0.0
#  1.4032274627896102
#  0.7290267892368372
ReverseDiff.gradient(x -> simple(x, oops, QuadratureAdjoint()), p)
# 3-element Array{Float64,1}:
# 0.0
#  1.2517556141290906
#  0.0
ReverseDiff.gradient(x -> calculate(x, oop, TrackerAdjoint()), p)
ERROR: type Float64 has no field partials

ERROR: type Float64 has no field partials
Stacktrace: 2. getproperty(::Float64, ::Symbol) at ./Base.jl:33 3. _deriv(::Function, ::Float64, ::Val{1}, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64) at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/derivatives/broadcast.jl:224 4. _broadcast_getindex_evalf at ./broadcast.jl:648 5. _broadcast_getindex at ./broadcast.jl:621 6. getindex at ./broadcast.jl:575 7. copy at ./broadcast.jl:876 8. materialize at ./broadcast.jl:837 9. macro expansion at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/derivatives/broadcast.jl:0 10. _derivs(::Base.Broadcast.var"#2#4"{Base.Broadcast.var"#8#10"{Base.Broadcast.var"#8#10"{Base.Broadcast.var"#1#3",Base.Broadcast.var"#8#10"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"},Base.Broadcast.var"#5#6"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"}},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(+)},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(DiffEqBase.ODE_DEFAULT_NORM)},Base.Broadcast.var"#8#10"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"},Base.Broadcast.var"#5#6"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"}},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(-)},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(DiffEqBase.ODE_DEFAULT_NORM)},typeof(max)}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Float64, ::Array{Float64,1}, ::Array{Float64,1}, ::Float64) at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/derivatives/broadcast.jl:226 11. special_reverse_exec!(::ReverseDiff.SpecialInstruction{typeof(ReverseDiff.tracker_∇broadcast),Tuple{ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},Float64,ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},Float64},ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},Tuple{Base.Broadcast.var"#2#4"{Base.Broadcast.var"#8#10"{Base.Broadcast.var"#8#10"{Base.Broadcast.var"#1#3",Base.Broadcast.var"#8#10"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"},Base.Broadcast.var"#5#6"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"}},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(+)},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(DiffEqBase.ODE_DEFAULT_NORM)},Base.Broadcast.var"#8#10"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"},Base.Broadcast.var"#5#6"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"}},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(-)},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(DiffEqBase.ODE_DEFAULT_NORM)},typeof(max)}}}) at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/derivatives/broadcast.jl:255 12. reverse_exec!(::ReverseDiff.SpecialInstruction{typeof(ReverseDiff.tracker_∇broadcast),Tuple{ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},Float64,ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},Float64},ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},Tuple{Base.Broadcast.var"#2#4"{Base.Broadcast.var"#8#10"{Base.Broadcast.var"#8#10"{Base.Broadcast.var"#1#3",Base.Broadcast.var"#8#10"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"},Base.Broadcast.var"#5#6"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"}},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(+)},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(DiffEqBase.ODE_DEFAULT_NORM)},Base.Broadcast.var"#8#10"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"},Base.Broadcast.var"#5#6"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"}},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(-)},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(DiffEqBase.ODE_DEFAULT_NORM)},typeof(max)}}}) at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/tape.jl:93 13. reverse_pass!(::Array{ReverseDiff.AbstractInstruction,1}) at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/tape.jl:87 14. reverse_pass! at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/api/tape.jl:36 15. seeded_reverse_pass!(::Array{Float64,1}, ::ReverseDiff.TrackedReal{Float64,Float64,Nothing}, ::ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}}, ::ReverseDiff.GradientTape{var"#19#20",ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},ReverseDiff.TrackedReal{Float64,Float64,Nothing}}) at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/api/utils.jl:31 16. seeded_reverse_pass!(::Array{Float64,1}, ::ReverseDiff.GradientTape{var"#19#20",ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},ReverseDiff.TrackedReal{Float64,Float64,Nothing}}) at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/api/tape.jl:47 17. gradient(::Function, ::Array{Float64,1}, ::ReverseDiff.GradientConfig{ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}}}) at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/api/gradients.jl:24 18. gradient(::Function, ::Array{Float64,1}) at /home/borghi/.julia/packages/ReverseDiff/jFRo1/src/api/gradients.jl:22 19. top-level scope at /home/borghi/Desktop/UniversalMonteCarlo.jl/examples/greeks/fix.jl:99 20. include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091 21. invokelatest(::Any, ::Any, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ./essentials.jl:710 22. invokelatest(::Any, ::Any, ::Vararg{Any,N} where N) at ./essentials.jl:709 23. inlineeval(::Module, ::String, ::Int64, ::Int64, ::String; softscope::Bool) at /home/borghi/.vscode/extensions/julialang.language-julia-1.0.8/scripts/packages/VSCodeServer/src/eval.jl:83 24. (::VSCodeServer.var"#43#45"{VSCodeServer.ReplRunCodeRequestParams,String,Int64,Int64,String,Module,Bool})() at /home/borghi/.vscode/extensions/julialang.language-julia-1.0.8/scripts/packages/VSCodeServer/src/eval.jl:45 25. withpath(::VSCodeServer.var"#43#45"{VSCodeServer.ReplRunCodeRequestParams,String,Int64,Int64,String,Module,Bool}, ::String) at /home/borghi/.vscode/extensions/julialang.language-julia-1.0.8/scripts/packages/VSCodeServer/src/repl.jl:118 26. (::VSCodeServer.var"#42#44"{VSCodeServer.ReplRunCodeRequestParams,String,Int64,Int64,String,Module,Bool,Bool})() at /home/borghi/.vscode/extensions/julialang.language-julia-1.0.8/scripts/packages/VSCodeServer/src/eval.jl:43 27. hideprompt(::VSCodeServer.var"#42#44"{VSCodeServer.ReplRunCodeRequestParams,String,Int64,Int64,String,Module,Bool,Bool}) at /home/borghi/.vscode/extensions/julialang.language-julia-1.0.8/scripts/packages/VSCodeServer/src/repl.jl:36 28. repl_runcode_request(::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint,Base.PipeEndpoint}, ::VSCodeServer.ReplRunCodeRequestParams) at /home/borghi/.vscode/extensions/julialang.language-julia-1.0.8/scripts/packages/VSCodeServer/src/eval.jl:23 29. dispatch_msg(::VSCodeServer.JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint,Base.PipeEndpoint}, ::VSCodeServer.JSONRPC.MsgDispatcher, ::Dict{String,Any}) at /home/borghi/.vscode/extensions/julialang.language-julia-1.0.8/scripts/packages/JSONRPC/src/typed.jl:66 30. macro expansion at /home/borghi/.vscode/extensions/julialang.language-julia-1.0.8/scripts/packages/VSCodeServer/src/VSCodeServer.jl:95 31. (::VSCodeServer.var"#61#63"{Bool,String})() at ./task.jl:356

Closes call of ReverseDiff.gradient

Reverse mode AD using Zygote.jl

Using (1) works. Using (2) fails.

# using Zygote.jl
Zygote.gradient(x -> simple(x, oops, QuadratureAdjoint()), p)[1]
# 3-element Array{Float64,1}:
# 1.0512710963760281
#  1.2517556141290906
#  0.0
Zygote.gradient(x -> calculate(x, oops, QuadratureAdjoint()), p)[1]
ERROR:MethodError: no method matching getproperty(::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}, ::Int64)

ERROR: MethodError: no method matching getproperty(::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}, ::Int64)
Closest candidates are:
  getproperty(!Matched::Tuple, ::Int64) at Base.jl:30
  getproperty(!Matched::ChainRulesCore.Composite, ::Int64) at /home/borghi/.julia/packages/ChainRulesCore/tBJg6/src/differentials/composite.jl:63
  getproperty(!Matched::Union{Tables.AbstractColumns, Tables.AbstractRow}, ::Int64) at /home/borghi/.julia/packages/Tables/xHhzi/src/Tables.jl:164

Stacktrace: 2. adjoint at /home/borghi/.julia/packages/Zygote/chgvX/src/lib/lib.jl:197 3. _pullback at /home/borghi/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47 4. _pullback(::Zygote.Context, ::typeof(Zygote.literal_getindex), ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}, ::Val{1}) at /home/borghi/.julia/packages/Zygote/chgvX/src/lib/lib.jl:217 5. fs at /home/borghi/Desktop/UniversalMonteCarlo.jl/examples/greeks/fix.jl:16 6. _pullback(::Zygote.Context, ::typeof(fs), ::Array{Float64,1}, ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}, ::Float64) at /home/borghi/.julia/packages/Zygote/chgvX/src/compiler/interface2.jl:0 7. adjoint at /home/borghi/.julia/packages/Zygote/chgvX/src/lib/lib.jl:172 8. _pullback at /home/borghi/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47 9. SDEFunction at /home/borghi/.julia/packages/DiffEqBase/gLFRA/src/diffeqfunction.jl:286 10. _pullback(::Zygote.Context, ::SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}, ::Array{Float64,1}, ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}, ::Float64) at /home/borghi/.julia/packages/Zygote/chgvX/src/compiler/interface2.jl:0 11. #30 at /home/borghi/.julia/dev/DiffEqSensitivity/src/local_sensitivity/derivative_wrappers.jl:290 12. _pullback(::Zygote.Context, ::DiffEqSensitivity.var"#30#32"{Float64,SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}, ::Array{Float64,1}, ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}) at /home/borghi/.julia/packages/Zygote/chgvX/src/compiler/interface2.jl:0 13. _pullback(::Function, ::Array{Float64,1}, ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}) at /home/borghi/.julia/packages/Zygote/chgvX/src/compiler/interface.jl:38 14. pullback(::Function, ::Array{Float64,1}, ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}) at /home/borghi/.julia/packages/Zygote/chgvX/src/compiler/interface.jl:44 15. _vecjacobian!(::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}, ::Float64, ::DiffEqSensitivity.ODEQuadratureAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},LinearAlgebra.UniformScaling{Bool}},QuadratureAdjoint{0,true,Val{:central},Bool},Array{Float64,1},RODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},NoiseProcess{Float64,2,Float64,Array{Float64,1},Array{Float64,1},Array{Array{Float64,1},1},typeof(DiffEqNoiseProcess.WHITE_NOISE_DIST),typeof(DiffEqNoiseProcess.WHITE_NOISE_BRIDGE),false,ResettableStacks.ResettableStack{Tuple{Float64,Array{Float64,1},Array{Float64,1}},false},ResettableStacks.ResettableStack{Tuple{Float64,Array{Float64,1},Array{Float64,1}},false},RSWM{Float64},Nothing,RandomNumbers.Xorshifts.Xoroshiro128Plus},SDEProblem{Array{Float64,1},Tuple{Float64,Float64},false,NamedTuple{(:r, :σ),Tuple{Float64,Float64}},Nothing,SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(gs),Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},Nothing},SRIW1,StochasticDiffEq.LinearInterpolationData{Array{Array{Float64,1},1},Array{Float64,1}},DiffEqBase.DEStats},SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}, ::ZygoteVJP, ::Nothing, ::Nothing) at /home/borghi/.julia/dev/DiffEqSensitivity/src/local_sensitivity/derivative_wrappers.jl:289 16. _vecjacobian!(::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}, ::Float64, ::DiffEqSensitivity.ODEQuadratureAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},LinearAlgebra.UniformScaling{Bool}},QuadratureAdjoint{0,true,Val{:central},Bool},Array{Float64,1},RODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},NoiseProcess{Float64,2,Float64,Array{Float64,1},Array{Float64,1},Array{Array{Float64,1},1},typeof(DiffEqNoiseProcess.WHITE_NOISE_DIST),typeof(DiffEqNoiseProcess.WHITE_NOISE_BRIDGE),false,ResettableStacks.ResettableStack{Tuple{Float64,Array{Float64,1},Array{Float64,1}},false},ResettableStacks.ResettableStack{Tuple{Float64,Array{Float64,1},Array{Float64,1}},false},RSWM{Float64},Nothing,RandomNumbers.Xorshifts.Xoroshiro128Plus},SDEProblem{Array{Float64,1},Tuple{Float64,Float64},false,NamedTuple{(:r, :σ),Tuple{Float64,Float64}},Nothing,SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(gs),Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},Nothing},SRIW1,StochasticDiffEq.LinearInterpolationData{Array{Array{Float64,1},1},Array{Float64,1}},DiffEqBase.DEStats},SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}, ::Bool, ::Nothing, ::Nothing) at /home/borghi/.julia/dev/DiffEqSensitivity/src/local_sensitivity/derivative_wrappers.jl:193 17. vecjacobian!(::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}, ::Float64, ::DiffEqSensitivity.ODEQuadratureAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},LinearAlgebra.UniformScaling{Bool}},QuadratureAdjoint{0,true,Val{:central},Bool},Array{Float64,1},RODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},NoiseProcess{Float64,2,Float64,Array{Float64,1},Array{Float64,1},Array{Array{Float64,1},1},typeof(DiffEqNoiseProcess.WHITE_NOISE_DIST),typeof(DiffEqNoiseProcess.WHITE_NOISE_BRIDGE),false,ResettableStacks.ResettableStack{Tuple{Float64,Array{Float64,1},Array{Float64,1}},false},ResettableStacks.ResettableStack{Tuple{Float64,Array{Float64,1},Array{Float64,1}},false},RSWM{Float64},Nothing,RandomNumbers.Xorshifts.Xoroshiro128Plus},SDEProblem{Array{Float64,1},Tuple{Float64,Float64},false,NamedTuple{(:r, :σ),Tuple{Float64,Float64}},Nothing,SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(gs),Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},Nothing},SRIW1,StochasticDiffEq.LinearInterpolationData{Array{Array{Float64,1},1},Array{Float64,1}},DiffEqBase.DEStats},SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}; dgrad::Nothing, dy::Nothing) at /home/borghi/.julia/dev/DiffEqSensitivity/src/local_sensitivity/derivative_wrappers.jl:147 18. vecjacobian!(::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::NamedTuple{(:r, :σ),Tuple{Float64,Float64}}, ::Float64, ::DiffEqSensitivity.ODEQuadratureAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},LinearAlgebra.UniformScaling{Bool}},QuadratureAdjoint{0,true,Val{:central},Bool},Array{Float64,1},RODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},NoiseProcess{Float64,2,Float64,Array{Float64,1},Array{Float64,1},Array{Array{Float64,1},1},typeof(DiffEqNoiseProcess.WHITE_NOISE_DIST),typeof(DiffEqNoiseProcess.WHITE_NOISE_BRIDGE),false,ResettableStacks.ResettableStack{Tuple{Float64,Array{Float64,1},Array{Float64,1}},false},ResettableStacks.ResettableStack{Tuple{Float64,Array{Float64,1},Array{Float64,1}},false},RSWM{Float64},Nothing,RandomNumbers.Xorshifts.Xoroshiro128Plus},SDEProblem{Array{Float64,1},Tuple{Float64,Float64},false,NamedTuple{(:r, :σ),Tuple{Float64,Float64}},Nothing,SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},typeof(gs),Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},Nothing},SRIW1,StochasticDiffEq.LinearInterpolationData{Array{Array{Float64,1},1},Array{Float64,1}},DiffEqBase.DEStats},SDEFunction{false,typeof(fs),typeof(gs),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}) at /home/borghi/.julia/dev/DiffEqSensitivity/src/local_sensitivity/derivative_wrappers.jl:147 [18] (::DiffEqSensitivity.ODEQuadratureAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},LinearAlgebra.UniformScaling{Bool}},QuadratureAdjoint{0,true,Val{:central},Bool},Array{Float64,1},RODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},NoiseProcess{Float64,2,Float64,Array{Float64,1},Array{Float64,1},Array{Array{Float64,1},1},typeof(DiffEqNoiseProcess.WHITE_NOISE_DIST),typeof(DiffEqNoiseProcess.WHITE_NOISE_BRIDGE),false,ResettableStacks.ResettableStack{Tuple{Float64,Array{Float64,1},Array{Float64,1}},false},ResettableStacks.ResettableStack{Tuple{Floa

Thanks in advance.

mattborghi avatar Oct 09 '20 20:10 mattborghi

Yes, the object for the parameters needs to be some kind of abstract array, otherwise math is not defined on it. This is something I'm hoping to fix, but for now, you need a type that is suitable as a differential equation array (such as any <:AbstractArray)

ChrisRackauckas avatar Oct 12 '20 06:10 ChrisRackauckas

Thank you Chris! Is there any issue open right now in order to track the progress?

mattborghi avatar Oct 13 '20 12:10 mattborghi

I guess https://github.com/SciML/DiffEqFlux.jl/issues/178 was it, but this is a better issue to track it from so I'll leave this open. DiffEqFlux's issue here is essentially a DiffEqSensitivity issue in that it needs to build a new differential equation.

ChrisRackauckas avatar Oct 13 '20 17:10 ChrisRackauckas