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

Support for complex matrix ODEs #74

Closed
seadra opened this issue Aug 10, 2019 · 26 comments
Closed

Support for complex matrix ODEs #74

seadra opened this issue Aug 10, 2019 · 26 comments
Labels

Comments

@seadra
Copy link

seadra commented Aug 10, 2019

I'm adapt the first and simplest example in the readme, but diffeq_rd doesn't seem to be working with a complex matrix ODE.
Even something like

function myode(du,u,p,t)
    du = u;
end

or

function myode(u,p,t)
    return u;
end

doesn't seem to be working. As the initial condition, I'm using a 2x2 identity matrix with Complex{Float64} entries. t is Float64. solve() does work with no issues but diffeq_rd gives

MethodError: no method matching Array{Float64,1}(::Array{Complex{Float64},2})

@ChrisRackauckas
Copy link
Member

Yeah, somewhat of a duplicate for #34 . We are addressing this problem with a new AD.

@seadra
Copy link
Author

seadra commented Aug 10, 2019

Thanks!

I'm working on a problem and currently exploring possibilities but I'm time-constrained. Seeing #34 wasn't updated in the past 4 months, I was wondering if you had any (vague) timeline for that?

@ChrisRackauckas
Copy link
Member

End of the month. We needed to build a new forward mode AD to fix it and like 5 other issues. The new AD will be released quite soon.

@seadra
Copy link
Author

seadra commented Sep 6, 2019

Any developments on that front?

@ChrisRackauckas ChrisRackauckas changed the title Support for matrix ODEs Support for complex matrix ODEs Sep 6, 2019
@ChrisRackauckas
Copy link
Member

It's happening here: https://github.com/YingboMa/ForwardDiff2.jl . Shashi had to take some time off but he's back and will likely continue this.

@seadra
Copy link
Author

seadra commented Jun 19, 2020

Using the most recent versions, solve is now working now, but sciml_train fails.

Here's a minimal reproduction code:

A  = [1.0*im  2.0; 3.0 4.0]

u0 = [1.0 0.0*im; 0.0 1.0]
tspan = (0.0, 1.0)

#f(u,p,t) = A*u

function f(du,u,p,t)
    du .= (A*u)*(p[1]*t + p[2]*t^2 + p[3]*t^3 + p[4]*t^4)
end

prob = ODEProblem(f,u0,tspan)

utarget = [0.0*im 1.0; 1.0 0.0]

function loss_adjoint(p)
    ufinal = last(solve(prob, Tsit5(), p=p).u)
    loss = 1 - abs(tr(ufinal*utarget')/2)^2
    return loss
end

p = [1.5, 1.0, 3.0, 1.0]

solve(prob, Tsit5()) # <--- this now works

DiffEqFlux.sciml_train(loss_adjoint, p, BFGS(initial_stepnorm = 0.0001))  # <--- this fails

This fails with the error:

TypeError: in TrackedReal, in V, expected V<:Real, got Type{Complex{Float64}}
Full stack trace TypeError: in TrackedReal, in V, expected V<:Real, got Type{Complex{Float64}}

Stacktrace:
[1] ReverseDiff.TrackedArray(::Array{Complex{Float64},2}, ::Array{Complex{Float64},2}, ::Array{ReverseDiff.AbstractInstruction,1}) at /home/user/.julia/packages/ReverseDiff/uy0uk/src/tracked.jl:86
[2] track(::Array{Complex{Float64},2}, ::Type{Complex{Float64}}, ::Array{ReverseDiff.AbstractInstruction,1}) at /home/user/.julia/packages/ReverseDiff/uy0uk/src/tracked.jl:387
[3] (::ReverseDiff.var"#543#544"{Complex{Float64},Array{ReverseDiff.AbstractInstruction,1}})(::Array{Complex{Float64},2}) at /home/user/.julia/packages/ReverseDiff/uy0uk/src/api/Config.jl:46
[4] map(::ReverseDiff.var"#543#544"{Complex{Float64},Array{ReverseDiff.AbstractInstruction,1}}, ::Tuple{Array{Complex{Float64},2},Array{Float64,1},Array{Float64,1}}) at ./tuple.jl:159
[5] ReverseDiff.GradientConfig(::Tuple{Array{Complex{Float64},2},Array{Float64,1},Array{Float64,1}}, ::Type{Complex{Float64}}, ::Array{ReverseDiff.AbstractInstruction,1}) at /home/user/.julia/packages/ReverseDiff/uy0uk/src/api/Config.jl:46
[6] ReverseDiff.GradientConfig(::Tuple{Array{Complex{Float64},2},Array{Float64,1},Array{Float64,1}}, ::Array{ReverseDiff.AbstractInstruction,1}) at /home/user/.julia/packages/ReverseDiff/uy0uk/src/api/Config.jl:37 (repeats 2 times)
[7] ReverseDiff.GradientTape(::Function, ::Tuple{Array{Complex{Float64},2},Array{Float64,1},Array{Float64,1}}) at /home/user/.julia/packages/ReverseDiff/uy0uk/src/api/tape.jl:204
[8] adjointdiffcache(::Function, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::Bool, ::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::Nothing, ::ODEFunction{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}; quad::Bool, noiseterm::Bool) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/adjoint_common.jl:114
[9] adjointdiffcache at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/adjoint_common.jl:27 [inlined]
[10] DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction(::Function, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::Bool, ::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::Nothing, ::Array{Float64,1}, ::NamedTuple{(:reltol, :abstol),Tuple{Float64,Float64}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/interpolating_adjoint.jl:36
[11] ODEAdjointProblem(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::DiffEqSensitivity.var"#df#126"{NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Array{Union{Nothing, Array{Complex{Float64},2}},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},Array{Complex{Float64},2},Colon}, ::Array{Float64,1}, ::Nothing; checkpoints::Array{Float64,1}, callback::CallbackSet{Tuple{},Tuple{}}, reltol::Float64, abstol::Float64, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/interpolating_adjoint.jl:114
[12] _adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::Tsit5, ::DiffEqSensitivity.var"#df#126"{NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Array{Union{Nothing, Array{Complex{Float64},2}},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},Array{Complex{Float64},2},Colon}, ::Array{Float64,1}, ::Nothing; abstol::Float64, reltol::Float64, checkpoints::Array{Float64,1}, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/sensitivity_interface.jl:17
[13] _adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::Tsit5, ::Function, ::Array{Float64,1}, ::Nothing) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/sensitivity_interface.jl:13 (repeats 2 times)
[14] adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::Tsit5, ::Vararg{Any,N} where N; sensealg::InterpolatingAdjoint{0,true,Val{:central},Bool}, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/sensitivity_interface.jl:6
[15] (::DiffEqSensitivity.var"#adjoint_sensitivity_backpass#125"{Tsit5,InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},Array{Float64,1},Tuple{},Colon})(::NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Array{Union{Nothing, Array{Complex{Float64},2}},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/concrete_solve.jl:113
[16] #521#back at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [inlined]
[17] #175 at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [inlined]
[18] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{DiffEqBase.var"#521#back#466"{DiffEqSensitivity.var"#adjoint_sensitivity_backpass#125"{Tsit5,InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},Array{Float64,1},Tuple{},Colon}},Tuple{NTuple{4,Nothing},Tuple{Nothing}}}})(::NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Array{Union{Nothing, Array{Complex{Float64},2}},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49
[19] #solve#453 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:106 [inlined]
[20] (::typeof(∂(#solve#453)))(::NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Array{Union{Nothing, Array{Complex{Float64},2}},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0
[21] (::Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}})(::NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Array{Union{Nothing, Array{Complex{Float64},2}},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}) at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182
[22] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}}})(::NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Array{Union{Nothing, Array{Complex{Float64},2}},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49
[23] (::typeof(∂(solve##kw)))(::NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Array{Union{Nothing, Array{Complex{Float64},2}},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0
[24] loss_adjoint at ./In[189]:16 [inlined]
[25] (::typeof(∂(loss_adjoint)))(::Int64) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0
[26] #175 at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [inlined]
[27] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{typeof(∂(loss_adjoint)),Tuple{Tuple{Nothing},Int64}}})(::Int64) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49
[28] #43 at /home/user/.julia/packages/DiffEqFlux/61JUC/src/train.jl:176 [inlined]
[29] (::typeof(∂(λ)))(::Int64) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0
[30] #37 at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface.jl:45 [inlined]
[31] (::DiffEqFlux.var"#46#59"{DiffEqFlux.var"#43#56"{typeof(loss_adjoint)}})(::Array{Float64,1}, ::Array{Float64,1}) at /home/user/.julia/packages/DiffEqFlux/61JUC/src/train.jl:199
[32] value_gradient!!(::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}) at /home/user/.julia/packages/NLSolversBase/mGaJg/src/interface.jl:82
[33] initial_state(::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Optim.Options{Float64,DiffEqFlux.var"#_cb#55"{DiffEqFlux.var"#53#66",Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}}}, ::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}) at /home/user/.julia/packages/Optim/L5T76/src/multivariate/solvers/first_order/bfgs.jl:66
[34] optimize(::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}, ::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Optim.Options{Float64,DiffEqFlux.var"#_cb#55"{DiffEqFlux.var"#53#66",Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}}}) at /home/user/.julia/packages/Optim/L5T76/src/multivariate/optimize/optimize.jl:33
[35] sciml_train(::Function, ::Array{Float64,1}, ::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}; cb::Function, maxiters::Int64, diffmode::DiffEqFlux.ZygoteDiffMode, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqFlux/61JUC/src/train.jl:269
[36] sciml_train at /home/user/.julia/packages/DiffEqFlux/61JUC/src/train.jl:163 [inlined] (repeats 2 times)
[37] top-level scope at In[189]:22

