-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Allocations in callbacks #8
Comments
|
Thanks! But strange behaviour from this. I tried to modify my callback function as such function dHdu_residual(c::CurveProblem, u, t, integ, ::MDCDynamics)
N = num_params(c)
H = c.momentum
θ₀ = initial_params(c)
θ = u[1:N]
λ = u[N + 1:end]
μ2 = (c.cost(θ) - H) / 2.
μ1 = t > 1e-3 ? (λ' * λ - 4 * μ2^2 ) / (λ' * (θ - θ₀)) : 0.
dθ = SciMLBase.get_tmp_cache(integ)[1][1:N]
dθ[:] = (-λ + μ1 * (θ - θ₀)) / (2 * μ2)
dθ /= (sqrt(sum((dθ).^2)))
return sum(abs.(λ + 2 * μ2 * dθ))
end Partway through the simulation (and after the callback has been called multiple times), I get an error: Are there any examples of |
|
Sure, I made a new branch: NonAllocatingCallbacks. On this branch if you do
you get the error. The error is resolved if you get rid of the tmp_cache, e.g. by replacing Thanks! |
Post the stacktrace and error? |
My bad, here they are: ERROR: LoadError: MethodError: no method matching setindex!(::Nothing, ::Vector{Float64}, ::Colon)
Stacktrace:
[1] dHdu_residual(c::MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, u::Vector{Float64}, t::Float64, dθ::Nothing, #unused#::MinimallyDisruptiveCurves.MDCDynamics)
@ MinimallyDisruptiveCurves ~/.julia/dev/MinimallyDisruptiveCurves.jl/src/MDCProblem.jl:200
[2] dHdu_residual(c::MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, u::Vector{Float64}, t::Float64, p::Nothing)
@ MinimallyDisruptiveCurves ~/.julia/dev/MinimallyDisruptiveCurves.jl/src/MDCTypes.jl:20
[3] (::HamiltonianResidual{Float64})(c::MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, u::Vector{Float64}, t::Float64, integ::OrdinaryDiffEq.ODEIntegrator{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, SciMLBase.NullParameters, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{CurveDistance{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{HamiltonianResidual{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#rescond#14"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Float64, Int64}, MinimallyDisruptiveCurves.var"#16#18"{MinimallyDisruptiveCurves.var"#reset_costate!#17"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Vector{Float64}, Float64, Int64}}, typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#condition#13"{Int64, Float64, DiffCost{typeof(loss), typeof(lossgrad)}}, typeof(terminate!), typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}}}, 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, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit})
@ MinimallyDisruptiveCurves ~/.julia/dev/MinimallyDisruptiveCurves.jl/src/evolve_options.jl:71
[4] (::MinimallyDisruptiveCurves.var"#92#95"{HamiltonianResidual{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}})(u::Vector{Float64}, t::Float64, _integ::OrdinaryDiffEq.ODEIntegrator{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, SciMLBase.NullParameters, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{CurveDistance{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{HamiltonianResidual{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#rescond#14"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Float64, Int64}, MinimallyDisruptiveCurves.var"#16#18"{MinimallyDisruptiveCurves.var"#reset_costate!#17"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Vector{Float64}, Float64, Int64}}, typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#condition#13"{Int64, Float64, DiffCost{typeof(loss), typeof(lossgrad)}}, typeof(terminate!), typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}}}, 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, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit})
@ MinimallyDisruptiveCurves ~/.julia/dev/MinimallyDisruptiveCurves.jl/src/evolve_options.jl:80
[5] (::DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{HamiltonianResidual{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}})(integrator::OrdinaryDiffEq.ODEIntegrator{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, SciMLBase.NullParameters, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{CurveDistance{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{HamiltonianResidual{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#rescond#14"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Float64, Int64}, MinimallyDisruptiveCurves.var"#16#18"{MinimallyDisruptiveCurves.var"#reset_costate!#17"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Vector{Float64}, Float64, Int64}}, typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#condition#13"{Int64, Float64, DiffCost{typeof(loss), typeof(lossgrad)}}, typeof(terminate!), typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}}}, 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, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}, force_func::Bool)
@ DiffEqCallbacks ~/.julia/packages/DiffEqCallbacks/K2FFO/src/function_caller.jl:26
[6] FunctionCallingAffect
@ ~/.julia/packages/DiffEqCallbacks/K2FFO/src/function_caller.jl:12 [inlined]
[7] apply_discrete_callback!
@ ~/.julia/packages/DiffEqBase/YIT73/src/callbacks.jl:865 [inlined]
[8] apply_discrete_callback!
@ ~/.julia/packages/DiffEqBase/YIT73/src/callbacks.jl:881 [inlined]
[9] apply_discrete_callback!
@ ~/.julia/packages/DiffEqBase/YIT73/src/callbacks.jl:877 [inlined]
[10] handle_callbacks!(integrator::OrdinaryDiffEq.ODEIntegrator{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, SciMLBase.NullParameters, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{CurveDistance{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{HamiltonianResidual{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#rescond#14"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Float64, Int64}, MinimallyDisruptiveCurves.var"#16#18"{MinimallyDisruptiveCurves.var"#reset_costate!#17"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Vector{Float64}, Float64, Int64}}, typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#condition#13"{Int64, Float64, DiffCost{typeof(loss), typeof(lossgrad)}}, typeof(terminate!), typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}}}, 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, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit})
@ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/4BjSL/src/integrators/integrator_utils.jl:267
[11] _loopfooter!(integrator::OrdinaryDiffEq.ODEIntegrator{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, SciMLBase.NullParameters, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{CurveDistance{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{HamiltonianResidual{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#rescond#14"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Float64, Int64}, MinimallyDisruptiveCurves.var"#16#18"{MinimallyDisruptiveCurves.var"#reset_costate!#17"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Vector{Float64}, Float64, Int64}}, typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#condition#13"{Int64, Float64, DiffCost{typeof(loss), typeof(lossgrad)}}, typeof(terminate!), typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}}}, 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, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit})
@ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/4BjSL/src/integrators/integrator_utils.jl:207
[12] loopfooter!
@ ~/.julia/packages/OrdinaryDiffEq/4BjSL/src/integrators/integrator_utils.jl:168 [inlined]
[13] solve!(integrator::OrdinaryDiffEq.ODEIntegrator{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, true, Vector{Float64}, Nothing, Float64, SciMLBase.NullParameters, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{CurveDistance{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{HamiltonianResidual{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#rescond#14"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Float64, Int64}, MinimallyDisruptiveCurves.var"#16#18"{MinimallyDisruptiveCurves.var"#reset_costate!#17"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Vector{Float64}, Float64, Int64}}, typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#condition#13"{Int64, Float64, DiffCost{typeof(loss), typeof(lossgrad)}}, typeof(terminate!), typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}}}, 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, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit})
@ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/4BjSL/src/solve.jl:479
[14] #__solve#493
@ ~/.julia/packages/OrdinaryDiffEq/4BjSL/src/solve.jl:5 [inlined]
[15] #solve_call#42
@ ~/.julia/packages/DiffEqBase/YIT73/src/solve.jl:61 [inlined]
[16] #solve_up#44
@ ~/.julia/packages/DiffEqBase/YIT73/src/solve.jl:87 [inlined]
[17] #solve#43
@ ~/.julia/packages/DiffEqBase/YIT73/src/solve.jl:73 [inlined]
[18] (::MinimallyDisruptiveCurves.var"#runn#102"{Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, UnionAll, CallbackSet{Tuple{}, Tuple{DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{CurveDistance{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{DiffEqCallbacks.var"#27#28", DiffEqCallbacks.FunctionCallingAffect{MinimallyDisruptiveCurves.var"#92#95"{HamiltonianResidual{Float64}, MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}}, typeof(DiffEqCallbacks.functioncalling_initialize), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#rescond#14"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Float64, Int64}, MinimallyDisruptiveCurves.var"#16#18"{MinimallyDisruptiveCurves.var"#reset_costate!#17"{MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, Vector{Float64}, Float64, Int64}}, typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}, DiscreteCallback{MinimallyDisruptiveCurves.var"#condition#13"{Int64, Float64, DiffCost{typeof(loss), typeof(lossgrad)}}, typeof(terminate!), typeof(DiffEqBase.INITIALIZE_DEFAULT), typeof(DiffEqBase.FINALIZE_DEFAULT)}}}})(p::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, MinimallyDisruptiveCurves.var"#upd#12"{Vector{Float64}, Float64, Int64, Vector{Float64}, DiffCost{typeof(loss), typeof(lossgrad)}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem})
@ MinimallyDisruptiveCurves ~/.julia/dev/MinimallyDisruptiveCurves.jl/src/evolve.jl:24
[19] evolve(c::MDCProblem{DiffCost{typeof(loss), typeof(lossgrad)}, Vector{Float64}, Vector{Float64}, Float64, Tuple{Float64, Float64}}, solmethod::Type{Tsit5}; mdc_callback::Vector{Verbose{CurveInfoSnippet}}, callback::Nothing, momentum_tol::Float64, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ MinimallyDisruptiveCurves ~/.julia/dev/MinimallyDisruptiveCurves.jl/src/evolve.jl:29
[20] top-level scope
@ ./timing.jl:210
in expression starting at /Users/dvr23/.julia/dev/MinimallyDisruptiveCurves.jl/play/mwe.jl:58 |
Which solver are you using? |
Tsit5 |
Check out the functions
dHdu_residual
andbuild_affect(::MDCProblem, ::CostateAffect)
in src/MDCProblem.jl.You will notice that there is an unnecessary allocation in the line
dθ = ...
. This could be expensive in problems with many parameters.I initially used
dθ[:] = ....
, but this produced unreliable output (the MDCurve changed on each solution). I found that this was because temporary arrays like this are not safe in callbacks, for some reason. The solution is to use SciMLBase.get_tmp_cache, I think. Don't have time to figure out how to do this right now. Do at some point (me or anybody else who is interested of course!)The text was updated successfully, but these errors were encountered: