SciML / StochasticDiffEq.jl

Solvers for stochastic differential equations which connect with the scientific machine learning (SciML) ecosystem
Other
245 stars 66 forks source link

UndefVarError: J not defined from line 60 of implicit_split_step.jl #481

Closed evolbio closed 2 years ago

evolbio commented 2 years ago

From solve (prob, S.solver, u0=u_init, p=p[S.ddim+1:end]) for prob as SDEProblem with no special args, and solver as ISSEM().

ERROR: UndefVarError: J not defined
Stacktrace:
  [1] perform_step!(integrator::StochasticDiffEq.SDEIntegrator{StochasticDiffEq.ISSEM{0, true, Nothing, typeof(OrdinaryDiffEq.DEFAULT_PRECS), Val{:central}, true, nothing, DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, Float64, :Predictive}, false, Vector{Float64}, Float64, Float64, Float64, Vector{Float64}, Float64, Float64, Float64, DiffEqNoiseProcess.NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.WHITE_NOISE_BRIDGE), false, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, false}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, false}, DiffEqNoiseProcess.RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, Nothing, Vector{Float64}, SciMLBase.RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, DiffEqNoiseProcess.NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.WHITE_NOISE_BRIDGE), false, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, false}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, false}, DiffEqNoiseProcess.RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SciMLBase.SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, false, Vector{Float64}, Nothing, SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(OptTF.ode_noise), Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:maxiters, :reltol, :abstol, :callback), Tuple{Float64, Float64, Float64, SciMLBase.CallbackSet{Tuple{}, Tuple{}}}}}, Nothing}, StochasticDiffEq.ISSEM{0, true, Nothing, typeof(OrdinaryDiffEq.DEFAULT_PRECS), Val{:central}, true, nothing, DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, Float64, :Predictive}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.ISSEMConstantCache{OrdinaryDiffEq.NLSolver{DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, false, Vector{Float64}, Float64, Nothing, Float64, OrdinaryDiffEq.NLNewtonConstantCache{Float64, Float64, Matrix{Float64}, LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, SciMLBase.UDerivativeWrapper{SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Float64, Vector{Float64}}}}}, SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(OptTF.ode_noise), Nothing, StochasticDiffEq.SDEOptions{Float64, Float64, OrdinaryDiffEq.PIController{Float64}, typeof(DiffEqBase.ODE_DEFAULT_NORM), Bool, SciMLBase.CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, Nothing, Nothing, Float64, Float64, Float64, Float64, Tuple{}, Tuple{}, Tuple{}}, Nothing, Float64, Nothing, Nothing}, cache::StochasticDiffEq.ISSEMConstantCache{OrdinaryDiffEq.NLSolver{DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, false, Vector{Float64}, Float64, Nothing, Float64, OrdinaryDiffEq.NLNewtonConstantCache{Float64, Float64, Matrix{Float64}, LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, SciMLBase.UDerivativeWrapper{SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Float64, Vector{Float64}}}}})
    @ StochasticDiffEq /opt/julia/packages/StochasticDiffEq/Qloc0/src/perform_step/implicit_split_step.jl:60
  [2] solve!(integrator::StochasticDiffEq.SDEIntegrator{StochasticDiffEq.ISSEM{0, true, Nothing, typeof(OrdinaryDiffEq.DEFAULT_PRECS), Val{:central}, true, nothing, DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, Float64, :Predictive}, false, Vector{Float64}, Float64, Float64, Float64, Vector{Float64}, Float64, Float64, Float64, DiffEqNoiseProcess.NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.WHITE_NOISE_BRIDGE), false, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, false}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, false}, DiffEqNoiseProcess.RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, Nothing, Vector{Float64}, SciMLBase.RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, DiffEqNoiseProcess.NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.WHITE_NOISE_BRIDGE), false, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, false}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, false}, DiffEqNoiseProcess.RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SciMLBase.SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, false, Vector{Float64}, Nothing, SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(OptTF.ode_noise), Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:maxiters, :reltol, :abstol, :callback), Tuple{Float64, Float64, Float64, SciMLBase.CallbackSet{Tuple{}, Tuple{}}}}}, Nothing}, StochasticDiffEq.ISSEM{0, true, Nothing, typeof(OrdinaryDiffEq.DEFAULT_PRECS), Val{:central}, true, nothing, DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, Float64, :Predictive}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.ISSEMConstantCache{OrdinaryDiffEq.NLSolver{DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, false, Vector{Float64}, Float64, Nothing, Float64, OrdinaryDiffEq.NLNewtonConstantCache{Float64, Float64, Matrix{Float64}, LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, SciMLBase.UDerivativeWrapper{SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Float64, Vector{Float64}}}}}, SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(OptTF.ode_noise), Nothing, StochasticDiffEq.SDEOptions{Float64, Float64, OrdinaryDiffEq.PIController{Float64}, typeof(DiffEqBase.ODE_DEFAULT_NORM), Bool, SciMLBase.CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, Nothing, Nothing, Float64, Float64, Float64, Float64, Tuple{}, Tuple{}, Tuple{}}, Nothing, Float64, Nothing, Nothing})
    @ StochasticDiffEq /opt/julia/packages/StochasticDiffEq/Qloc0/src/solve.jl:611
  [3] #__solve#110
    @ /opt/julia/packages/StochasticDiffEq/Qloc0/src/solve.jl:7 [inlined]
  [4] solve_call(_prob::SciMLBase.SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, false, Vector{Float64}, Nothing, SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(OptTF.ode_noise), Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:maxiters, :reltol, :abstol, :callback), Tuple{Float64, Float64, Float64, SciMLBase.CallbackSet{Tuple{}, Tuple{}}}}}, Nothing}, args::StochasticDiffEq.ISSEM{0, true, Nothing, typeof(OrdinaryDiffEq.DEFAULT_PRECS), Val{:central}, true, nothing, DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, Float64, :Predictive}; merge_callbacks::Bool, kwargshandle::DiffEqBase.KeywordArgError, kwargs::Base.Pairs{Symbol, Real, NTuple{7, Symbol}, NamedTuple{(:save_noise, :save_start, :save_end, :verbose, :reltol, :abstol, :maxiters), Tuple{Bool, Bool, Bool, Bool, Float64, Float64, Float64}}})
    @ DiffEqBase /opt/julia/packages/DiffEqBase/aAyno/src/solve.jl:433
  [5] #solve_up#34
    @ /opt/julia/packages/DiffEqBase/aAyno/src/solve.jl:772 [inlined]
  [6] #solve#33
    @ /opt/julia/packages/DiffEqBase/aAyno/src/solve.jl:756 [inlined]
  [7] _concrete_solve_adjoint(::SciMLBase.SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, false, Vector{Float64}, Nothing, SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(OptTF.ode_noise), Base.Pairs{Symbol, Any, NTuple{5, Symbol}, NamedTuple{(:reltol, :abstol, :callback, :saveat, :maxiters), Tuple{Float64, Float64, Nothing, Vector{Float64}, Float64}}}, Nothing}, ::StochasticDiffEq.ISSEM{0, true, Nothing, typeof(OrdinaryDiffEq.DEFAULT_PRECS), Val{:central}, true, nothing, DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, Float64, :Predictive}, ::DiffEqSensitivity.InterpolatingAdjoint{0, true, Val{:central}, DiffEqSensitivity.ZygoteVJP}, ::Vector{Float64}, ::Vector{Float64}, ::SciMLBase.ChainRulesOriginator; save_start::Bool, save_end::Bool, saveat::Vector{Float64}, save_idxs::Nothing, kwargs::Base.Pairs{Symbol, Union{Nothing, Real}, NTuple{5, Symbol}, NamedTuple{(:verbose, :reltol, :abstol, :callback, :maxiters), Tuple{Bool, Float64, Float64, Nothing, Float64}}})
    @ DiffEqSensitivity /opt/julia/packages/DiffEqSensitivity/Pn9H4/src/concrete_solve.jl:164
  [8] #_concrete_solve_adjoint#224
    @ /opt/julia/packages/DiffEqSensitivity/Pn9H4/src/concrete_solve.jl:102 [inlined]
  [9] #_solve_adjoint#57
    @ /opt/julia/packages/DiffEqBase/aAyno/src/solve.jl:1142 [inlined]
 [10] _solve_adjoint
    @ /opt/julia/packages/DiffEqBase/aAyno/src/solve.jl:1111 [inlined]
 [11] #rrule#55
    @ /opt/julia/packages/DiffEqBase/aAyno/src/solve.jl:1095 [inlined]
 [12] rrule
    @ /opt/julia/packages/DiffEqBase/aAyno/src/solve.jl:1091 [inlined]
 [13] rrule
    @ /opt/julia/packages/ChainRulesCore/16PWJ/src/rules.jl:134 [inlined]
 [14] chain_rrule
    @ /opt/julia/packages/Zygote/IoW2g/src/compiler/chainrules.jl:217 [inlined]
 [15] macro expansion
    @ /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:0 [inlined]
 [16] _pullback
    @ /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:9 [inlined]
 [17] _apply
    @ ./boot.jl:816 [inlined]
 [18] adjoint
    @ /opt/julia/packages/Zygote/IoW2g/src/lib/lib.jl:204 [inlined]
 [19] _pullback
    @ /opt/julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [20] _pullback
    @ /opt/julia/packages/DiffEqBase/aAyno/src/solve.jl:756 [inlined]
 [21] _pullback(::Zygote.Context, ::DiffEqBase.var"##solve#33", ::Nothing, ::Vector{Float64}, ::Vector{Float64}, ::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::typeof(CommonSolve.solve), ::SciMLBase.SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, false, Vector{Float64}, Nothing, SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(OptTF.ode_noise), Base.Pairs{Symbol, Any, NTuple{5, Symbol}, NamedTuple{(:reltol, :abstol, :callback, :saveat, :maxiters), Tuple{Float64, Float64, Nothing, Vector{Float64}, Float64}}}, Nothing}, ::StochasticDiffEq.ISSEM{0, true, Nothing, typeof(OrdinaryDiffEq.DEFAULT_PRECS), Val{:central}, true, nothing, DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, Float64, :Predictive})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:0
 [22] _apply(::Function, ::Vararg{Any})
    @ Core ./boot.jl:816
 [23] adjoint
    @ /opt/julia/packages/Zygote/IoW2g/src/lib/lib.jl:204 [inlined]
 [24] _pullback
    @ /opt/julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [25] _pullback
    @ /opt/julia/packages/DiffEqBase/aAyno/src/solve.jl:749 [inlined]
 [26] _pullback(::Zygote.Context, ::CommonSolve.var"#solve##kw", ::NamedTuple{(:u0, :p), Tuple{Vector{Float64}, Vector{Float64}}}, ::typeof(CommonSolve.solve), ::SciMLBase.SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, false, Vector{Float64}, Nothing, SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(OptTF.ode_noise), Base.Pairs{Symbol, Any, NTuple{5, Symbol}, NamedTuple{(:reltol, :abstol, :callback, :saveat, :maxiters), Tuple{Float64, Float64, Nothing, Vector{Float64}, Float64}}}, Nothing}, ::StochasticDiffEq.ISSEM{0, true, Nothing, typeof(OrdinaryDiffEq.DEFAULT_PRECS), Val{:central}, true, nothing, DiffEqBase.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}}, Float64, :Predictive})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:0
 [27] _pullback
    @ ~/sim/zzOtherLang/julia/projects/OptTF/src/OptTF.jl:241 [inlined]
 [28] _pullback(::Zygote.Context, ::OptTF.var"#predict_ode_dummy#13"{Settings, Float64, Float64, Float64}, ::Vector{Float64}, ::SciMLBase.SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, false, Vector{Float64}, Nothing, SciMLBase.SDEFunction{false, OptTF.var"#24#26"{Settings, loss_args, OptTF.OptTF_settings.OptTF_data.Circadian}, typeof(OptTF.ode_noise), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(OptTF.ode_noise), Base.Pairs{Symbol, Any, NTuple{5, Symbol}, NamedTuple{(:reltol, :abstol, :callback, :saveat, :maxiters), Tuple{Float64, Float64, Nothing, Vector{Float64}, Float64}}}, Nothing})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:0
 [29] _pullback
    @ ~/sim/zzOtherLang/julia/projects/OptTF/src/OptTF.jl:320 [inlined]
 [30] _pullback(::Zygote.Context, ::typeof(loss), ::Vector{Float64}, ::Settings, ::loss_args)
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:0
 [31] _pullback
    @ ~/sim/zzOtherLang/julia/projects/OptTF/src/OptTF.jl:351 [inlined]
 [32] _pullback(::Zygote.Context, ::OptTF.var"#35#36"{Settings, loss_args}, ::Vector{Float64}, ::Vector{Float64})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:0
 [33] _apply
    @ ./boot.jl:816 [inlined]
 [34] adjoint
    @ /opt/julia/packages/Zygote/IoW2g/src/lib/lib.jl:204 [inlined]
 [35] _pullback
    @ /opt/julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [36] _pullback
    @ /opt/julia/packages/SciMLBase/TqBga/src/scimlfunctions.jl:2891 [inlined]
 [37] _pullback(::Zygote.Context, ::SciMLBase.OptimizationFunction{true, Optimization.AutoZygote, OptTF.var"#35#36"{Settings, loss_args}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, ::Vector{Float64}, ::Vector{Float64})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:0
 [38] _apply(::Function, ::Vararg{Any})
    @ Core ./boot.jl:816
 [39] adjoint
    @ /opt/julia/packages/Zygote/IoW2g/src/lib/lib.jl:204 [inlined]
 [40] _pullback
    @ /opt/julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [41] _pullback
    @ /opt/julia/packages/Optimization/i9NGR/src/function/zygote.jl:30 [inlined]
 [42] _pullback(ctx::Zygote.Context, f::Optimization.var"#128#138"{SciMLBase.OptimizationFunction{true, Optimization.AutoZygote, OptTF.var"#35#36"{Settings, loss_args}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}}, args::Vector{Float64})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:0
 [43] _apply(::Function, ::Vararg{Any})
    @ Core ./boot.jl:816
 [44] adjoint
    @ /opt/julia/packages/Zygote/IoW2g/src/lib/lib.jl:204 [inlined]
 [45] _pullback
    @ /opt/julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [46] _pullback
    @ /opt/julia/packages/Optimization/i9NGR/src/function/zygote.jl:32 [inlined]
 [47] _pullback(ctx::Zygote.Context, f::Optimization.var"#131#141"{Tuple{}, Optimization.var"#128#138"{SciMLBase.OptimizationFunction{true, Optimization.AutoZygote, OptTF.var"#35#36"{Settings, loss_args}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}}}, args::Vector{Float64})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface2.jl:0
 [48] _pullback(f::Function, args::Vector{Float64})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface.jl:34
 [49] pullback(f::Function, args::Vector{Float64})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface.jl:40
 [50] gradient(f::Function, args::Vector{Float64})
    @ Zygote /opt/julia/packages/Zygote/IoW2g/src/compiler/interface.jl:75
 [51] (::Optimization.var"#129#139"{Optimization.var"#128#138"{SciMLBase.OptimizationFunction{true, Optimization.AutoZygote, OptTF.var"#35#36"{Settings, loss_args}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}}})(::Vector{Float64}, ::Vector{Float64})
    @ Optimization /opt/julia/packages/Optimization/i9NGR/src/function/zygote.jl:32
 [52] macro expansion
    @ /opt/julia/packages/OptimizationOptimisers/XLPqT/src/OptimizationOptimisers.jl:35 [inlined]
 [53] macro expansion
    @ /opt/julia/packages/Optimization/i9NGR/src/utils.jl:35 [inlined]
 [54] __solve(prob::SciMLBase.OptimizationProblem{true, SciMLBase.OptimizationFunction{true, Optimization.AutoZygote, OptTF.var"#35#36"{Settings, loss_args}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, opt::Optimisers.Adam{Float64}, data::Base.Iterators.Cycle{Tuple{Optimization.NullData}}; maxiters::Int64, callback::Function, progress::Bool, save_best::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ OptimizationOptimisers /opt/julia/packages/OptimizationOptimisers/XLPqT/src/OptimizationOptimisers.jl:33
 [55] #solve#516
    @ /opt/julia/packages/SciMLBase/TqBga/src/solve.jl:71 [inlined]
 [56] fit_diffeq(S::Settings; noise::Float64, new_rseed::Bool, init_on::Bool, offset::Bool, noise_wait::Float64, hill_k_init::Float64)
    @ OptTF ~/sim/zzOtherLang/julia/projects/OptTF/src/OptTF.jl:425
 [57] top-level scope
    @ REPL[15]:1
ChrisRackauckas commented 2 years ago

@frankschae can you look at this one/?

frankschae commented 2 years ago

Yes, I can have a look. @evolbio can you post an MWE? I am a bit confused by the stack trace. Are you differentiating the solve call (did you set a sensealg?)?

evolbio commented 2 years ago

@frankschae: I apologize, I do not yet have an MWE, which I realize would help a lot. For now, I think the following code pieces show most of the key points. In essence, I am using Optimization.jl solve, which requires setting up an OptimizationProblem based on an OptimizationFunction. If you have any questions, let me know. If this is not sufficient, I will try to put together a MWE.

I think the main point is that the error arises from line 60 of implicit_split_step.jl. I generated the same error when using ForwardDiff in another case, so I don't think it is Zygote, but rather something related to differentiating through ISSEM. I can't get any other SDE solver to work either but the issues seem to differ. Previously I was successfully using ISSEM for very similar code, so maybe some recent changes?

result = solve(opt_prob(p,S,L), ADAM(S.adm_learn), callback = callback,
                maxiters=S.max_it)

opt_func(S,L) = OptimizationFunction((p,u) -> loss(p,S,L), Optimization.AutoZygote())
opt_prob(p,S,L) = OptimizationProblem(opt_func(S,L), p, L.u0)

function loss(p, S, L)
    G = S.f_data(S; init_on=L.init_on, rand_offset=L.rand_offset, noise_wait=L.noise_wait)
    diffeq = (u, p, t) -> node(u, p, t, S, L.tf, L.re, L.state, G)
    prob = SDEProblem(diffeq, ode_noise, L.u0, L.prob.tspan, p,
                        reltol = S.rtol, abstol = S.atol,
                        callback=nothing, saveat = values(L.prob.kwargs).saveat,
                        maxiters=1e6)
    pred_all = L.predict(p, prob)

    # pick out tracked protein, first protein in system output
    pred = @view pred_all[S.n+1,:]
    pred_length = length(pred)
    input = @view G.input_true[1:pred_length]
    hill_input = hill.(0.5,L.hill_k,input)
    hill_pred  = hill.(S.switch_level,L.hill_k,pred)
    @assert pred_length == length(L.w)
    loss = sum(abs2, L.w .* (hill_input .- hill_pred))
    return loss, S, L, G, pred_all
end

sqrt_abs(x) = (x > 16.) ? sqrt(x) : abs(x) / 4.
ode_noise(u, p, t) = sqrt_abs.(u)

# this is condensed but has main points, solver is ISSEM()
L.predict(p,prob) = solve(prob, S.solver, u0=u_init, p=p[S.ddim+1:end])

function node(u, p, t, S, tf, re, state, G)
    n = S.n
    u_m = @view u[1:n]          # mRNA
    u_p = @view u[n+1:2n]       # protein
    p_rates = @view p[1:4n]
    p_nn = @view p[4n+1:end]

    # first 4n parameters are rates
    pp = linear_sigmoid.(p_rates, S.d, S.k1, S.k2)  # normalizes on [0,1] w/linear_sigmoid 
    # set min on rates m_a, m_d, p_a, p_d, causes top to be p_max + p_min
    ppp = (pp .* S.p_mult) .+ S.p_min

    m_a = @view ppp[1:n]
    m_d = @view ppp[n+1:2n]
    p_a = @view ppp[2n+1:3n]
    p_d = @view ppp[3n+1:4n]

    # remainder of p is for NN
    f_val = tf(u_p,re(p_nn),state)[1]
    du_m = m_a .* f_val .- m_d .* u_m       # mRNA level
    du_p = p_a .* u_m .- p_d .* u_p         # protein level
    light = G.circadian_val(G,t)            # noisy circadian input
    # fast extra production rate by post-translation modification or allostery
    du_p_2 = du_p[2] + S.light_prod_rate * intensity(light)
    return [du_m; du_p[1]; du_p_2; du_p[3:end]]
end
evolbio commented 2 years ago

I am using 1.8.0-rc1 on Mac Arm. 1.7 does not work fully on Mac M1 (arm).

julia> versioninfo()
Julia Version 1.8.0-rc1
Commit 6368fdc6565 (2022-05-27 18:33 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.3.0)
  CPU: 20 × Apple M1 Ultra
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 6 on 16 virtual cores
Environment:
  JULIA_DEPOT_PATH = /opt/julia:
  JULIA_NUM_THREADS = 6
  LD_LIBRARY_PATH = /Users/steve/sim/simlib/lib_osx:/opt/local/lib:/usr/local/lib:/usr/lib:/usr/X11/lib
  JULIA_WARN_COLOR = red

I noticed additional problems with, for example, loading CUDA when trying 1.8.0-rc3, so maybe julia version is related to this issue??

frankschae commented 2 years ago

Previously I was successfully using ISSEM for very similar code, so maybe some recent changes?

It seems to be a bug in the out-of-place code for ISSEM with adaptive steps. The in-place formulation works for me. I'll fix it and link the PR here. Perhaps, your other code was written in the in-place form?

MWE:

using StochasticDiffEq

fIto(u, p, t) = p[1] * u
σ(u, p, t) = p[2] * u

# set initial state
u0 = [1 / 6]
tspan = (0.0, 1.0)
dt = 1e-5

# non-exploding initialization.
α = 1 / (exp(-randn()) + 1)
β = -α^2 - 1 / (exp(-randn()) + 1)
p = [α, β]

# define problem in Ito sense
probIto = SDEProblem(fIto, σ, u0, tspan, p)

# solve Ito sense
solIto = solve(probIto, ISSEM())
evolbio commented 2 years ago

Thanks very much. I did have success with a different problem and in-place form with ISSEM. Not sure about all of the variations I have tried, but it seems likely that your comments are correct.

evolbio commented 2 years ago

I updated StochasticDiffEq to 6.50.1 and also updated other packages to 7/24/2022 date. Prior error solved. However, I get a new error

ERROR: MethodError: no method matching vec(::Nothing)
Closest candidates are:
  vec(::Tuple{Vararg{MultivariatePolynomials.AbstractVariable}}) at /opt/julia/packages/MultivariatePolynomials/1bIGc/src/operators.jl:348
  vec(::StrideArraysCore.PtrArray{S, D, T, 1, C, 0}) where {S, D, T, C} at /opt/julia/packages/StrideArraysCore/VQxXL/src/reshape.jl:1
  vec(::StrideArraysCore.PtrArray{S, D, T, N, C, 0}) where {S, D, T, N, C} at /opt/julia/packages/StrideArraysCore/VQxXL/src/reshape.jl:2
  ...
Stacktrace:
  [1] _jacNoise!(λ::SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}

Full stacktrace attached. Thanks. trace.txt

evolbio commented 2 years ago

NOTES: My code works with ForwardDiff and also works for an ODE problem when using Zygote, so it seems to be an interaction between Zygote and the SDE form. The switch from ODE to SDE requires (1) adding a noise function, which in this case is

sqrt_abs(x) = (x > 16.) ? sqrt(x) : abs(x) / 4.
ode_noise(u, p, t) = sqrt_abs.(u)

and (2) changing from Tstit5() to ISSEM() when using SDEProblem instead of ODEProblem. The following small example works, so the problem is associated with the more extensive form used in my code, but I still have not gotten it down to a MWE.

# This succeeds, not clear what needs to be added to trigger error
using Optimization, DifferentialEquations, DiffEqSensitivity, OptimizationOptimisers

n = 3

function ode1(u, p, t)
    du = p[1:n] .* u .- p[n+1:2n]
end

ode = ode1

sqrt_abs(x) = (x > 16.) ? sqrt(x) : abs(x) / 4.
ode_noise(u, p, t) = sqrt_abs.(u)

function loss(p, u0)
    prob = SDEProblem(ode, ode_noise, u0, (0.,1.), p, saveat=0:0.1:1)
    x = solve(prob, ISSEM(), p=p)
    y = [sin(2*pi*z) for z = 0:0.1:1]
    sum(abs2.(x[1,:] - y))
end

opt_func(p,u0) = OptimizationFunction((p,u0) -> loss(p,u0), Optimization.AutoZygote())
opt_prob(p,u0) = OptimizationProblem(opt_func(p,u0), p, u0)

p = randn(2n);
u0 = randn(n);

result = solve(opt_prob(p, u0), ADAM(), maxiters=50)
frankschae commented 2 years ago

This might be more difficult to solve than the previous one because it's related to the sensitivity analysis tools and not only to the primal evaluation of the SDE solution.

so the problem is associated with the more extensive form used in my code, but I still have not gotten it down to a MWE.

Can you try to replace

x = solve(prob, ISSEM(), p=p)

by

x = solve(prob, ISSEM(), p=p, sensealg=BacksolveAdjoint())

I think your example might have a too small number of parameters. For small numbers of parameters, we're using tangent/forward sensitivity methods per default to compute the backward pass through the SDE solution.

I wanted to look into some SDE sensitivity issues. So I hope to get to it soon.

evolbio commented 2 years ago

Using the option sensealg=BacksolveAdjoint() in the above short example code leads to the warning:

julia> result = solve(opt_prob(p, u0), ADAM(), maxiters=50)
┌ Warning: Automatic AD choice of autojacvec failed in ODE adjoint, failing back to ODE adjoint + numerical vjp
└ @ DiffEqSensitivity /opt/julia/packages/DiffEqSensitivity/Pn9H4/src/sensitivity_interface.jl:290

I raised n=1000 to invoke internal algorithms for a larger parameter vector and then tried some other combinations. All either gave an error or were so slow that I gave up before getting any return.

ChrisRackauckas commented 2 years ago

Can you make a new issue to SciMLSensitivity.jl? What's left is unrelated to the SDE solver itself.