SciML / DifferentialEquations.jl

Multi-language suite for high-performance solvers of differential equations and scientific machine learning (SciML) components. Ordinary differential equations (ODEs), stochastic differential equations (SDEs), delay differential equations (DDEs), differential-algebraic equations (DAEs), and more in Julia.
https://docs.sciml.ai/DiffEqDocs/stable/
Other
2.88k stars 230 forks source link

Integrator Object Plot for ODE Problem #799

Open QiyaoWei opened 3 years ago

QiyaoWei commented 3 years ago

Hi all, I am trying to follow this tutorial to plot an integrator object (https://diffeq.sciml.ai/stable/basics/integrator/), but received the following error. For completeness, I also post the segment of code where I use the plot function. Any help is appreciated. Thanks a lot!

ERROR: LoadError: MethodError: no method matching interpret_vars(::Nothing, ::ODESolution{Float32, 2, Vector{Vector{Float32}}, Nothing, Nothing, Vector{Float32}, Vector{Vector{Vector{Float32}}}, ODEProblem{Vector{Float32}, Tuple{Float32, Float32}, false, Vector{Float32}, ODEFunction{false, var"#dudt_#31"{Vector{Int64}}, 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, OrdinaryDiffEq.InterpolationData{ODEFunction{false, var"#dudt_#31"{Vector{Int64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float32}}, Vector{Float32}, Vector{Vector{Vector{Float32}}}, OrdinaryDiffEq.Tsit5ConstantCache{Float32, Float32}}, DiffEqBase.DEStats})
Closest candidates are:
  interpret_vars(::Any, ::Any, ::Any) at /Users/qiyaowei/.julia/packages/SciMLBase/UIp7W/src/solutions/solution_interface.jl:387
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/SciMLBase/UIp7W/src/integrator_interface.jl:487 [inlined]
  [2] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, integrator::SciMLBase.DEIntegrator)
    @ SciMLBase ~/.julia/packages/RecipesBase/3fzVq/src/RecipesBase.jl:283
  [3] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/i2bA0/src/user_recipe.jl:36
  [4] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/i2bA0/src/RecipesPipeline.jl:70
  [5] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/4UbNP/src/plot.jl:208
  [6] plot(args::Any; kw::Any)
    @ Plots ~/.julia/packages/Plots/4UbNP/src/plot.jl:91
  [7] plot(args::Any)
    @ Plots ~/.julia/packages/Plots/4UbNP/src/plot.jl:85
  [8] solve_ss(x::Vector{Int64})
    @ Main ~/julia/simpleDEQ.jl:40
  [9] (::var"#32#33")()
    @ Main ~/julia/simpleDEQ.jl:85
 [10] top-level scope
    @ ~/julia/simpleDEQ.jl:93
 [11] include(fname::String)
    @ Base.MainInclude ./client.jl:444
 [12] top-level scope
    @ none:1
function solve_ss(x)
    z = re(p)(x)
    function dudt_(u, _p, t)
        # Solving the equation f(u) - u = du = 0
        re(_p)(u+x) - u
    end
    ss = ODEProblem(dudt_, z, tspan, p)
    xx = solve(ss, Tsit5(), u0=z, abstol=Float32(1e-5), reltol=Float32(1e-5), tspan=1.0f0).u
    integrator = init(ss,Tsit5();dt=1//2^(4),tstops=[0.5])
    pyplot(show=true)
    plot(integrator)
    for i in integrator
      display(plot!(integrator,vars=(0,1),legend=false))
    end
    step!(integrator); plot!(integrator,vars=(0,1),legend=false)
    savefig("iteratorplot.png")
end
ChrisRackauckas commented 3 years ago

Yup it looks like this is only implemented for AbstractTimeseriesSolutions right now, so non-time series objects (steady states) are missing this plot. This needs to get fixed.

QiyaoWei commented 3 years ago

Hey Chris! Thanks a lot for the reply! As a follow-up to this question, I have tried directly copying and pasting the code in the last section "Plot Recipe" from (https://diffeq.sciml.ai/stable/basics/integrator/), and it still returns the same issue. I wonder if this is a package issue? I append the error and code here for completeness

ERROR: LoadError: MethodError: no method matching interpret_vars(::Nothing, ::ODESolution{Float64, 1, Vector{Float64}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Float64}}, ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, var"#7#8", LinearAlgebra.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, OrdinaryDiffEq.InterpolationData{ODEFunction{false, var"#7#8", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}, Vector{Vector{Float64}}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, DiffEqBase.DEStats})
Closest candidates are:
  interpret_vars(::Any, ::Any, ::Any) at /Users/qiyaowei/.julia/packages/SciMLBase/UIp7W/src/solutions/solution_interface.jl:387
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/SciMLBase/UIp7W/src/integrator_interface.jl:487 [inlined]
  [2] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, integrator::SciMLBase.DEIntegrator)
    @ SciMLBase ~/.julia/packages/RecipesBase/3fzVq/src/RecipesBase.jl:283
  [3] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/i2bA0/src/user_recipe.jl:36
  [4] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/i2bA0/src/RecipesPipeline.jl:70
  [5] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/Di0Qb/src/plot.jl:208
  [6] plot(args::Any; kw::Any)
    @ Plots ~/.julia/packages/Plots/Di0Qb/src/plot.jl:91
  [7] plot(args::Any)
    @ Plots ~/.julia/packages/Plots/Di0Qb/src/plot.jl:85
  [8] top-level scope
    @ ~/julia/test.jl:9
  [9] include(fname::String)
    @ Base.MainInclude ./client.jl:444
 [10] top-level scope
    @ none:1
in expression starting at /Users/qiyaowei/julia/test.jl:9
using DifferentialEquations, DiffEqProblemLibrary, Plots

# Linear ODE which starts at 0.5 and solves from t=0.0 to t=1.0
prob = ODEProblem((u,p,t)->1.01u,0.5,(0.0,1.0))

using Plots
integrator = init(prob,Tsit5();dt=1//2^(4),tstops=[0.5])
pyplot(show=true)
plot(integrator)
for i in integrator
  display(plot!(integrator,vars=(0,1),legend=false))
end
step!(integrator); plot!(integrator,vars=(0,1),legend=false)
savefig("iteratorplot.png")