dojo-sim / Dojo.jl

A differentiable physics engine for robotics
MIT License
297 stars 26 forks source link

Call to simulate fails with MethodError (lu on 6x6 SMatrix is ambiguous) #13

Closed stephane-caron closed 2 years ago

stephane-caron commented 2 years ago

Running Julia 1.7.2 with Dojo v0.1.0, the first steps of the example from Defining a Simulation work so far:

using Dojo
timestep=0.01
gravity=0.0
mech = get_mechanism(:dzhanibekov, timestep=timestep, gravity=gravity);
initialize!(mech, :dzhanibekov, angular_velocity=[15.0; 0.01; 0.0])

But next the simulation fails with the following error:

julia> storage = simulate!(mech, 5.0, record=true, verbose=false)
ERROR: MethodError: lu(::StaticArrays.SMatrix{6, 6, Float64, 36}, ::Val{true}) is ambiguous. Candidates:
  lu(A::AbstractMatrix, ::Val{true}; check) in LinearAlgebra at deprecated.jl:70
  lu(A::StaticArrays.StaticMatrix{N, N}, pivot::Union{Val{false}, Val{true}}; check) where N in StaticArrays at ~/.julia/packages/StaticArrays/LJQEe/src/lu.jl:40
  lu(A::StaticArrays.StaticMatrix, pivot::Union{Val{false}, Val{true}}; check) in StaticArrays at ~/.julia/packages/StaticArrays/LJQEe/src/lu.jl:33
Possible fix, define
  lu(::StaticArrays.StaticMatrix{N, N}, ::Val{true}) where N
Stacktrace:
  [1] lu(A::StaticArrays.SMatrix{6, 6, Float64, 36})
    @ StaticArrays ~/.julia/packages/StaticArrays/LJQEe/src/lu.jl:42
  [2] macro expansion
    @ ~/.julia/packages/StaticArrays/LJQEe/src/inv.jl:77 [inlined]
  [3] _inv
    @ ~/.julia/packages/StaticArrays/LJQEe/src/inv.jl:72 [inlined]
  [4] inv
    @ ~/.julia/packages/StaticArrays/LJQEe/src/inv.jl:5 [inlined]
  [5] ldu_factorization_acyclic!(diagonal_v::Dojo.Entry{StaticArrays.SMatrix{6, 6, Float64, 36}}, offdiagonal_l::Dojo.Entry{StaticArrays.SMatrix{6, 6, Float64, 36}}, diagonal_c::Dojo.Entry{StaticArrays.SMatrix{6, 6, Float64, 36}}, offdiagonal_u::Dojo.Entry{StaticArrays.SMatrix{6, 6, Float64, 36}}, diagonal_inverse_c::Dojo.Entry{StaticArrays.SMatrix{6, 6, Float64, 36}})
    @ Dojo ~/.julia/packages/Dojo/wc2gJ/src/graph/ldu_factorization.jl:6
  [6] ldu_factorization!(system::Dojo.System{4})
    @ Dojo ~/.julia/packages/Dojo/wc2gJ/src/graph/ldu_factorization.jl:38
  [7] mehrotra!(mechanism::Mechanism{Float64, 4, 2, 2, 0}; opts::SolverOptions{Float64})
    @ Dojo ~/.julia/packages/Dojo/wc2gJ/src/solver/mehrotra.jl:36
  [8] simulate!(mechanism::Mechanism{Float64, 4, 2, 2, 0}, steps::Base.OneTo{Int64}, storage::Dojo.Storage{Float64, 500}, control!::Dojo.var"#180#182"; record::Bool, verbose::Bool, abort_upon_failure::Bool, opts::SolverOptions{Float64})
    @ Dojo ~/.julia/packages/Dojo/wc2gJ/src/simulation/simulate.jl:28
  [9] simulate!(::Mechanism{Float64, 4, 2, 2, 0}, ::Float64; record::Bool, verbose::Bool, abort_upon_failure::Bool, opts::SolverOptions{Float64})
    @ Dojo ~/.julia/packages/Dojo/wc2gJ/src/simulation/simulate.jl:46
 [10] top-level scope
    @ REPL[6]:1

This error looks similar to https://github.com/JuliaArrays/StaticArrays.jl/issues/920. Perhaps the version of StaticArrays used by Dojo (0.12.5) is not up-to-date?

NB: this only happens when Dojo is installed by add Dojo. The error does not appear when installing by add Dojo#main. (In both cases the version number is 0.1.0.)

thowell commented 2 years ago

Interesting... I think this is because v0.1.0 was tested with Julia v1.6.2. We just updated StaticArrays and to Julia v1.7.2 so this (lu) should be fixed on main branch. Will push a new version (0.1.1) to general registry by end of day.

simon-lc commented 2 years ago

@stephane-caron This issue has been fixed in version 0.2.0 that @thowell pushed to the general registry this morning.