JuliaDynamics / InteractiveDynamics.jl

Fast, general-purpose interactive applications for complex systems
https://juliadynamics.github.io/InteractiveDynamics.jl/dev/
MIT License
171 stars 25 forks source link

interactive_evolution's idxs parameter doesn't behave as expected #96

Open perryprog opened 2 years ago

perryprog commented 2 years ago

When using interactive_evolution (and possibly other function that support idxs; I haven't tested them), the idxs parameter doesn't seem to behave correctly. When using DynamicalSystem's double pendulum system (param order is [θ₁,ω₁,θ₂,ω₂]) and attempting to graph both theta values, this is what I get:

julia> using GLMakie, DynamicalSystems, InteractiveDynamics

julia> ds = Systems.double_pendulum()
4-dimensional continuous dynamical system
 state:       [1.5708, 0.0, 0.0, 0.5]
 rule f:      doublependulum_rule
 in-place?    false
 jacobian:    ForwardDiff
 parameters:  [10.0, 1.0, 1.0, 1.0, 1.0]

julia> interactive_evolution(ds; idxs = [1, 3]);

juila> # Click "Step" ("run" does nothing):
Error in callback:
BoundsError: attempt to access Tuple{Float64, Float64} at index [3]
Stacktrace ```julia Stacktrace: [1] getindex @ ./tuple.jl:29 [inlined] [2] getindex @ ~/.julia/packages/StaticArrays/6D1fn/src/SArray.jl:94 [inlined] [3] (::InteractiveDynamics.var"#69#77"{typeof(identity), SVector{2, Int64}, Vector{Int64}, Int64, Observable{Vector{Point{2, Float32}}}, Vector{Observable}, SimpleDiffEq.SimpleATsit5Integrator{true, Vector{SVector{4, Float64}}, Float64, Vector{Float64}, SciMLBase.ODEFunction{true, DynamicalSystemsBase.var"#30#32"{ContinuousDynamicalSystem{false, SVector{4, Float64}, 4, typeof(DynamicalSystemsBase.Systems.doublependulum_rule), Vector{Float64}, DynamicalSystemsBase.var"#9#15"{typeof(DynamicalSystemsBase.Systems.doublependulum_rule)}, SMatrix{4, 4, Float64, 16}, true}, Int64}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(DynamicalSystemsBase._parallelnorm)}, Int64})(clicks::Int64) @ InteractiveDynamics ~/.julia/packages/InteractiveDynamics/NHT8Y/src/chaos/trajanim.jl:175 [4] #invokelatest#2 @ ./essentials.jl:716 [inlined] [5] invokelatest @ ./essentials.jl:714 [inlined] [6] notify @ ~/.julia/packages/Observables/OFj0u/src/Observables.jl:88 [inlined] [7] setindex!(observable::Observable{Any}, val::Int64) @ Observables ~/.julia/packages/Observables/OFj0u/src/Observables.jl:248 [8] (::Makie.MakieLayout.var"#615#625"{Observable{Symbol}, Observable{Any}})(#unused#::MouseEvent) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/layoutables/button.jl:87 [9] (::Makie.MakieLayout.var"#30#31"{Makie.MakieLayout.var"#615#625"{Observable{Symbol}, Observable{Any}}})(event::MouseEvent) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/mousestatemachine.jl:86 [10] #invokelatest#2 @ ./essentials.jl:716 [inlined] [11] invokelatest @ ./essentials.jl:714 [inlined] [12] (::Makie.PrioCallback)(val::MouseEvent) @ Makie ~/.julia/packages/Makie/lgPZh/src/interaction/PriorityObservable.jl:16 [13] #invokelatest#2 @ ./essentials.jl:716 [inlined] [14] invokelatest @ ./essentials.jl:714 [inlined] [15] notify(observable::Makie.PriorityObservable{MouseEvent}) @ Makie ~/.julia/packages/Makie/lgPZh/src/interaction/PriorityObservable.jl:84 [16] setindex! @ ~/.julia/packages/Makie/lgPZh/src/interaction/PriorityObservable.jl:78 [inlined] [17] (::Makie.MakieLayout.var"#100#102"{Scene, Base.RefValue{Bool}, Base.RefValue{Union{Nothing, Makie.Mouse.Button}}, Base.RefValue{Float64}, Base.RefValue{Float64}, Base.RefValue{Bool}, Base.RefValue{Bool}, Base.RefValue{Union{Nothing, Makie.Mouse.Button}}, Base.RefValue{Bool}, Base.RefValue{Point{2, Float32}}, Base.RefValue{Point{2, Float32}}, Base.RefValue{Makie.Mouse.Action}, Makie.PriorityObservable{MouseEvent}, Float64, Module})(event::Makie.MouseButtonEvent) @ Makie.MakieLayout ~/.julia/packages/Makie/lgPZh/src/makielayout/mousestatemachine.jl:259 [18] #invokelatest#2 @ ./essentials.jl:716 [inlined] [19] invokelatest @ ./essentials.jl:714 [inlined] [20] (::Makie.PrioCallback)(val::Makie.MouseButtonEvent) @ Makie ~/.julia/packages/Makie/lgPZh/src/interaction/PriorityObservable.jl:16 [21] #invokelatest#2 @ ./essentials.jl:716 [inlined] [22] invokelatest @ ./essentials.jl:714 [inlined] [23] notify(observable::Makie.PriorityObservable{Makie.MouseButtonEvent}) @ Makie ~/.julia/packages/Makie/lgPZh/src/interaction/PriorityObservable.jl:84 [24] setindex! @ ~/.julia/packages/Makie/lgPZh/src/interaction/PriorityObservable.jl:78 [inlined] [25] (::GLMakie.var"#mousebuttons#78"{Makie.PriorityObservable{Makie.MouseButtonEvent}})(window::GLFW.Window, button::GLFW.MouseButton, action::GLFW.Action, mods::Int32) @ GLMakie ~/.julia/packages/GLMakie/TfSB1/src/events.jl:89 [26] _MouseButtonCallbackWrapper(window::GLFW.Window, button::GLFW.MouseButton, action::GLFW.Action, mods::Int32) @ GLFW ~/.julia/packages/GLFW/BWxfF/src/callback.jl:43 [27] PollEvents @ ~/.julia/packages/GLFW/BWxfF/src/glfw3.jl:620 [inlined] [28] pollevents @ ~/.julia/packages/GLMakie/TfSB1/src/screen.jl:545 [inlined] [29] fps_renderloop(screen::GLMakie.Screen, framerate::Float64) @ GLMakie ~/.julia/packages/GLMakie/TfSB1/src/rendering.jl:21 [30] renderloop(screen::GLMakie.Screen; framerate::Float64) @ GLMakie ~/.julia/packages/GLMakie/TfSB1/src/rendering.jl:48 [31] renderloop(screen::GLMakie.Screen) @ GLMakie ~/.julia/packages/GLMakie/TfSB1/src/rendering.jl:41 [32] (::GLMakie.var"#56#58"{GLMakie.Screen})() @ GLMakie ./task.jl:429 ```

If I attempt to use a tuple for idxs instead, as sometimes suggested by the documentation (I assume either an Array or a Tuple is supposed to be fine), I get this type error:


julia> interactive_evolution(ds; idxs = (1, 3))
ERROR: ArgumentError: invalid index: (1, 3) of type Tuple{Int64, Int64}
Stacktrace:
 [1] to_index(i::Tuple{Int64, Int64})
   @ Base ./indices.jl:300
 [2] to_index(A::SVector{4, Float64}, i::Tuple{Int64, Int64})
   @ Base ./indices.jl:277
 [3] to_indices
   @ ./indices.jl:333 [inlined]
 [4] to_indices
   @ ./indices.jl:325 [inlined]
 [5] getindex
   @ ./abstractarray.jl:1218 [inlined]
 [6] _init_timeseries_plots!(layout::GridLayout, pinteg::SimpleDiffEq.SimpleATsit5Integrator{true, Vector{SVector{4, Float64}}, Float64, Vector{Float64}, SciMLBase.ODEFunction{true, DynamicalSystemsBase.var"#30#32"{ContinuousDynamicalSystem{false, SVector{4, Float64}, 4, typeof(DynamicalSystemsBase.Systems.doublependulum_rule), Vector{Float64}, DynamicalSystemsBase.var"#9#15"{typeof(DynamicalSystemsBase.Systems.doublependulum_rule)}, SMatrix{4, 4, Float64, 16}, true}, Int64}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, typeof(DynamicalSystemsBase._parallelnorm)}, idxs::Tuple{Int64, Int64}, colors::Vector{ColorTypes.RGBA{Float32}}, linekwargs::NamedTuple{(:linewidth,), Tuple{Int64}}, transform::typeof(identity), tail::Int64, lims::Tuple{Tuple{Float64, Float64}, Tuple{Float64, Float64}})
   @ InteractiveDynamics ~/.julia/packages/InteractiveDynamics/NHT8Y/src/chaos/trajanim.jl:283
 [7] interactive_evolution(ds::ContinuousDynamicalSystem{false, SVector{4, Float64}, 4, typeof(DynamicalSystemsBase.Systems.doublependulum_rule), Vector{Float64}, DynamicalSystemsBase.var"#9#15"{typeof(DynamicalSystemsBase.Systems.doublependulum_rule)}, SMatrix{4, 4, Float64, 16}, true}, u0s::Vector{SVector{4, Float64}}; transform::typeof(identity), idxs::Tuple{Int64, Int64}, tsidxs::Tuple{Int64, Int64}, colors::Vector{ColorTypes.RGBA{Float32}}, tail::Int64, lims::Nothing, diffeq::NamedTuple{(), Tuple{}}, plotkwargs::NamedTuple{(), Tuple{}}, m::Float64, total_span::Int64, linekwargs::NamedTuple{(:linewidth,), Tuple{Int64}}, ps::Nothing, pnames::Nothing, add_controls::Bool, steps_per_update::Int64, figure::NamedTuple{(:resolution,), Tuple{Tuple{Int64, Int64}}}, axis::NamedTuple{(), Tuple{}}, fade::Bool)
   @ InteractiveDynamics ~/.julia/packages/InteractiveDynamics/NHT8Y/src/chaos/trajanim.jl:134
 [8] top-level scope
   @ REPL[9]:1

Versions:

  [61744808] DynamicalSystems v2.3.0
  [e9467ef8] GLMakie v0.5.5
  [ec714cd0] InteractiveDynamics v0.21.3
subhajitbn commented 1 year ago

Facing the same problem with the lorenz attractor GUI. Is there any update?

Datseris commented 1 year ago

no updates yet but this is super easy to fix if someone wants to do a pr