@seadra
Copy link
Author

seadra commented Jun 19, 2020

On a related note, it appears it is also impossible to use @SMatrix with sciml_train.

If I add @SMatrix in the definitions in A and u0 in the example above, I get a different error:

MethodError: no method matching OrdinaryDiffEq.Tsit5Cache(::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::MArray{Tuple{2,2},Complex{Float64},2,4}, ::MArray{Tuple{2,2},Complex{Float64},2,4}, ::MArray{Tuple{2,2},Complex{Float64},2,4}, ::OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64})

Full stack trace MethodError: no method matching OrdinaryDiffEq.Tsit5Cache(::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::MArray{Tuple{2,2},Complex{Float64},2,4}, ::MArray{Tuple{2,2},Complex{Float64},2,4}, ::MArray{Tuple{2,2},Complex{Float64},2,4}, ::OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}) Closest candidates are: OrdinaryDiffEq.Tsit5Cache(::#226#uType, ::#226#uType, ::#227#rateType, ::#227#rateType, ::#227#rateType, ::#227#rateType, ::#227#rateType, ::#227#rateType, ::#227#rateType, !Matched::#226#uType, !Matched::#226#uType, ::#228#uNoUnitsType, ::#229#TabType) where {#226#uType, #227#rateType, #228#uNoUnitsType, #229#TabType} at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/caches/low_order_rk_caches.jl:272

Stacktrace:
[1] alg_cache(::Tsit5, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Type{T} where T, ::Type{T} where T, ::Type{T} where T, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::ODEFunction{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}, ::Float64, ::Float64, ::Float64, ::Array{Float64,1}, ::Bool, ::Val{true}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/caches/low_order_rk_caches.jl:359
[2] __init(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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, ::Tuple{}, ::Tuple{}, ::Tuple{}, ::Type{Val{true}}; saveat::Tuple{}, tstops::Tuple{}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Bool, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Nothing, reltol::Nothing, qmin::Rational{Int64}, qmax::Int64, qsteady_min::Int64, qsteady_max::Int64, qoldinit::Rational{Int64}, fullnormalize::Bool, failfactor::Int64, beta1::Nothing, beta2::Nothing, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias_u0::Bool, alias_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:save_noise,),Tuple{Bool}}}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/solve.jl:271
[3] __solve(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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; kwargs::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:save_noise, :save_start, :save_end),Tuple{Bool,Bool,Bool}}}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/solve.jl:4
[4] solve_call(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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; merge_callbacks::Bool, kwargs::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:save_noise, :save_start, :save_end),Tuple{Bool,Bool,Bool}}}) at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:96
[5] solve_up(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::Nothing, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Array{Float64,1}, ::Tsit5; kwargs::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:save_noise, :save_start, :save_end),Tuple{Bool,Bool,Bool}}}) at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:122
[6] solve(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,typeof(f),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; sensealg::Nothing, u0::Nothing, p::Nothing, kwargs::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:save_noise, :save_start, :save_end),Tuple{Bool,Bool,Bool}}}) at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:106
[7] _concrete_solve_adjoint(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),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, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Array{Float64,1}; save_start::Bool, save_end::Bool, saveat::Array{Float64,1}, save_idxs::Nothing, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/concrete_solve.jl:41
[8] _concrete_solve_adjoint(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),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, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Array{Float64,1}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/concrete_solve.jl:25
[9] _concrete_solve_adjoint(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),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, ::Nothing, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Array{Float64,1}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/concrete_solve.jl:11
[10] _concrete_solve_adjoint(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),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, ::Nothing, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Array{Float64,1}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/concrete_solve.jl:8
[11] _solve_adjoint(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::Nothing, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Array{Float64,1}, ::Tsit5; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:327
[12] _solve_adjoint(::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::Nothing, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Array{Float64,1}, ::Tsit5) at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:324
[13] #adjoint#465 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:291 [inlined]
[14] adjoint at ./none:0 [inlined]
[15] _pullback at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47 [inlined]
[16] adjoint at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:179 [inlined]
[17] _pullback at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47 [inlined]
[18] #solve#453 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:106 [inlined]
[19] _pullback(::Zygote.Context, ::DiffEqBase.var"##solve#453", ::Nothing, ::Nothing, ::Array{Float64,1}, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(solve), ::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),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) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0
[20] adjoint at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:179 [inlined]
[21] _pullback at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47 [inlined]
[22] _pullback(::Zygote.Context, ::DiffEqBase.var"#solve##kw", ::NamedTuple{(:p,),Tuple{Array{Float64,1}}}, ::typeof(solve), ::ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(f),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) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0
[23] loss_adjoint at ./In[192]:16 [inlined]
[24] _pullback(::Zygote.Context, ::typeof(loss_adjoint), ::Array{Float64,1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0
[25] adjoint(::Zygote.Context, ::typeof(Core._apply_iterate), ::typeof(iterate), ::Function, ::Tuple{Array{Float64,1}}, ::DiffEqFlux.NullData) at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:179
[26] _pullback at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47 [inlined]
[27] #43 at /home/user/.julia/packages/DiffEqFlux/61JUC/src/train.jl:176 [inlined]
[28] _pullback(::Zygote.Context, ::DiffEqFlux.var"#43#56"{typeof(loss_adjoint)}, ::Array{Float64,1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0
[29] _pullback at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface.jl:38 [inlined]
[30] pullback at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface.jl:44 [inlined]
[31] (::DiffEqFlux.var"#46#59"{DiffEqFlux.var"#43#56"{typeof(loss_adjoint)}})(::Array{Float64,1}, ::Array{Float64,1}) at /home/user/.julia/packages/DiffEqFlux/61JUC/src/train.jl:197
[32] value_gradient!!(::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}) at /home/user/.julia/packages/NLSolversBase/mGaJg/src/interface.jl:82
[33] initial_state(::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Optim.Options{Float64,DiffEqFlux.var"#_cb#55"{DiffEqFlux.var"#53#66",Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}}}, ::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}) at /home/user/.julia/packages/Optim/L5T76/src/multivariate/solvers/first_order/bfgs.jl:66
[34] optimize(::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}, ::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Optim.Options{Float64,DiffEqFlux.var"#_cb#55"{DiffEqFlux.var"#53#66",Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}}}) at /home/user/.julia/packages/Optim/L5T76/src/multivariate/optimize/optimize.jl:33
[35] sciml_train(::Function, ::Array{Float64,1}, ::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}; cb::Function, maxiters::Int64, diffmode::DiffEqFlux.ZygoteDiffMode, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqFlux/61JUC/src/train.jl:269
[36] sciml_train at /home/user/.julia/packages/DiffEqFlux/61JUC/src/train.jl:163 [inlined] (repeats 2 times)
[37] top-level scope at In[192]:22

Should I open a separate issue for this one?

@ChrisRackauckas
Copy link
Member

yeah though I don't know if that's fixable. I'll just tag that as an upstream issue that the reverse-mode AD libraries need a mutable array type.

For complex, try sensealg=InterpolatingAdjoint(autojacvec=ZygoteVJP()). It might just be a ReverseDiff issue.

@seadra
Copy link
Author

seadra commented Jun 19, 2020

Thanks for the quick response!

The loss function is real in my case, it's just that it is calculated from a complex matrix. When you said "I don't know if that's fixable", do you mean complex numbers at intermediate steps are fundamentally impossible?

I tried adding the sensealg option to solve, and it's giving a different error now:

