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

Error related to @autodiff and DiscretizedDynamics() #76

Closed
jbwillis opened this issue Aug 3, 2022 · 3 comments
Closed

Error related to @autodiff and DiscretizedDynamics() #76

jbwillis opened this issue Aug 3, 2022 · 3 comments
Assignees

Comments

@jbwillis
Copy link
Contributor

jbwillis commented Aug 3, 2022

There seems to have been something in a recent package update that is breaking the Quickstart (and my code). I’ve found that my older code works as long as I don’t run Pkg.update() but after I update I get an error. The error seems to be related to the @autodiff stuff when I try to create a discretized model. (also happens when calling Problem() on a continuous model, but this is an mwe).

The following mwe is basically two steps:

  1. create a new Julia environment and add RobotDynamics StaticArrays TrajectoryOptimization LinearAlgebra Test
  2. Copy + Paste Steps 1 and 2 from http://roboticexplorationlab.org/TrajectoryOptimization.jl/v0.7/quickstart.html#quickstart_page
❯ julia6
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.5 (2021-12-19)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.6) pkg> activate .
  Activating new environment at `~/scratch/trajopt_quickstart_issue/Project.toml`

(trajopt_quickstart_issue) pkg> add RobotDynamics StaticArrays TrajectoryOptimization LinearAlgebra Test
    Updating registry at `~/.julia/registries/General`
   Resolving package versions...
    Updating `~/scratch/trajopt_quickstart_issue/Project.toml`
  [38ceca67] + RobotDynamics v0.4.6
  [90137ffa] + StaticArrays v1.5.2
  [c79d492b] + TrajectoryOptimization v0.7.0
  [37e2e46d] + LinearAlgebra
  [8dfed614] + Test
    Updating `~/scratch/trajopt_quickstart_issue/Manifest.toml`
  [30b0a656] + ArrayInterfaceCore v0.1.17
  [d360d2e6] + ChainRulesCore v1.15.3
  [9e997f8a] + ChangesOfVariables v0.1.4
  [bbf7d656] + CommonSubexpressions v0.3.0
  [34da2185] + Compat v4.1.0
  [187b0558] + ConstructionBase v1.4.0
  [163ba53b] + DiffResults v1.0.3
  [b552c78f] + DiffRules v1.11.0
  [ffbed154] + DocStringExtensions v0.8.6
  [6a86dc24] + FiniteDiff v2.14.0
  [f6369f11] + ForwardDiff v0.10.30
  [3587e190] + InverseFunctions v0.1.7
  [92d709cd] + IrrationalConstants v0.1.1
  [692b3bcd] + JLLWrappers v1.4.1
  [2ab3a3ac] + LogExpFunctions v0.3.17
  [1914dd2f] + MacroTools v0.5.9
  [77ba4419] + NaNMath v1.0.1
  [21216c6a] + Preferences v1.3.0
  [3cdcf5f2] + RecipesBase v1.2.1
  [ae029012] + Requires v1.3.0
  [38ceca67] + RobotDynamics v0.4.6
  [74be38bb] + RobotZoo v0.3.1
  [6038ab10] + Rotations v1.0.4
  [efcf1570] + Setfield v1.0.0
  [276daf66] + SpecialFunctions v2.1.7
  [90137ffa] + StaticArrays v1.5.2
  [1e83bf80] + StaticArraysCore v1.0.1
  [c79d492b] + TrajectoryOptimization v0.7.0
  [efe28fd5] + OpenSpecFun_jll v0.5.5+0
  [0dad84c5] + ArgTools
  [56f22d72] + Artifacts
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [f43a241f] + Downloads
  [9fa8497b] + Future
  [b77e0a4c] + InteractiveUtils
  [b27032c2] + LibCURL
  [76f85450] + LibGit2
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [ca575930] + NetworkOptions
  [44cfe95a] + Pkg
  [de0858da] + Printf
  [3fa0cd96] + REPL
  [9a3f8284] + Random
  [ea8e919c] + SHA
  [9e88b42a] + Serialization
  [6462fe0b] + Sockets
  [2f01184e] + SparseArrays
  [10745b16] + Statistics
  [4607b0f0] + SuiteSparse
  [fa267f1f] + TOML
  [a4e569a6] + Tar
  [8dfed614] + Test
  [cf7118a7] + UUIDs
  [4ec0a83e] + Unicode
  [e66e0078] + CompilerSupportLibraries_jll
  [deac9b47] + LibCURL_jll
  [29816b5a] + LibSSH2_jll
  [c8ffd9c3] + MbedTLS_jll
  [14a3606d] + MozillaCACerts_jll
  [05823500] + OpenLibm_jll
  [83775a58] + Zlib_jll
  [8e850ede] + nghttp2_jll
  [3f19e933] + p7zip_jll

julia> using TrajectoryOptimization

julia> using RobotDynamics

julia> using StaticArrays

julia> using LinearAlgebra

julia> using RobotDynamics

julia> using Test

julia> const TO = TrajectoryOptimization
TrajectoryOptimization

julia> const RD = RobotDynamics
RobotDynamics

julia> ## Model Definition
       struct DoubleIntegrator{T} <: RD.ContinuousDynamics 
           mass::T
       end

julia> function RD.dynamics(model::DoubleIntegrator, x, u)
           mass = model.mass
           vx,vy = x[3], x[4]
           ax,ay = u[1] / mass, u[2] / mass
           SA[vx, vy, ax, ay]
       end

julia> RD.state_dim(::DoubleIntegrator) = 4

julia> RD.control_dim(::DoubleIntegrator) = 2

julia> model = DoubleIntegrator(1.0)
DoubleIntegrator{Float64}(1.0)

julia> dmodel = RD.DiscretizedDynamics{RD.RK4}(model)
ERROR: MethodError: Cannot `convert` an object of type 
  FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64} to an object of type 
  FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64, returntype} where returntype
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:205
Stacktrace:
 [1] RobotDynamics.DiscretizedDynamics(continuous_dynamics::DoubleIntegrator{Float64}, integrator::RobotDynamics.RK4)
   @ RobotDynamics ~/.julia/packages/RobotDynamics/xW4Xp/src/discretized_dynamics.jl:763
 [2] (RobotDynamics.DiscretizedDynamics{RobotDynamics.RK4, Q, JCH} where {Q, JCH})(continuous_dynamics::DoubleIntegrator{Float64})
   @ RobotDynamics ~/.julia/packages/RobotDynamics/xW4Xp/src/discretized_dynamics.jl:183
 [3] top-level scope
   @ REPL[16]:1
@jbwillis
Copy link
Contributor Author

jbwillis commented Aug 3, 2022

Did more digging, this seems to be due to a change in FiniteDiff.jl. I don't get this error with version v2.11.0 but I do get the error with v2.14.0.

@bjack205
Copy link
Member

bjack205 commented Aug 4, 2022

Fixed by this PR in RobotDynamics.

Works with the latest version of RobotDynamics (v0.4.7).

@bjack205 bjack205 closed this as completed Aug 4, 2022
@SkylerHawkins
Copy link

Hello, I'm just now getting into this library and I'm having this same issue when trying to run the examples such as Cartpole and Quadrotor. I think the compats may be outdated, can anyone give me their compats so I can replicate without running into this FiniteDiff error?

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

No branches or pull requests

3 participants