SciML / SciMLSensitivity.jl

A component of the DiffEq ecosystem for enabling sensitivity analysis for scientific machine learning (SciML). Optimize-then-discretize, discretize-then-optimize, adjoint methods, and more for ODEs, SDEs, DDEs, DAEs, etc.
https://docs.sciml.ai/SciMLSensitivity/stable/
Other
333 stars 71 forks source link

Error on differentiation with a terminate! callback #720

Open axsk opened 2 years ago

axsk commented 2 years ago

Trying to autodiff (Zygote.jl) through a neural SDE (StochasticDiffEq.jl, Lux.jl) with a ContinuousCallback triggering a terminate! leads to the following error

julia> test()
ERROR: Event was triggered but no corresponding event in ContinuousCallback was found. Please report this error.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] get_indx(cb::ContinuousCallback{var"#9#10"{Int64, Int64}, SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#9#10"{Int64, Int64}, Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#9#10"{Int64, Int64}, Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#9#10"{Int64, Int64}, Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#9#10"{Int64, Int64}, Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#9#10"{Int64, Int64}, Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, Float64}, Float64, 2, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#9#10"{Int64, Int64}, Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, Float64}, Float64, 2}}}, var"#9#10"{Int64, Int64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#9#10"{Int64, Int64}, Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#9#10"{Int64, Int64}, Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#9#10"{Int64, Int64}, Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#9#10"{Int64, Int64}, Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#9#10"{Int64, Int64}, Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, Float64}, Float64, 2, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#9#10"{Int64, Int64}, Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(layer_1 = ViewAxis(1:20, Axis(weight = ViewAxis(1:10, ShapedAxis((10, 1), NamedTuple())), bias = ViewAxis(11:20, ShapedAxis((10, 1), NamedTuple())))), layer_2 = ViewAxis(21:31, Axis(weight = ViewAxis(1:10, ShapedAxis((1, 10), NamedTuple())), bias = ViewAxis(11:11, ShapedAxis((1, 1), NamedTuple())))))}}}, Float64, Float64}}, Float64}, Float64, 2}}}, var"#9#10"{Int64, Int64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}, t::Float64)
    @ SciMLSensitivity ~/.julia/packages/SciMLSensitivity/0ZY5u/src/callback_tracking.jl:365

The full stacktrace is here. The full code is here (call test())

The callback is

termination(ub, lb) = ContinuousCallback((u,t,int)->(u[1]-lb) * (ub-u[1]), terminate!)
prob = SDEProblem(_drift, _noise, xy0, T, p, noise_rate_prototype = n0, callback=termination(1,-1))

and I solve with

function msolve(prob; ps=prob.p, dt=0.01, salg=InterpolatingAdjoint(autojacvec=ReverseDiffVJP(), noisemixing=true))
    s = solve(prob, EM(), sensealg=salg, dt=dt, p=ps)
end
axsk commented 2 years ago

Trying to build an MWE I got another error.

using Zygote
using StochasticDiffEq, SciMLSensitivity

function mwe()
    x0 = [0.]
    drift(dx, x, p, t) = (dx .= p)
    noise(dx, x, p, t) = (dx .= 0.)
    n0 = zeros(1,1)
    T = 100.
    p0 = [1.]
    cb = ContinuousCallback((u,t,int)->(u[1]-1), terminate!, nothing)
    prob = SDEProblem(drift, noise, x0, T, p0, noise_rate_prototype = n0, callback=cb)

    sensealg = InterpolatingAdjoint(autojacvec=ReverseDiffVJP(), noisemixing=true)
    Zygote.gradient(p0) do ps
        solve(prob, EM(), dt=0.1, p=ps, sensealg=sensealg)[end][1]
    end
end

produces

ERROR: More than two occurances of the same time point. Please report this.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] separate_nonunique(t::Vector{Float64})
    @ SciMLSensitivity ~/.julia/packages/SciMLSensitivity/tO61G/src/adjoint_common.jl:554
  [3] SDEAdjointProblem(sol::RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, DiffEqNoiseProcess.NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, DiffEqNoiseProcess.RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, Nothing, SDEFunction{true, var"#drift#96", var"#noise#97", UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#noise#97", Base.Pairs{Symbol, CallbackSet{Tuple{ContinuousCallback{var"#93#98", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#93#98", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}, Tuple{Symbol}, NamedTuple{(:callback,), Tuple{CallbackSet{Tuple{ContinuousCallback{var"#93#98", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#93#98", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}}}}, Matrix{Float64}}, EM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}}, alg::EM{true}, t::Vector{Float64}, dgdu_discrete::SciMLSensitivity.var"#df_iip#268"{RecursiveArrayTools.VectorOfArray{Float64, 2, Vector{AbstractVector{Float64}}}, Colon}, dgdp_discrete::Nothing, dgdu_continuous::Nothing, dgdp_continuous::Nothing, g::Nothing; checkpoints::Vector{Float64}, callback::CallbackSet{Tuple{ContinuousCallback{var"#93#98", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#93#98", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}, reltol::Float64, abstol::Float64, diffusion_jac::Nothing, diffusion_paramjac::Nothing, kwargs::Base.Pairs{Symbol, Nothing, Tuple{Symbol}, NamedTuple{(:corfunc_analytical,), Tuple{Nothing}}})
    @ SciMLSensitivity ~/.julia/packages/SciMLSensitivity/tO61G/src/interpolating_adjoint.jl:407
  [4] _adjoint_sensitivities(sol::RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, DiffEqNoiseProcess.NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, DiffEqNoiseProcess.RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, Nothing, SDEFunction{true, var"#drift#96", var"#noise#97", UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#noise#97", Base.Pairs{Symbol, CallbackSet{Tuple{ContinuousCallback{var"#93#98", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#93#98", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}, Tuple{Symbol}, NamedTuple{(:callback,), Tuple{CallbackSet{Tuple{ContinuousCallback{var"#93#98", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#93#98", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}}}}, Matrix{Float64}}, EM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}}, alg::EM{true}; t::Vector{Float64}, dgdu_discrete::Function, dgdp_discrete::Nothing, dgdu_continuous::Nothing, dgdp_continuous::Nothing, g::Nothing, abstol::Float64, reltol::Float64, checkpoints::Vector{Float64}, corfunc_analytical::Nothing, callback::CallbackSet{Tuple{ContinuousCallback{var"#93#98", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#93#98", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}, kwargs::Base.Pairs{Symbol, Real, Tuple{Symbol, Symbol}, NamedTuple{(:verbose, :dt), Tuple{Bool, Float64}}})
    @ SciMLSensitivity ~/.julia/packages/SciMLSensitivity/tO61G/src/sensitivity_interface.jl:413
  [5] adjoint_sensitivities(sol::RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, DiffEqNoiseProcess.NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, DiffEqNoiseProcess.RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, Nothing, SDEFunction{true, var"#drift#96", var"#noise#97", UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#noise#97", Base.Pairs{Symbol, CallbackSet{Tuple{ContinuousCallback{var"#93#98", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#93#98", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}, Tuple{Symbol}, NamedTuple{(:callback,), Tuple{CallbackSet{Tuple{ContinuousCallback{var"#93#98", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#93#98", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}}}}, Matrix{Float64}}, EM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, args::EM{true}; sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}}, verbose::Bool, kwargs::Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:t, :dgdu_discrete, :callback, :dt), Tuple{Vector{Float64}, SciMLSensitivity.var"#df_iip#268"{RecursiveArrayTools.VectorOfArray{Float64, 2, Vector{AbstractVector{Float64}}}, Colon}, CallbackSet{Tuple{ContinuousCallback{var"#93#98", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#93#98", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#93#98", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#93#98", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}, Float64}}})
    @ SciMLSensitivity ~/.julia/packages/SciMLSensitivity/tO61G/src/sensitivity_interface.jl:386
axsk commented 2 years ago

Replacing 0. by .1 in the noise term leads to an

julia> mwe()
ERROR: type Nothing has no field event_times
Stacktrace:
  [1] getproperty(x::Nothing, f::Symbol)
    @ Base ./Base.jl:38
  [2] _setup_reverse_callbacks(cb::ContinuousCallback{var"#342#346", SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#342#346", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#342#346", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#342#346", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#342#346", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#342#346", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#342#346", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#342#346", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, Nothing, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}, affect::SciMLSensitivity.TrackedAffect{Float64, Vector{Float64}, Vector{Float64}, typeof(terminate!), SciMLSensitivity.ImplicitCorrection{Vector{Float64}, Vector{Float64}, SciMLSensitivity.ConditionTimeWrapper{var"#342#346", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, SciMLSensitivity.ConditionUWrapper{var"#342#346", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, ForwardDiff.DerivativeConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#342#346", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionTimeWrapper{var"#342#346", Vector{Float64}, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#342#346", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1, Vector{ForwardDiff.Dual{ForwardDiff.Tag{SciMLSensitivity.ConditionUWrapper{var"#342#346", Float64, SciMLSensitivity.FakeIntegrator{Vector{Float64}, Vector{Float64}, Float64, Float64}}, Float64}, Float64, 1}}}, var"#342#346", Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Base.RefValue{Int64}}, Int64}, sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}}, dgdu::Function, dgdp::Nothing, loss_ref::Base.RefValue{Int64}, terminated::Bool)
    @ SciMLSensitivity ~/.julia/packages/SciMLSensitivity/tO61G/src/callback_tracking.jl:335

Removing the nothing from the callback constructor then (sometimes) leads to the original error

ERROR: Event was triggered but no corresponding event in ContinuousCallback was found. Please report this error.

Both MWEs can be found in this gist Am I doing something wrong with the Callback construction? Any ideas on how to fix this?

frankschae commented 2 years ago

The condition should be of the form:

condition(u,t,integrator) = ...

(but since you only use the first argument that should not be the origin of the error..). I'll probably have some time towards the end of the week to look deeper into it.