MethodError: no method matching size(::NamedTuple{(:u, :u_analytic, :errors, :t, :k, :prob, :alg, :interp, :dense, :tslocation, :destats, :retcode),Tuple{Array{Union{Nothing, Array{Complex{Float64},2}},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}})
Closest candidates are:
size(!Matched::BitArray{1}) at bitarray.jl:99
size(!Matched::BitArray{1}, !Matched::Integer) at bitarray.jl:103
size(!Matched::Core.Compiler.StmtRange) at show.jl:1845

ChrisRackauckas added a commit to SciML/SciMLSensitivity.jl that referenced this issue Jun 20, 2020
@ChrisRackauckas
Copy link
Member

ChrisRackauckas commented Jun 20, 2020

This derivative requires a gradient in the complex plane, so the full example is:

using DiffEqSensitivity, OrdinaryDiffEq, Zygote, LinearAlgebra, FiniteDiff, Test
A  = [1.0*im  2.0; 3.0 4.0]
u0 = [1.0 0.0*im; 0.0 1.0]
tspan = (0.0, 1.0)

function f(u,p,t)
    (A*u)*(p[1]*t + p[2]*t^2 + p[3]*t^3 + p[4]*t^4)
end

p = [1.5 + im, 1.0, 3.0, 1.0]
prob = ODEProblem(f,u0,tspan,p)

utarget = [0.0*im 1.0; 1.0 0.0]

function loss_adjoint(p)
    ufinal = last(solve(prob, Tsit5(), p=p, abstol=1e-12, reltol=1e-12))
    loss = 1 - abs(tr(ufinal*utarget')/2)^2
    return loss
end

grad1 = Zygote.gradient(loss_adjoint,Complex{Float64}[1.5, 1.0, 3.0, 1.0])[1]
grad2 = FiniteDiff.finite_difference_gradient(loss_adjoint,Complex{Float64}[1.5, 1.0, 3.0, 1.0])
@test grad1  grad2

@ChrisRackauckas
Copy link
Member

This test was added to SciML/SciMLSensitivity.jl#289 so we can close this when that test merges, but it should work right now.

@seadra
Copy link
Author

seadra commented Jun 20, 2020

Whoa, thanks!

I actually started rewriting all my equations by manually splitting the real and imaginary parts, which quickly became tedious. This is going to be a huge boost, thanks again!

@seadra
Copy link
Author

seadra commented Jun 22, 2020

Thanks for the fixes! I tried with the merged commit, and the old error is definitely gone, and the gradient tests pass.

In this "proper" example. the gradient test passes, but sciml_train still fails, although with a new error now: InexactError: Float64(-0.0 + 0.19599520476388266im):

using DiffEqSensitivity, OrdinaryDiffEq, Zygote, LinearAlgebra, FiniteDiff, Test, DiffEqFlux, Optim

const T = 10.0;
const ω = π/T;

function f(u, p, t)
    a = p[1]*sin*t) + p[2]*sin(2*ω*t) + p[3]*sin(3*ω*t) + p[4]*sin(4*ω*t);
    A = [1.0 a; a -1.0];
    return -im*A*u;
end


u0 = [Complex{Float64}(1) 0; 0 1];

tspan = (0.0, T)
p = [0.7, 1.0, 3.0, 1.0]

prob_ode = ODEProblem{false}(f, u0, tspan, p);
sol_ode = solve(prob_ode, Tsit5());


utarget = [Complex{Float64}(0) im; im 0];

function predict_adjoint(p)
  return solve(prob_ode, Tsit5(), p=p, abstol=1e-12, reltol=1e-12)
end

function loss_adjoint(p)
    prediction = predict_adjoint(p)
    usol = last(prediction)
    loss = 1.0 - abs(tr(usol*utarget')/2)^2
    return loss
end

grad1 = Zygote.gradient(loss_adjoint,Complex{Float64}[1.5, 1.0, 3.0, 1.0])[1]
grad2 = FiniteDiff.finite_difference_gradient(loss_adjoint,Complex{Float64}[1.5, 1.0, 3.0, 1.0])

@test grad1  grad2 # <- succeeds

DiffEqFlux.sciml_train(loss_adjoint, p, BFGS(initial_stepnorm = 0.0001)) # <- fails
Stacktrace Stacktrace: [1] Real at ./complex.jl:37 [inlined] [2] convert at ./number.jl:7 [inlined] [3] setindex! at ./array.jl:826 [inlined] [4] setindex! at ./subarray.jl:301 [inlined] [5] copyto!(::SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}, ::Array{Complex{Float64},1}) at ./multidimensional.jl:962 [6] copyto! at ./broadcast.jl:905 [inlined] [7] copyto! at ./broadcast.jl:864 [inlined] [8] materialize! at ./broadcast.jl:823 [inlined] [9] (::DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon})(::SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}, ::Array{Complex{Float64},2}, ::Array{Float64,1}, ::Float64, ::Int64) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/concrete_solve.jl:97 [10] (::DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}})(::OrdinaryDiffEq.ODEIntegrator{Tsit5,true,Array{Float64,1},Nothing,Float64,Array{Float64,1},Float64,Float64,Float64,Array{Array{Float64,1},1},ODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}},OrdinaryDiffEq.DEOptions{Float64,Float64,Float64,Float64,typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(opnorm),CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Nothing,Nothing,Int64,Array{Float64,1},Array{Complex{Float64},1},Tuple{}},Array{Float64,1},Float64,Nothing,OrdinaryDiffEq.DefaultInit}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/adjoint_common.jl:277 [11] (::DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}})(::OrdinaryDiffEq.ODEIntegrator{Tsit5,true,Array{Float64,1},Nothing,Float64,Array{Float64,1},Float64,Float64,Float64,Array{Array{Float64,1},1},ODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}},OrdinaryDiffEq.DEOptions{Float64,Float64,Float64,Float64,typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(opnorm),CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Nothing,Nothing,Int64,Array{Float64,1},Array{Complex{Float64},1},Tuple{}},Array{Float64,1},Float64,Nothing,OrdinaryDiffEq.DefaultInit}) at /home/user/.julia/packages/DiffEqCallbacks/N6mXi/src/iterative_and_periodic.jl:12 [12] #35 at /home/user/.julia/packages/DiffEqCallbacks/N6mXi/src/iterative_and_periodic.jl:42 [inlined] [13] initialize! at /home/user/.julia/packages/DiffEqBase/LGnTa/src/callbacks.jl:325 [inlined] [14] initialize! at /home/user/.julia/packages/DiffEqBase/LGnTa/src/callbacks.jl:315 [inlined] [15] initialize_callbacks!(::OrdinaryDiffEq.ODEIntegrator{Tsit5,true,Array{Float64,1},Nothing,Float64,Array{Float64,1},Float64,Float64,Float64,Array{Array{Float64,1},1},ODESolution{Float64,2,Array{Array{Float64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Float64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},DiffEqBase.DEStats},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5Cache{Array{Float64,1},Array{Float64,1},Array{Float64,1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}},OrdinaryDiffEq.DEOptions{Float64,Float64,Float64,Float64,typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(opnorm),CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Nothing,Nothing,Int64,Array{Float64,1},Array{Complex{Float64},1},Tuple{}},Array{Float64,1},Float64,Nothing,OrdinaryDiffEq.DefaultInit}, ::Bool) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/solve.jl:520 [16] __init(::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem}, ::Tsit5, ::Tuple{}, ::Tuple{}, ::Tuple{}, ::Type{Val{true}}; saveat::Array{Complex{Float64},1}, tstops::Array{Float64,1}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Bool, callback::CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Float64, reltol::Float64, qmin::Rational{Int64}, qmax::Int64, qsteady_min::Int64, qsteady_max::Int64, qoldinit::Rational{Int64}, fullnormalize::Bool, failfactor::Int64, beta1::Nothing, beta2::Nothing, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias_u0::Bool, alias_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/solve.jl:402 [17] #__solve#360 at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/solve.jl:4 [inlined] [18] solve_call(::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},true,Array{Float64,1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Float64,1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem}, ::Tsit5; merge_callbacks::Bool, kwargs::Base.Iterators.Pairs{Symbol,Any,NTuple{6,Symbol},NamedTuple{(:save_everystep, :save_start, :saveat, :tstops, :abstol, :reltol),Tuple{Bool,Bool,Array{Complex{Float64},1},Array{Float64,1},Float64,Float64}}}) at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:96 [19] #solve_up#454 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:122 [inlined] [20] #solve#453 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:106 [inlined] [21] _adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats}, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::Tsit5, ::DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon}, ::Array{Float64,1}, ::Nothing; abstol::Float64, reltol::Float64, checkpoints::Array{Float64,1}, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/sensitivity_interface.jl:21 [22] adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Float64,1},ODEFunction{false,typeof(schrodinger),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,typeof(schrodinger),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats}, ::Tsit5, ::Vararg{Any,N} where N; sensealg::InterpolatingAdjoint{0,true,Val{:central},Bool}, kwargs::Base.Iterators.Pairs{Symbol,Float64,Tuple{Symbol,Symbol},NamedTuple{(:abstol, :reltol),Tuple{Float64,Float64}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/sensitivity_interface.jl:6 [23] (::DiffEqSensitivity.var"#adjoint_sensitivity_backpass#125"{Tsit5,InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},Array{Float64,1},Tuple{},Colon})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/concrete_solve.jl:113 [24] #526#back at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:55 [inlined] [25] #175 at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [inlined] [26] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{DiffEqBase.var"#526#back#467"{DiffEqSensitivity.var"#adjoint_sensitivity_backpass#125"{Tsit5,InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},Array{Float64,1},Tuple{},Colon}},Tuple{NTuple{6,Nothing},Tuple{Nothing}}}})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [27] #solve#453 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:106 [inlined] [28] (::typeof(∂(#solve#453)))(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [29] (::Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [30] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}}})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [31] (::typeof(∂(solve##kw)))(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [32] predict_adjoint at ./In[22]:24 [inlined] [33] (::typeof(∂(predict_adjoint)))(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [34] loss_adjoint at ./In[22]:28 [inlined] [35] #175 at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [inlined] [36] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{typeof(∂(loss_adjoint)),Tuple{Tuple{Nothing},Int64}}})(::Int64) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [37] #43 at /home/user/.julia/packages/DiffEqFlux/GYa64/src/train.jl:176 [inlined] [38] (::typeof(∂(λ)))(::Int64) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [39] #37 at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface.jl:45 [inlined] [40] (::DiffEqFlux.var"#46#59"{DiffEqFlux.var"#43#56"{typeof(loss_adjoint)}})(::Array{Float64,1}, ::Array{Float64,1}) at /home/user/.julia/packages/DiffEqFlux/GYa64/src/train.jl:199 [41] value_gradient!!(::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}) at /home/user/.julia/packages/NLSolversBase/mGaJg/src/interface.jl:82 [42] initial_state(::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Optim.Options{Float64,DiffEqFlux.var"#_cb#55"{DiffEqFlux.var"#53#66",Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}}}, ::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}) at /home/user/.julia/packages/Optim/L5T76/src/multivariate/solvers/first_order/bfgs.jl:66 [43] optimize(::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}, ::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Optim.Options{Float64,DiffEqFlux.var"#_cb#55"{DiffEqFlux.var"#53#66",Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}}}) at /home/user/.julia/packages/Optim/L5T76/src/multivariate/optimize/optimize.jl:33 [44] sciml_train(::Function, ::Array{Float64,1}, ::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}; cb::Function, maxiters::Int64, diffmode::DiffEqFlux.ZygoteDiffMode, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqFlux/GYa64/src/train.jl:269 [45] sciml_train at /home/user/.julia/packages/DiffEqFlux/GYa64/src/train.jl:163 [inlined] (repeats 2 times) [46] top-level scope at In[22]:38

