Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SavingCallback broken? #56

Closed
dkarrasch opened this issue Jan 11, 2019 · 1 comment · Fixed by SciML/DiffEqDocs.jl#191
Closed

SavingCallback broken? #56

dkarrasch opened this issue Jan 11, 2019 · 1 comment · Fixed by SciML/DiffEqDocs.jl#191

Comments

@dkarrasch
Copy link

dkarrasch commented Jan 11, 2019

I took the example from the callback docs (slightly corrected for Julia 0.7+

using DiffEqCallbacks, OrdinaryDiffEq, LinearAlgebra
prob = ODEProblem((du, u, t) -> du .= u, rand(4,4), (0.0, 1.0))
saved_values = SavedValues(Float64, Tuple{Float64,Float64})
cb = SavingCallback((u, t, integrator) -> (tr(u), norm(u)), saved_values)
sol = solve(prob, Tsit5(), callback=cb)

and got

ERROR: MethodError: Cannot `convert` an object of type Nothing to an object of type Float64
Closest candidates are:
  convert(::Type{T<:Number}, ::T<:Number) where T<:Number at number.jl:6
  convert(::Type{T<:Number}, ::Number) where T<:Number at number.jl:7
  convert(::Type{T<:Number}, ::Base.TwicePrecision) where T<:Number at twiceprecision.jl:250
  ...
Stacktrace:
 [1] fill!(::Array{Float64,2}, ::Nothing) at ./array.jl:386
 [2] copyto! at ./broadcast.jl:808 [inlined]
 [3] materialize! at ./broadcast.jl:759 [inlined]
 [4] (::getfield(Main, Symbol("##9#10")))(::Array{Float64,2}, ::Nothing, ::Float64) at ./none:1
 [5] (::ODEFunction{false,getfield(Main, Symbol("##9#10")),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing})(::Array{Float64,2}, ::Nothing, ::Vararg{Any,N} where N) at /Users/karrasch/.julia/packages/DiffEqBase/8usQ9/src/diffeqfunction.jl:106
 [6] initialize!(::OrdinaryDiffEq.ODEIntegrator{Tsit5,Array{Float64,2},Float64,Nothing,Float64,Float64,Float64,Array{Array{Float64,2},1},ODESolution{Float64,3,Array{Array{Float64,2},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,2},1},1},ODEProblem{Array{Float64,2},Tuple{Float64,Float64},false,Nothing,ODEFunction{false,getfield(Main, Symbol("##9#10")),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFunction{false,getfield(Main, Symbol("##9#10")),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Array{Array{Float64,2},1},Array{Float64,1},Array{Array{Array{Float64,2},1},1},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}}},ODEFunction{false,getfield(Main, Symbol("##9#10")),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64},OrdinaryDiffEq.DEOptions{Float64,Float64,Float64,Float64,typeof(DiffEqBase.ODE_DEFAULT_NORM),typeof(opnorm),CallbackSet{Tuple{},Tuple{DiscreteCallback{getfield(DiffEqCallbacks, Symbol("##28#29")),DiffEqCallbacks.SavingAffect{getfield(Main, Symbol("##11#12")),Float64,Tuple{Float64,Float64},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Array{Float64,1}},typeof(DiffEqCallbacks.saving_initialize)}}},typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN),typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE),typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK),DataStructures.BinaryHeap{Float64,DataStructures.LessThan},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Nothing,Nothing,Int64,Array{Float64,1},Array{Float64,1},Array{Float64,1}},Array{Float64,2},Float64}, ::OrdinaryDiffEq.Tsit5ConstantCache{Float64,Float64}) at /Users/karrasch/.julia/packages/OrdinaryDiffEq/SXL9q/src/perform_step/low_order_rk_perform_step.jl:524
 [7] #__init#205(::Int64, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Nothing, ::Bool, ::Nothing, ::Bool, ::Bool, ::Bool, ::DiscreteCallback{getfield(DiffEqCallbacks, Symbol("##28#29")),DiffEqCallbacks.SavingAffect{getfield(Main, Symbol("##11#12")),Float64,Tuple{Float64,Float64},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Array{Float64,1}},typeof(DiffEqCallbacks.saving_initialize)}, ::Bool, ::Bool, ::Float64, ::Bool, ::Rational{Int64}, ::Nothing, ::Nothing, ::Int64, ::Rational{Int64}, ::Int64, ::Int64, ::Rational{Int64}, ::Bool, ::Int64, ::Nothing, ::Nothing, ::Int64, ::Float64, ::Float64, ::typeof(DiffEqBase.ODE_DEFAULT_NORM), ::typeof(opnorm), ::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), ::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Int64, ::String, ::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), ::Nothing, ::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.__init), ::ODEProblem{Array{Float64,2},Tuple{Float64,Float64},false,Nothing,ODEFunction{false,getfield(Main, Symbol("##9#10")),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Type{Val{true}}) at /Users/karrasch/.julia/packages/OrdinaryDiffEq/SXL9q/src/solve.jl:325
 [8] (::getfield(DiffEqBase, Symbol("#kw##__init")))(::NamedTuple{(:callback,),Tuple{DiscreteCallback{getfield(DiffEqCallbacks, Symbol("##28#29")),DiffEqCallbacks.SavingAffect{getfield(Main, Symbol("##11#12")),Float64,Tuple{Float64,Float64},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Array{Float64,1}},typeof(DiffEqCallbacks.saving_initialize)}}}, ::typeof(DiffEqBase.__init), ::ODEProblem{Array{Float64,2},Tuple{Float64,Float64},false,Nothing,ODEFunction{false,getfield(Main, Symbol("##9#10")),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Type{Val{true}}) at ./none:0
 [9] #__solve#204(::Base.Iterators.Pairs{Symbol,DiscreteCallback{getfield(DiffEqCallbacks, Symbol("##28#29")),DiffEqCallbacks.SavingAffect{getfield(Main, Symbol("##11#12")),Float64,Tuple{Float64,Float64},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Array{Float64,1}},typeof(DiffEqCallbacks.saving_initialize)},Tuple{Symbol},NamedTuple{(:callback,),Tuple{DiscreteCallback{getfield(DiffEqCallbacks, Symbol("##28#29")),DiffEqCallbacks.SavingAffect{getfield(Main, Symbol("##11#12")),Float64,Tuple{Float64,Float64},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Array{Float64,1}},typeof(DiffEqCallbacks.saving_initialize)}}}}, ::Function, ::ODEProblem{Array{Float64,2},Tuple{Float64,Float64},false,Nothing,ODEFunction{false,getfield(Main, Symbol("##9#10")),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5, ::Array{Any,1}, ::Array{Any,1}, ::Array{Any,1}, ::Type{Val{true}}) at /Users/karrasch/.julia/packages/OrdinaryDiffEq/SXL9q/src/solve.jl:6
 [10] #__solve at ./none:0 [inlined] (repeats 5 times)
 [11] #solve#442(::Base.Iterators.Pairs{Symbol,DiscreteCallback{getfield(DiffEqCallbacks, Symbol("##28#29")),DiffEqCallbacks.SavingAffect{getfield(Main, Symbol("##11#12")),Float64,Tuple{Float64,Float64},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Array{Float64,1}},typeof(DiffEqCallbacks.saving_initialize)},Tuple{Symbol},NamedTuple{(:callback,),Tuple{DiscreteCallback{getfield(DiffEqCallbacks, Symbol("##28#29")),DiffEqCallbacks.SavingAffect{getfield(Main, Symbol("##11#12")),Float64,Tuple{Float64,Float64},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Array{Float64,1}},typeof(DiffEqCallbacks.saving_initialize)}}}}, ::Function, ::ODEProblem{Array{Float64,2},Tuple{Float64,Float64},false,Nothing,ODEFunction{false,getfield(Main, Symbol("##9#10")),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5) at /Users/karrasch/.julia/packages/DiffEqBase/8usQ9/src/solve.jl:39
 [12] (::getfield(DiffEqBase, Symbol("#kw##solve")))(::NamedTuple{(:callback,),Tuple{DiscreteCallback{getfield(DiffEqCallbacks, Symbol("##28#29")),DiffEqCallbacks.SavingAffect{getfield(Main, Symbol("##11#12")),Float64,Tuple{Float64,Float64},DataStructures.BinaryHeap{Float64,DataStructures.LessThan},Array{Float64,1}},typeof(DiffEqCallbacks.saving_initialize)}}}, ::typeof(solve), ::ODEProblem{Array{Float64,2},Tuple{Float64,Float64},false,Nothing,ODEFunction{false,getfield(Main, Symbol("##9#10")),UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Nothing,DiffEqBase.StandardODEProblem}, ::Tsit5) at ./none:0
 [13] top-level scope at none:0
@dkarrasch
Copy link
Author

dkarrasch commented Jan 11, 2019

I just saw that the parameter p in the second line was also missing. That fixes the issue.

EDIT: Well, I guess what remains is to fix the docs.

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

Successfully merging a pull request may close this issue.

1 participant