It seems to be working if I change predict_adjoint as, though

function predict_adjoint(p)
  return solve(prob_ode, Tsit5(), p=Complex{Float64}.(p), abstol=1e-12, reltol=1e-12)
end

Is this the way solve should be called, even for a real set of parameters?

Another strange thing I came accross is that the gradient test also fails if the definition of ω is changed as

const ω = 2*π/T;

in which case grad1 is non-zero whereas grad2 is zero.

@seadra
Copy link
Author

seadra commented Jun 22, 2020

I just tried using @SMatrix to speed things up a little, but there appears to a separate issue with regards to that, seemingly in DiffEqBase:

using DiffEqSensitivity, OrdinaryDiffEq, Zygote, LinearAlgebra, FiniteDiff, Test, DiffEqFlux, Optim

const T = 10.0;
const ω = π/T;

function f(u, p, t)
    a = p[1]*sin*t) + p[2]*sin(2*ω*t) + p[3]*sin(3*ω*t) + p[4]*sin(4*ω*t);
    A = @SMatrix [1.0 a; a -1.0];
    return -im*A*u;
end


u0 = @SMatrix [Complex{Float64}(1) 0; 0 1];

tspan = (0.0, T)
p = @MVector [0.7, 1.0, 3.0, 1.0]

prob_ode = ODEProblem{false}(f, u0, tspan, p);
sol_ode = solve(prob_ode, Tsit5());


utarget = [Complex{Float64}(0) im; im 0];

function predict_adjoint(p)
  return solve(prob_ode, Tsit5(), p=Complex{Float64}.(p), abstol=1e-12, reltol=1e-12)
end

function loss_adjoint(p)
    prediction = predict_adjoint(p)
    usol = last(prediction)
    loss = 1.0 - abs(tr(usol*utarget')/2)^2
    return loss
end

DiffEqFlux.sciml_train(loss_adjoint, p, BFGS(initial_stepnorm = 0.0001)) # <- fails

with the error message:

setindex!(::SArray{Tuple{2,2},Complex{Float64},2,4}, value, ::Int) is not defined.

Stacktrace Stacktrace: [1] setindex!(::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Complex{Float64}, ::Int64) at /home/user/.julia/packages/StaticArrays/mlIi1/src/indexing.jl:3 [2] macro expansion at /home/user/.julia/packages/StaticArrays/mlIi1/src/broadcast.jl:155 [inlined] [3] _broadcast! at /home/user/.julia/packages/StaticArrays/mlIi1/src/broadcast.jl:135 [inlined] [4] _copyto! at /home/user/.julia/packages/StaticArrays/mlIi1/src/broadcast.jl:39 [inlined] [5] copyto! at /home/user/.julia/packages/StaticArrays/mlIi1/src/broadcast.jl:30 [inlined] [6] materialize! at ./broadcast.jl:823 [inlined] [7] macro expansion at /home/user/.julia/packages/DiffEqBase/LGnTa/src/diffeqfastbc.jl:88 [inlined] [8] _ode_interpolant!(::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Float64, ::Float64, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Array{SArray{Tuple{2,2},Complex{Float64},2,4},1}, ::OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}, ::Nothing, ::Type{Val{0}}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/dense/interpolants.jl:291 [9] ode_interpolant!(::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Float64, ::Float64, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Array{SArray{Tuple{2,2},Complex{Float64},2,4},1}, ::OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}, ::Nothing, ::Type{Val{0}}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/dense/generic_dense.jl:384 [10] ode_interpolation!(::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Float64, ::Function, ::Nothing, ::Type{T} where T, ::Array{Complex{Float64},1}, ::Symbol) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/dense/generic_dense.jl:327 [11] InterpolationData at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/interp_func.jl:75 [inlined] [12] #_#19 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solutions/ode_solutions.jl:19 [inlined] [13] (::ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats})(::SArray{Tuple{2,2},Complex{Float64},2,4}, ::Float64, ::Type{T} where T) at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solutions/ode_solutions.jl:19 (repeats 2 times) [14] (::DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},SArray{Tuple{2,2},Complex{Float64},2,4},ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}})(::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}, ::Float64) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/interpolating_adjoint.jl:60 [15] (::ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},SArray{Tuple{2,2},Complex{Float64},2,4},ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing})(::Array{Complex{Float64},1}, ::Vararg{Any,N} where N) at /home/user/.julia/packages/DiffEqBase/LGnTa/src/diffeqfunction.jl:248 [16] initialize!(::OrdinaryDiffEq.ODEIntegrator{Tsit5,true,Array{Complex{Float64},1},Nothing,Float64,Array{Complex{Float64},1},Float64,Float64,Float64,Array{Array{Complex{Float64},1},1},ODESolution{Complex{Float64},2,Array{Array{Complex{Float64},1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},1},1},1},ODEProblem{Array{Complex{Float64},1},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},SArray{Tuple{2,2},Complex{Float64},2,4},ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},SArray{Tuple{2,2},Complex{Float64},2,4},ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},1},1},Array{Float64,1},Array{Array{Array{Complex{Float64},1},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},1},Array{Complex{Float64},1},Array{Complex{Float64},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},SArray{Tuple{2,2},Complex{Float64},2,4},ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},1},Array{Complex{Float64},1},Array{Complex{Float64},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},OrdinaryDiffEq.DEOptions{Float64,Float64,Float64,Float64,typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(opnorm),CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Nothing,Nothing,Int64,Array{Float64,1},Array{Complex{Float64},1},Tuple{}},Array{Complex{Float64},1},Complex{Float64},Nothing,OrdinaryDiffEq.DefaultInit}, ::OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},1},Array{Complex{Float64},1},Array{Complex{Float64},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/perform_step/low_order_rk_perform_step.jl:623 [17] __init(::ODEProblem{Array{Complex{Float64},1},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},SArray{Tuple{2,2},Complex{Float64},2,4},ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem}, ::Tsit5, ::Tuple{}, ::Tuple{}, ::Tuple{}, ::Type{Val{true}}; saveat::Array{Complex{Float64},1}, tstops::Array{Float64,1}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Bool, callback::CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Float64, reltol::Float64, qmin::Rational{Int64}, qmax::Int64, qsteady_min::Int64, qsteady_max::Int64, qoldinit::Rational{Int64}, fullnormalize::Bool, failfactor::Int64, beta1::Nothing, beta2::Nothing, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias_u0::Bool, alias_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/solve.jl:403 [18] #__solve#360 at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/solve.jl:4 [inlined] [19] solve_call(::ODEProblem{Array{Complex{Float64},1},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Array{Complex{Float64},1},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},SArray{Tuple{2,2},Complex{Float64},2,4},ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#88#90"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#89#91"{DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},SArray{Tuple{2,2},Complex{Float64},2,4},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem}, ::Tsit5; merge_callbacks::Bool, kwargs::Base.Iterators.Pairs{Symbol,Any,NTuple{6,Symbol},NamedTuple{(:save_everystep, :save_start, :saveat, :tstops, :abstol, :reltol),Tuple{Bool,Bool,Array{Complex{Float64},1},Array{Float64,1},Float64,Float64}}}) at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:96 [20] #solve_up#454 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:122 [inlined] [21] #solve#453 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:106 [inlined] [22] _adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats}, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::Tsit5, ::DiffEqSensitivity.var"#df#126"{Array{AbstractArray{Complex{Float64},2},1},SArray{Tuple{2,2},Complex{Float64},2,4},Colon}, ::Array{Float64,1}, ::Nothing; abstol::Float64, reltol::Float64, checkpoints::Array{Float64,1}, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/sensitivity_interface.jl:21 [23] adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Nothing,Nothing,Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},ODEProblem{SArray{Tuple{2,2},Complex{Float64},2,4},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(schrodinger!),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,typeof(schrodinger!),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},Array{Float64,1},Array{Array{SArray{Tuple{2,2},Complex{Float64},2,4},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats}, ::Tsit5, ::Vararg{Any,N} where N; sensealg::InterpolatingAdjoint{0,true,Val{:central},Bool}, kwargs::Base.Iterators.Pairs{Symbol,Float64,Tuple{Symbol,Symbol},NamedTuple{(:abstol, :reltol),Tuple{Float64,Float64}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/sensitivity_interface.jl:6 [24] (::DiffEqSensitivity.var"#adjoint_sensitivity_backpass#125"{Tsit5,InterpolatingAdjoint{0,true,Val{:central},Bool},SArray{Tuple{2,2},Complex{Float64},2,4},Array{Complex{Float64},1},Tuple{},Colon})(::Array{AbstractArray{Complex{Float64},2},1}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/concrete_solve.jl:113 [25] #526#back at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:55 [inlined] [26] #175 at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [inlined] [27] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{DiffEqBase.var"#526#back#467"{DiffEqSensitivity.var"#adjoint_sensitivity_backpass#125"{Tsit5,InterpolatingAdjoint{0,true,Val{:central},Bool},SArray{Tuple{2,2},Complex{Float64},2,4},Array{Complex{Float64},1},Tuple{},Colon}},Tuple{NTuple{6,Nothing},Tuple{Nothing}}}})(::Array{AbstractArray{Complex{Float64},2},1}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [28] #solve#453 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:106 [inlined] [29] (::typeof(∂(#solve#453)))(::Array{AbstractArray{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [30] (::Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}})(::Array{AbstractArray{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [31] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}}})(::Array{AbstractArray{Complex{Float64},2},1}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [32] (::typeof(∂(solve##kw)))(::Array{AbstractArray{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [33] predict_adjoint at ./In[75]:28 [inlined] [34] (::typeof(∂(predict_adjoint)))(::Array{AbstractArray{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [35] loss_adjoint at ./In[75]:32 [inlined] [36] (::typeof(∂(loss_adjoint)))(::Int64) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [37] #175 at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [inlined] [38] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{typeof(∂(loss_adjoint)),Tuple{Tuple{Nothing},Int64}}})(::Int64) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [39] #43 at /home/user/.julia/packages/DiffEqFlux/GYa64/src/train.jl:176 [inlined] [40] (::typeof(∂(λ)))(::Int64) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [41] #37 at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface.jl:45 [inlined] [42] (::DiffEqFlux.var"#46#59"{DiffEqFlux.var"#43#56"{typeof(loss_adjoint)}})(::Array{Float64,1}, ::Array{Float64,1}) at /home/user/.julia/packages/DiffEqFlux/GYa64/src/train.jl:199 [43] value_gradient!!(::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}) at /home/user/.julia/packages/NLSolversBase/mGaJg/src/interface.jl:82 [44] initial_state(::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Optim.Options{Float64,DiffEqFlux.var"#_cb#55"{DiffEqFlux.var"#53#66",Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}}}, ::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}) at /home/user/.julia/packages/Optim/L5T76/src/multivariate/solvers/first_order/bfgs.jl:66 [45] optimize(::TwiceDifferentiable{Float64,Array{Float64,1},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}, ::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Optim.Options{Float64,DiffEqFlux.var"#_cb#55"{DiffEqFlux.var"#53#66",Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}}}) at /home/user/.julia/packages/Optim/L5T76/src/multivariate/optimize/optimize.jl:33 [46] sciml_train(::Function, ::Array{Float64,1}, ::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}, ::Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}; cb::Function, maxiters::Int64, diffmode::DiffEqFlux.ZygoteDiffMode, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqFlux/GYa64/src/train.jl:269 [47] sciml_train at /home/user/.julia/packages/DiffEqFlux/GYa64/src/train.jl:163 [inlined] (repeats 2 times) [48] top-level scope at In[75]:44

@ChrisRackauckas
Copy link
Member

I just tried using @smatrix to speed things up a little, but there appears to a separate issue with regards to that, seemingly in DiffEqBase:

I mentioned earlier that static arrays are not supported in the adjoints, and that's not a high priority because if you are using static arrays then adjoints are not the most optimal method, so it's a weird combination. Use forward sensitivities in that case.

@ChrisRackauckas
Copy link
Member

Looks like your example works just fine if you make p an array of possibly complex numbers as mentioned earlier:

using DiffEqSensitivity, OrdinaryDiffEq, Zygote, LinearAlgebra, FiniteDiff, Test, DiffEqFlux, Optim

const T = 10.0;
const ω = π/T;

function f(u, p, t)
    a = p[1]*sin*t) + p[2]*sin(2*ω*t) + p[3]*sin(3*ω*t) + p[4]*sin(4*ω*t);
    A = [1.0 a; a -1.0];
    return -im*A*u;
end


u0 = [Complex{Float64}(1) 0; 0 1];

tspan = (0.0, T)
p = Complex{Float64}[0.7, 1.0, 3.0, 1.0]

prob_ode = ODEProblem{false}(f, u0, tspan, p);
sol_ode = solve(prob_ode, Tsit5());


utarget = [Complex{Float64}(0) im; im 0];

function predict_adjoint(p)
  return solve(prob_ode, Tsit5(), p=p, abstol=1e-12, reltol=1e-12)
end

function loss_adjoint(p)
    prediction = predict_adjoint(p)
    usol = last(prediction)
    loss = 1.0 - abs(tr(usol*utarget')/2)^2
    return loss
end

grad1 = Zygote.gradient(loss_adjoint,Complex{Float64}[1.5, 1.0, 3.0, 1.0])[1]
grad2 = FiniteDiff.finite_difference_gradient(loss_adjoint,Complex{Float64}[1.5, 1.0, 3.0, 1.0])

@test grad1  grad2 # <- succeeds

res = DiffEqFlux.sciml_train(loss_adjoint, p, BFGS(initial_stepnorm = 0.0001)) # <- fails
res.minimizer # Complex{Float64}[0.3601285857150311 + 0.0im, 0.9525963326731084 + 0.0im, 3.2163299056173216 + 0.0im, 0.9696107069145927 + 0.0im]
loss_adjoint(res.minimizer) # 1.2534417948018017e-12

@ChrisRackauckas
Copy link
Member

Another strange thing I came accross is that the gradient test also fails if the definition of ω is changed as

Both compute zero:

4-element Array{Complex{Float64},1}:
  -1.170854484124002e-27 + 0.0im
  -4.097793673184153e-28 + 0.0im
  1.6174714686732235e-27 + 0.0im
 -2.9688076044084723e-27 + 0.0im

for finite differencing vs

4-element Array{Complex{Float64},1}:
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im

for AD. Finite differencing isn't exact, but it's pretty close here.

@seadra
Copy link
Author

seadra commented Jun 22, 2020

OK, thanks a lot for the replies!

I am not familiar with the internals of how they work, so I'll just take your word for it with regards to the use of StaticArrays.

Looks like your example works just fine if you make p an array of possibly complex numbers as mentioned earlier:

When I do that, it actually fails with the following error:

MethodError: no method matching ini_dec(::Complex{Float64}, ::Int64, ::Array{UInt8,1})
Closest candidates are:
  ini_dec(::Any, ::Any, !Matched::Int64, !Matched::String, !Matched::Int64, !Matched::Int64, !Matched::Char, !Matched::Any) at /build/julia/src/julia-1.4.2/usr/share/julia/stdlib/v1.4/Printf/src/Printf.jl:845
  ini_dec(!Matched::BigInt, ::Int64, ::Any) at /build/julia/src/julia-1.4.2/usr/share/julia/stdlib/v1.4/Printf/src/Printf.jl:1056
  ini_dec(!Matched::Integer, ::Int64, ::Any) at /build/julia/src/julia-1.4.2/usr/share/julia/stdlib/v1.4/Printf/src/Printf.jl:1014
  ...
Stacktrace Stacktrace: [1] ini_dec(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Complex{Float64}, ::Int64, ::String, ::Int64, ::Int64, ::Char, ::Array{UInt8,1}) at /build/julia/src/julia-1.4.2/usr/share/julia/stdlib/v1.4/Printf/src/Printf.jl:845 [2] (::Optim.var"#2#4")(::Complex{Float64}) at /build/julia/src/julia-1.4.2/usr/share/julia/stdlib/v1.4/Printf/src/Printf.jl:0 [3] iterate at ./generator.jl:47 [inlined] [4] collect(::Base.Generator{Base.Iterators.Take{Array{Complex{Float64},1}},Optim.var"#2#4"}) at ./array.jl:665 [5] show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::Optim.MultivariateOptimizationResults{BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat},Float64,Array{Complex{Float64},1},Float64,Float64,Array{OptimizationState{Float64,BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}},1},Bool}) at /home/user/.julia/packages/Optim/L5T76/src/types.jl:242 [6] show at ./multimedia.jl:47 [inlined] [7] limitstringmime(::MIME{Symbol("text/plain")}, ::Optim.MultivariateOptimizationResults{BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat},Float64,Array{Complex{Float64},1},Float64,Float64,Array{OptimizationState{Float64,BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}},1},Bool}) at /home/user/.julia/packages/IJulia/DrVMH/src/inline.jl:43 [8] display_mimestring(::MIME{Symbol("text/plain")}, ::Optim.MultivariateOptimizationResults{BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat},Float64,Array{Complex{Float64},1},Float64,Float64,Array{OptimizationState{Float64,BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}},1},Bool}) at /home/user/.julia/packages/IJulia/DrVMH/src/display.jl:67 [9] display_dict(::Optim.MultivariateOptimizationResults{BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat},Float64,Array{Complex{Float64},1},Float64,Float64,Array{OptimizationState{Float64,BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Float64,Flat}},1},Bool}) at /home/user/.julia/packages/IJulia/DrVMH/src/display.jl:96 [10] #invokelatest#1 at ./essentials.jl:712 [inlined] [11] invokelatest at ./essentials.jl:711 [inlined] [12] execute_request(::ZMQ.Socket, ::IJulia.Msg) at /home/user/.julia/packages/IJulia/DrVMH/src/execute_request.jl:112 [13] #invokelatest#1 at ./essentials.jl:712 [inlined] [14] invokelatest at ./essentials.jl:711 [inlined] [15] eventloop(::ZMQ.Socket) at /home/user/.julia/packages/IJulia/DrVMH/src/eventloop.jl:8 [16] (::IJulia.var"#15#18")() at ./task.jl:358

It works fine, though, when I do the type-cast only when passing p to solve.

@ChrisRackauckas
Copy link
Member

Oh that's different. It's actually working, but it seems like when you try to display the results of the optimization it errors. So the optimization didn't actually error, you can check res.minimizer, it's just that the complex numbers break Optim's display mechanism. It would be good to get an issue on Optim.jl for that.

@seadra
Copy link
Author

seadra commented Jun 22, 2020

Oh I see! Thanks, I'll do that!

I apologize for coming back with further issues, but it appears that using f(du, u, p, t) instead of f(u, p, t) brings back this previous error

using DiffEqSensitivity, OrdinaryDiffEq, Zygote, LinearAlgebra, FiniteDiff, Test, DiffEqFlux, Optim

const T = 10.0;
const ω = π/T;

function f1(du, u, p, t)
    a = p[1]*sin*t) + p[2]*sin(2*ω*t) + p[3]*sin(3*ω*t) + p[4]*sin(4*ω*t);
    A = [1.0 a; a -1.0];
    du .= -im*A*u;
end


u0 = [Complex{Float64}(1) 0; 0 1];

tspan = (0.0, T)
p = [0.7, 1.0, 3.0, 1.0]

prob_ode = ODEProblem(f1, u0, tspan, p);
sol_ode = solve(prob_ode, Tsit5());


utarget = [Complex{Float64}(0) im; im 0];

function predict_adjoint(p)
  return solve(prob_ode, Tsit5(), p=Complex{Float64}.(p), abstol=1e-12, reltol=1e-12)
end

function loss_adjoint(p)
    prediction = predict_adjoint(p)
    usol = last(prediction)
    loss = 1.0 - abs(tr(usol*utarget')/2)^2
    return loss
end

DiffEqFlux.sciml_train(loss_adjoint, p, BFGS(initial_stepnorm = 0.0001))

TypeError: in TrackedReal, in V, expected V<:Real, got Type{Complex{Float64}}

Stacktrace Stacktrace: [1] ReverseDiff.TrackedArray(::Array{Complex{Float64},2}, ::Array{Complex{Float64},2}, ::Array{ReverseDiff.AbstractInstruction,1}) at /home/user/.julia/packages/ReverseDiff/uy0uk/src/tracked.jl:86 [2] track at /home/user/.julia/packages/ReverseDiff/uy0uk/src/tracked.jl:387 [inlined] [3] #543 at /home/user/.julia/packages/ReverseDiff/uy0uk/src/api/Config.jl:46 [inlined] [4] map at ./tuple.jl:159 [inlined] [5] ReverseDiff.GradientConfig(::Tuple{Array{Complex{Float64},2},Array{Complex{Float64},1},Array{Float64,1}}, ::Type{Complex{Float64}}, ::Array{ReverseDiff.AbstractInstruction,1}) at /home/user/.julia/packages/ReverseDiff/uy0uk/src/api/Config.jl:46 [6] GradientConfig at /home/user/.julia/packages/ReverseDiff/uy0uk/src/api/Config.jl:37 [inlined] (repeats 2 times) [7] ReverseDiff.GradientTape(::Function, ::Tuple{Array{Complex{Float64},2},Array{Complex{Float64},1},Array{Float64,1}}) at /home/user/.julia/packages/ReverseDiff/uy0uk/src/api/tape.jl:204 [8] adjointdiffcache(::Function, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::Bool, ::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,typeof(f1),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{true,typeof(f1),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::Nothing, ::ODEFunction{true,typeof(f1),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}; quad::Bool, noiseterm::Bool) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/adjoint_common.jl:114 [9] adjointdiffcache at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/adjoint_common.jl:27 [inlined] [10] DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction(::Function, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::Bool, ::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,typeof(f1),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{true,typeof(f1),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::Nothing, ::Array{Float64,1}, ::NamedTuple{(:reltol, :abstol),Tuple{Float64,Float64}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/interpolating_adjoint.jl:36 [11] ODEAdjointProblem(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,typeof(f1),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{true,typeof(f1),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon}, ::Array{Float64,1}, ::Nothing; checkpoints::Array{Float64,1}, callback::CallbackSet{Tuple{},Tuple{}}, reltol::Float64, abstol::Float64, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/interpolating_adjoint.jl:114 [12] _adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,typeof(f1),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{true,typeof(f1),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::Tsit5, ::DiffEqSensitivity.var"#df#126"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon}, ::Array{Float64,1}, ::Nothing; abstol::Float64, reltol::Float64, checkpoints::Array{Float64,1}, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/sensitivity_interface.jl:17 [13] adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,typeof(f1),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{true,typeof(f1),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.Tsit5Cache{Array{Complex{Float64},2},Array{Complex{Float64},2},Array{Complex{Float64},2},OrdinaryDiffEq.Tsit5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats}, ::Tsit5, ::Vararg{Any,N} where N; sensealg::InterpolatingAdjoint{0,true,Val{:central},Bool}, kwargs::Base.Iterators.Pairs{Symbol,Float64,Tuple{Symbol,Symbol},NamedTuple{(:abstol, :reltol),Tuple{Float64,Float64}}}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/sensitivity_interface.jl:6 [14] (::DiffEqSensitivity.var"#adjoint_sensitivity_backpass#125"{Tsit5,InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},Array{Complex{Float64},1},Tuple{},Colon})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/DiffEqSensitivity/XiKOH/src/local_sensitivity/concrete_solve.jl:113 [15] #526#back at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:55 [inlined] [16] #175 at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [inlined] [17] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{DiffEqBase.var"#526#back#467"{DiffEqSensitivity.var"#adjoint_sensitivity_backpass#125"{Tsit5,InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},Array{Complex{Float64},1},Tuple{},Colon}},Tuple{NTuple{6,Nothing},Tuple{Nothing}}}})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [18] #solve#453 at /home/user/.julia/packages/DiffEqBase/LGnTa/src/solve.jl:106 [inlined] [19] (::typeof(∂(#solve#453)))(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [20] (::Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/lib/lib.jl:182 [21] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}}})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [22] (::typeof(∂(solve##kw)))(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [23] predict_adjoint at ./In[135]:25 [inlined] [24] (::typeof(∂(predict_adjoint)))(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface2.jl:0 [25] loss_adjoint at ./In[135]:29 [inlined] [26] (::Zygote.var"#37#38"{typeof(∂(loss_adjoint))})(::Float64) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface.jl:45 [27] gradient(::Function, ::Array{Complex{Float64},1}) at /home/user/.julia/packages/Zygote/z3bQd/src/compiler/interface.jl:54 [28] top-level scope at In[135]:34

@seadra
Copy link
Author

seadra commented Jun 22, 2020

With regards to StaticArrays, actually, it could be significant for performance nonetheless (at least it is, in my case): in the callback function f(u, p ,t), there can be a lot of matrix operations, and using @SMatrix for the intermediate calculations (even if not for the input u and final return value du of f) leads to very significant speed ups in those cases.

Is it OK if I opened a separate issue for that, or do you prefer not to add support for StaticArrays?

@ChrisRackauckas
Copy link
Member

With regards to StaticArrays, actually, it could be significant for performance nonetheless (at least it is, in my case): in the callback function f(u, p ,t), there can be a lot of matrix operations, and using @smatrix for the intermediate calculations (even if not for the input u and final return value du of f) leads to very significant speed ups in those cases.

For intermediate calculations, that's probably a Zygote issue.

Is it OK if I opened a separate issue for that, or do you prefer not to add support for StaticArrays?

The issue is SciML/SciMLSensitivity.jl#113 . There was a partial PR that was never finished: SciML/SciMLSensitivity.jl#61 . There are some advantages that you'd get, but not really too many...

With regards to StaticArrays, actually, it could be significant for performance nonetheless (at least it is, in my case): in the callback function f(u, p ,t), there can be a lot of matrix operations, and using @smatrix for the intermediate calculations (even if not for the input u and final return value du of f) leads to very significant speed ups in those cases.

This is a Zygote issue. Zygote can only handle f(u,p,t), but it's also the only AD that's compatible with complex numbers. So I wouldn't expect this to have a nice fix for now since it needs upstream AD fixes

@seadra
Copy link
Author

seadra commented Jun 22, 2020

Ah, I see. Thanks a lot for the responses & the fixes!

@seadra
Copy link
Author

seadra commented Jun 23, 2020

Hi again,

I'm now trying to add a FastChain to my code (following this example).

using DiffEqSensitivity, OrdinaryDiffEq, Zygote, LinearAlgebra, FiniteDiff, Test, DiffEqFlux, Optim

const T = 10.0;
const ω = π/T;

ann = FastChain(FastDense(1,32,tanh), FastDense(32,32,tanh), FastDense(32,1))
p = initial_params(ann);

function f_nn(u, p, t)
    a = ann([t],p)[1];
    A = [1.0 a; a -1.0];
    return -im*A*u;
end


u0 = [Complex{Float64}(1) 0; 0 1];

tspan = (0.0, T)


prob_ode = ODEProblem(f_nn, u0, tspan, p);
sol_ode = solve(prob_ode, Tsit5());


utarget = [Complex{Float64}(0) im; im 0];

function predict_adjoint(p)
  return solve(prob_ode, Tsit5(), p=Complex{Float64}.(p), abstol=1e-12, reltol=1e-12)
end

function loss_adjoint(p)
    prediction = predict_adjoint(p)
    usol = last(prediction)
    loss = 1.0 - abs(tr(usol*utarget')/2)^2
    return loss
end

DiffEqFlux.sciml_train(loss_adjoint, p, ADAM(0.1), maxiters = 100)

It runs when using tanh as the activation function, but when using anything else (ex: relu or activation(x) = relu(real(x))), it errors with the following message:

MethodError: no method matching derivative(::typeof(activation), ::Complex{Float64})
Closest candidates are:
  derivative(::F, !Matched::R) where {F, R<:Real} at /home/user/.julia/packages/ForwardDiff/cXTw0/src/derivative.jl:13
  derivative(::Any, !Matched::AbstractArray, !Matched::Real) at /home/user/.julia/packages/ForwardDiff/cXTw0/src/derivative.jl:27
  derivative(::Any, !Matched::AbstractArray, !Matched::Real, !Matched::ForwardDiff.DerivativeConfig{T,D} where D) where T at /home/user/.julia/packages/ForwardDiff/cXTw0/src/derivative.jl:27
  ...
Stacktrace MethodError: no method matching derivative(::typeof(activation), ::Complex{Float64}) Closest candidates are: derivative(::F, !Matched::R) where {F, R<:Real} at /home/user/.julia/packages/ForwardDiff/cXTw0/src/derivative.jl:13 derivative(::Any, !Matched::AbstractArray, !Matched::Real) at /home/user/.julia/packages/ForwardDiff/cXTw0/src/derivative.jl:27 derivative(::Any, !Matched::AbstractArray, !Matched::Real, !Matched::ForwardDiff.DerivativeConfig{T,D} where D) where T at /home/user/.julia/packages/ForwardDiff/cXTw0/src/derivative.jl:27 ...

Stacktrace:
[1] _broadcast_getindex_evalf at ./broadcast.jl:631 [inlined]
[2] _broadcast_getindex at ./broadcast.jl:604 [inlined]
[3] _getindex at ./broadcast.jl:628 [inlined]
[4] _getindex at ./broadcast.jl:627 [inlined]
[5] _broadcast_getindex at ./broadcast.jl:603 [inlined]
[6] getindex at ./broadcast.jl:564 [inlined]
[7] copy at ./broadcast.jl:854 [inlined]
[8] materialize at ./broadcast.jl:820 [inlined]
[9] (::DiffEqFlux.var"#FastDense_adjoint#86"{FastDense{typeof(activation),DiffEqFlux.var"#initial_params#85"{typeof(Flux.glorot_uniform),typeof(Flux.zeros),Int64,Int64}},Array{Float64,1},Array{Complex{Float64},2},Array{Complex{Float64},1},Array{Float64,1}})(::Array{Complex{Float64},1}) at /home/user/.julia/packages/DiffEqFlux/h4lHT/src/fast_layers.jl:84
[10] #274#back at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [inlined]
[11] applychain at /home/user/.julia/packages/DiffEqFlux/h4lHT/src/fast_layers.jl:20 [inlined]
[12] (::typeof(∂(applychain)))(::Array{Complex{Float64},1}) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
... (the last 2 lines are repeated 1 more time)
[15] FastChain at /home/user/.julia/packages/DiffEqFlux/h4lHT/src/fast_layers.jl:21 [inlined]
[16] (::typeof(∂(λ)))(::Array{Complex{Float64},1}) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[17] f_nn at ./In[106]:3 [inlined]
[18] (::typeof(∂(f_nn)))(::Base.ReshapedArray{Complex{Float64},2,SubArray{Complex{Float64},1,Array{Complex{Float64},1},Tuple{UnitRange{Int64}},true},Tuple{}}) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[19] #549#back at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49 [inlined]
[20] #30 at /home/user/.julia/packages/DiffEqSensitivity/LhQWH/src/local_sensitivity/derivative_wrappers.jl:281 [inlined]
[21] (::typeof(∂(λ)))(::SubArray{Complex{Float64},1,Array{Complex{Float64},1},Tuple{UnitRange{Int64}},true}) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[22] (::Zygote.var"#37#38"{typeof(∂(λ))})(::SubArray{Complex{Float64},1,Array{Complex{Float64},1},Tuple{UnitRange{Int64}},true}) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface.jl:45
[23] _vecjacobian!(::SubArray{Complex{Float64},1,Array{Complex{Float64},1},Tuple{UnitRange{Int64}},true}, ::Array{Complex{Float64},2}, ::SubArray{Complex{Float64},1,Array{Complex{Float64},1},Tuple{UnitRange{Int64}},true}, ::Array{Complex{Float64},1}, ::Float64, ::DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}}, ::ZygoteVJP, ::SubArray{Complex{Float64},1,Array{Complex{Float64},1},Tuple{UnitRange{Int64}},true}, ::Nothing) at /home/user/.julia/packages/DiffEqSensitivity/LhQWH/src/local_sensitivity/derivative_wrappers.jl:283
[24] _vecjacobian! at /home/user/.julia/packages/DiffEqSensitivity/LhQWH/src/local_sensitivity/derivative_wrappers.jl:187 [inlined]
[25] #vecjacobian!#20 at /home/user/.julia/packages/DiffEqSensitivity/LhQWH/src/local_sensitivity/derivative_wrappers.jl:147 [inlined]
[26] (::DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}})(::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}, ::Array{Complex{Float64},1}, ::Float64) at /home/user/.julia/packages/DiffEqSensitivity/LhQWH/src/local_sensitivity/interpolating_adjoint.jl:87
[27] ODEFunction at /home/user/.julia/packages/DiffEqBase/Xoaan/src/diffeqfunction.jl:248 [inlined]
[28] initialize!(::OrdinaryDiffEq.ODEIntegrator{BS5,true,Array{Complex{Float64},1},Nothing,Float64,Array{Complex{Float64},1},Float64,Float64,Float64,Array{Array{Complex{Float64},1},1},ODESolution{Complex{Float64},2,Array{Array{Complex{Float64},1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},1},1},1},ODEProblem{Array{Complex{Float64},1},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},1},1},Array{Float64,1},Array{Array{Array{Complex{Float64},1},1},1},OrdinaryDiffEq.BS5Cache{Array{Complex{Float64},1},Array{Complex{Float64},1},Array{Complex{Float64},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}}},DiffEqBase.DEStats},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.BS5Cache{Array{Complex{Float64},1},Array{Complex{Float64},1},Array{Complex{Float64},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},OrdinaryDiffEq.DEOptions{Float64,Float64,Float64,Float64,typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(opnorm),CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Nothing,Nothing,Int64,Array{Float64,1},Array{Complex{Float64},1},Tuple{}},Array{Complex{Float64},1},Complex{Float64},Nothing,OrdinaryDiffEq.DefaultInit}, ::OrdinaryDiffEq.BS5Cache{Array{Complex{Float64},1},Array{Complex{Float64},1},Array{Complex{Float64},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/perform_step/low_order_rk_perform_step.jl:443
[29] __init(::ODEProblem{Array{Complex{Float64},1},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem}, ::BS5, ::Tuple{}, ::Tuple{}, ::Tuple{}, ::Type{Val{true}}; saveat::Array{Complex{Float64},1}, tstops::Array{Float64,1}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Bool, callback::CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Float64, reltol::Float64, qmin::Rational{Int64}, qmax::Int64, qsteady_min::Int64, qsteady_max::Int64, qoldinit::Rational{Int64}, fullnormalize::Bool, failfactor::Int64, beta1::Nothing, beta2::Nothing, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias_u0::Bool, alias_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/solve.jl:403
[30] #__solve#360 at /home/user/.julia/packages/OrdinaryDiffEq/NsugH/src/solve.jl:4 [inlined]
[31] solve_call(::ODEProblem{Array{Complex{Float64},1},Tuple{Float64,Float64},true,Array{Complex{Float64},1},ODEFunction{true,DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction{DiffEqSensitivity.AdjointDiffCache{Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool}},InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats},Nothing,ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Symbol,CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}},Tuple{Symbol},NamedTuple{(:callback,),Tuple{CallbackSet{Tuple{},Tuple{DiscreteCallback{DiffEqCallbacks.var"#33#36"{Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}},DiffEqCallbacks.var"#35#38"{typeof(DiffEqBase.INITIALIZE_DEFAULT),Bool,DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},Base.RefValue{Union{Nothing, Float64}},DiffEqCallbacks.var"#34#37"{DiffEqSensitivity.var"#94#96"{Base.RefValue{Int64},Array{Float64,1}},DiffEqSensitivity.var"#95#97"{DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon},InterpolatingAdjoint{0,true,Val{:central},Bool},Base.OneTo{Int64},UnitRange{Int64},UniformScaling{Bool},Bool,Nothing,Nothing,Nothing,Nothing,Bool,Array{Complex{Float64},1},Array{Float64,1},Array{Complex{Float64},2},Base.RefValue{Int64},Int64,UniformScaling{Bool}},Base.RefValue{Union{Nothing, Float64}}}}}}}}}},DiffEqBase.StandardODEProblem}, ::BS5; merge_callbacks::Bool, kwargs::Base.Iterators.Pairs{Symbol,Any,NTuple{6,Symbol},NamedTuple{(:save_everystep, :save_start, :saveat, :tstops, :abstol, :reltol),Tuple{Bool,Bool,Array{Complex{Float64},1},Array{Float64,1},Float64,Float64}}}) at /home/user/.julia/packages/DiffEqBase/Xoaan/src/solve.jl:96
[32] #solve_up#454 at /home/user/.julia/packages/DiffEqBase/Xoaan/src/solve.jl:122 [inlined]
[33] #solve#453 at /home/user/.julia/packages/DiffEqBase/Xoaan/src/solve.jl:106 [inlined]
[34] _adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats}, ::InterpolatingAdjoint{0,true,Val{:central},Bool}, ::BS5, ::DiffEqSensitivity.var"#df#132"{Array{Array{Complex{Float64},2},1},Array{Complex{Float64},2},Colon}, ::Array{Float64,1}, ::Nothing; abstol::Float64, reltol::Float64, checkpoints::Array{Float64,1}, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/DiffEqSensitivity/LhQWH/src/local_sensitivity/sensitivity_interface.jl:21
[35] adjoint_sensitivities(::ODESolution{Complex{Float64},3,Array{Array{Complex{Float64},2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},ODEProblem{Array{Complex{Float64},2},Tuple{Float64,Float64},false,Array{Complex{Float64},1},ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem},BS5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,typeof(f_nn),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Complex{Float64},2},1},Array{Float64,1},Array{Array{Array{Complex{Float64},2},1},1},OrdinaryDiffEq.BS5ConstantCache{Complex{Float64},Float64}},DiffEqBase.DEStats}, ::BS5, ::Vararg{Any,N} where N; sensealg::InterpolatingAdjoint{0,true,Val{:central},Bool}, kwargs::Base.Iterators.Pairs{Symbol,Float64,Tuple{Symbol,Symbol},NamedTuple{(:abstol, :reltol),Tuple{Float64,Float64}}}) at /home/user/.julia/packages/DiffEqSensitivity/LhQWH/src/local_sensitivity/sensitivity_interface.jl:6
[36] (::DiffEqSensitivity.var"#adjoint_sensitivity_backpass#131"{BS5,InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},Array{Complex{Float64},1},Tuple{},Colon})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/DiffEqSensitivity/LhQWH/src/local_sensitivity/concrete_solve.jl:113
[37] #526#back at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:55 [inlined]
[38] #175 at /home/user/.julia/packages/Zygote/1GXzF/src/lib/lib.jl:182 [inlined]
[39] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{DiffEqBase.var"#526#back#467"{DiffEqSensitivity.var"#adjoint_sensitivity_backpass#131"{BS5,InterpolatingAdjoint{0,true,Val{:central},Bool},Array{Complex{Float64},2},Array{Complex{Float64},1},Tuple{},Colon}},Tuple{NTuple{6,Nothing},Tuple{Nothing}}}})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49
[40] #solve#453 at /home/user/.julia/packages/DiffEqBase/Xoaan/src/solve.jl:106 [inlined]
[41] (::typeof(∂(#solve#453)))(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[42] (::Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/1GXzF/src/lib/lib.jl:182
[43] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{typeof(∂(#solve#453)),Tuple{NTuple{6,Nothing},Tuple{Nothing}}}})(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49
[44] (::typeof(∂(solve##kw)))(::Array{Array{Complex{Float64},2},1}) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[45] loss_adjoint at ./In[106]:14 [inlined]
[46] (::typeof(∂(loss_adjoint)))(::Float64) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[47] #175 at /home/user/.julia/packages/Zygote/1GXzF/src/lib/lib.jl:182 [inlined]
[48] (::Zygote.var"#347#back#177"{Zygote.var"#175#176"{typeof(∂(loss_adjoint)),Tuple{Tuple{Nothing},Tuple{}}}})(::Float64) at /home/user/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:49
[49] #33 at /home/user/.julia/packages/DiffEqFlux/h4lHT/src/train.jl:99 [inlined]
[50] (::typeof(∂(λ)))(::Float64) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0
[51] (::Zygote.var"#50#51"{Params,Zygote.Context,typeof(∂(λ))})(::Float64) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface.jl:177
[52] gradient(::Function, ::Params) at /home/user/.julia/packages/Zygote/1GXzF/src/compiler/interface.jl:54
[53] macro expansion at /home/user/.julia/packages/DiffEqFlux/h4lHT/src/train.jl:98 [inlined]
[54] macro expansion at /home/user/.julia/packages/ProgressLogging/BBN0b/src/ProgressLogging.jl:328 [inlined]
[55] (::DiffEqFlux.var"#32#37"{DiffEqFlux.var"#36#41",Int64,Bool,Bool,typeof(loss_adjoint),Array{Float32,1},Params})() at /home/user/.julia/packages/DiffEqFlux/h4lHT/src/train.jl:43
[56] with_logstate(::DiffEqFlux.var"#32#37"{DiffEqFlux.var"#36#41",Int64,Bool,Bool,typeof(loss_adjoint),Array{Float32,1},Params}, ::Base.CoreLogging.LogState) at ./logging.jl:398
[57] with_logger at ./logging.jl:505 [inlined]
[58] maybe_with_logger(::DiffEqFlux.var"#32#37"{DiffEqFlux.var"#36#41",Int64,Bool,Bool,typeof(loss_adjoint),Array{Float32,1},Params}, ::LoggingExtras.TeeLogger{Tuple{LoggingExtras.EarlyFilteredLogger{ConsoleProgressMonitor.ProgressLogger,DiffEqBase.var"#10#12"},LoggingExtras.EarlyFilteredLogger{Base.CoreLogging.SimpleLogger,DiffEqBase.var"#11#13"}}}) at /home/user/.julia/packages/DiffEqBase/Xoaan/src/utils.jl:259
[59] sciml_train(::Function, ::Array{Float32,1}, ::ADAM, ::Base.Iterators.Cycle{Tuple{DiffEqFlux.NullData}}; cb::Function, maxiters::Int64, progress::Bool, save_best::Bool) at /home/user/.julia/packages/DiffEqFlux/h4lHT/src/train.jl:42

I couldn't be sure if this something that I should be reporting to ForwardDiff or Zygote instead or not.

@ChrisRackauckas
Copy link
Member

it's JuliaDiff/ForwardDiff.jl#455 . We can hardcode more analytical solutions if it helps. These are hardcoded for extra speed: https://github.com/SciML/DiffEqFlux.jl/blob/master/src/fast_layers.jl#L78-L82

@seadra
Copy link
Author

seadra commented Jun 23, 2020

Oh, great, so once JuliaDiff/ForwardDiff.jl#455 gets merged, I believe we can use an arbitrary activation function!

I think it would be nice to have optimized versions for common activation functions, since they can have a strong impact on convergence.

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

No branches or pull requests

2 participants