dojo-sim / Dojo.jl

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

Try fixing sysid example #30

Closed rejuvyesh closed 1 year ago

rejuvyesh commented 2 years ago

I can' figure out where ω_finite_difference is defined (or what's the equivalent function now)?

Current error:

ERROR: LoadError: UndefVarError: ω_finite_difference not defined
Stacktrace:
 [1] toss2z(toss::Vector{Vector{Float64}}, timestep::Float64; s::Int64)
   @ Main ~/.julia/dev/Dojo/examples/system_identification/data/data.jl:36
 [2] generate_hardware_dataset(; N::Int64, sleep_ratio::Float64, show_contact::Bool, s::Int64)
   @ Main ~/.julia/dev/Dojo/examples/system_identification/data/data.jl:75
 [3] top-level scope
   @ ~/.julia/dev/Dojo/examples/system_identification/methods/data_processing.jl:44
codecov-commenter commented 2 years ago

Codecov Report

Merging #30 (1734ce5) into main (1c87f5c) will decrease coverage by 43.63%. The diff coverage is n/a.

:exclamation: Current head 1734ce5 differs from pull request most recent head 17117b7. Consider uploading reports for the commit 17117b7 to get more accurate results

@@             Coverage Diff             @@
##             main      #30       +/-   ##
===========================================
- Coverage   91.73%   48.10%   -43.64%     
===========================================
  Files          87       94        +7     
  Lines        4477     4958      +481     
===========================================
- Hits         4107     2385     -1722     
- Misses        370     2573     +2203     
Impacted Files Coverage Δ
src/contacts/linear.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/mechanics/energy.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/mechanics/momentum.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/graph/linear_system.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/simulation/simulate.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/joints/rotational/impulses.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/gradients/finite_difference.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/joints/translational/impulses.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/contacts/collisions/sphere_sphere.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/contacts/collisions/collision.jl 0.00% <0.00%> (-98.77%) :arrow_down:
... and 77 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1c87f5c...17117b7. Read the comment docs.

simon-lc commented 2 years ago

Hi Jayesh, sorry for this, the function has been renamed angular_velocity. I pushed the modification to main, hopefully this helps!

rejuvyesh commented 2 years ago

Thanks for the update. I tried making some more fixes. Now I think the issue is with the data itself which was created when you were using Rotations.jl rather than Quaternions.jl:

┌ Warning: saved type Rotations.QuatRotation{Float64} is missing field q in workspace type; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/data/reconstructing_datatypes.jl:152
ERROR: LoadError: MethodError: Cannot `convert` an object of type JLD2.ReconstructedTypes.var"##Rotations.QuatRotation{Float64}#296" to an object of type Quaternions.QuaternionF64
Closest candidates are:
  convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at ~/.julia/juliaup/julia-1.7.2+0~x64/share/julia/base/twiceprecision.jl:262
  convert(::Type{T}, ::AbstractChar) where T<:Number at ~/.julia/juliaup/julia-1.7.2+0~x64/share/julia/base/char.jl:185
  convert(::Type{T}, ::CartesianIndex{1}) where T<:Number at ~/.julia/juliaup/julia-1.7.2+0~x64/share/julia/base/multidimensional.jl:136
  ...
Stacktrace:
  [1] setindex!(A::Vector{Quaternions.QuaternionF64}, x::JLD2.ReconstructedTypes.var"##Rotations.QuatRotation{Float64}#296", i1::Int64)
    @ Base ./array.jl:903
  [2] _unsafe_copyto!(dest::Vector{Quaternions.QuaternionF64}, doffs::Int64, src::Vector{JLD2.ReconstructedTypes.var"##Rotations.QuatRotation{Float64}#296"}, soffs::Int64, n::Int64)
    @ Base ./array.jl:253
  [3] unsafe_copyto!
    @ ./array.jl:307 [inlined]
  [4] _copyto_impl!
    @ ./array.jl:331 [inlined]
  [5] copyto!
    @ ./array.jl:317 [inlined]
  [6] copyto!
    @ ./array.jl:343 [inlined]
  [7] copyto_axcheck!
    @ ./abstractarray.jl:1104 [inlined]
  [8] Vector{Quaternions.QuaternionF64}(x::Vector{JLD2.ReconstructedTypes.var"##Rotations.QuatRotation{Float64}#296"})
    @ Base ./array.jl:563
  [9] convert
    @ ./array.jl:554 [inlined]
 [10] setindex!
    @ ./array.jl:903 [inlined]
 [11] _unsafe_copyto!(dest::Vector{Vector{Quaternions.QuaternionF64}}, doffs::Int64, src::Vector{Vector{JLD2.ReconstructedTypes.var"##Rotations.QuatRotation{Float64}#296"}}, soffs::Int64, n::Int64)
    @ Base ./array.jl:253
 [12] unsafe_copyto!
    @ ./array.jl:307 [inlined]
 [13] _copyto_impl!
    @ ./array.jl:331 [inlined]
 [14] copyto!
    @ ./array.jl:317 [inlined]
 [15] copyto!
    @ ./array.jl:343 [inlined]
 [16] copyto_axcheck!
    @ ./abstractarray.jl:1104 [inlined]
 [17] Vector{Vector{Quaternions.QuaternionF64}}(x::Vector{Vector{JLD2.ReconstructedTypes.var"##Rotations.QuatRotation{Float64}#296"}})
    @ Base ./array.jl:563
 [18] convert(#unused#::Type{Vector{Vector{Quaternions.QuaternionF64}}}, a::Vector{Vector{JLD2.ReconstructedTypes.var"##Rotations.QuatRotation{Float64}#296"}})
    @ Base ./array.jl:554
 [19] rconvert(T::Type, x::Vector{Vector{JLD2.ReconstructedTypes.var"##Rotations.QuatRotation{Float64}#296"}})
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/data/custom_serialization.jl:10
 [20] jlconvert
    @ ~/.julia/packages/JLD2/k9Gt0/src/data/writing_datatypes.jl:305 [inlined]
 [21] macro expansion
    @ ~/.julia/packages/JLD2/k9Gt0/src/data/reconstructing_datatypes.jl:589 [inlined]
 [22] jlconvert(#unused#::JLD2.ReadRepresentation{Storage{Float64, 14}, JLD2.OnDiskRepresentation{(0, 8, 16, 24, 32, 40, 48, 56), Tuple{Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{Quaternions.QuaternionF64}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}}, NTuple{8, JLD2.RelOffset}}()}, f::JLD2.JLDFile{JLD2.MmapIO}, ptr::Ptr{Nothing}, header_offset::JLD2.RelOffset)
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/data/reconstructing_datatypes.jl:513
 [23] read_scalar(f::JLD2.JLDFile{JLD2.MmapIO}, rr::JLD2.ReadRepresentation{Storage{Float64, 14}, JLD2.OnDiskRepresentation{(0, 8, 16, 24, 32, 40, 48, 56), Tuple{Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{Quaternions.QuaternionF64}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}, Vector{Vector{StaticArrays.SVector{3, Float64}}}}, NTuple{8, JLD2.RelOffset}}()}, header_offset::JLD2.RelOffset)
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/dataio.jl:37
 [24] read_data(f::JLD2.JLDFile{JLD2.MmapIO}, rr::Any, read_dataspace::Tuple{JLD2.ReadDataspace, JLD2.RelOffset, Int64, UInt16}, attributes::Vector{JLD2.ReadAttribute})
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/datasets.jl:170
 [25] read_data(f::JLD2.JLDFile{JLD2.MmapIO}, dataspace::JLD2.ReadDataspace, datatype_class::UInt8, datatype_offset::Int64, data_offset::Int64, data_length::Int64, filter_id::UInt16, header_offset::JLD2.RelOffset, attributes::Vector{JLD2.ReadAttribute})
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/datasets.jl:149
 [26] load_dataset(f::JLD2.JLDFile{JLD2.MmapIO}, offset::JLD2.RelOffset)
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/datasets.jl:92
 [27] jlconvert
    @ ~/.julia/packages/JLD2/k9Gt0/src/data/writing_datatypes.jl:304 [inlined]
 [28] macro expansion
    @ ~/.julia/packages/JLD2/k9Gt0/src/dataio.jl:70 [inlined]
 [29] macro expansion
    @ ./simdloop.jl:77 [inlined]
 [30] read_array!(v::Vector{Any}, f::JLD2.JLDFile{JLD2.MmapIO}, rr::JLD2.ReadRepresentation{Any, JLD2.RelOffset})
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/dataio.jl:68
 [31] read_array(f::JLD2.JLDFile{JLD2.MmapIO}, dataspace::JLD2.ReadDataspace, rr::JLD2.ReadRepresentation{Any, JLD2.RelOffset}, data_length::Int64, filter_id::UInt16, header_offset::JLD2.RelOffset, attributes::Vector{JLD2.ReadAttribute})
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/datasets.jl:329
 [32] read_data(f::JLD2.JLDFile{JLD2.MmapIO}, rr::JLD2.ReadRepresentation{Any, JLD2.RelOffset}, read_dataspace::Tuple{JLD2.ReadDataspace, JLD2.RelOffset, Int64, UInt16}, attributes::Vector{JLD2.ReadAttribute})
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/datasets.jl:200
 [33] macro expansion
    @ ~/.julia/packages/JLD2/k9Gt0/src/datasets.jl:156 [inlined]
 [34] macro expansion
    @ ~/.julia/packages/JLD2/k9Gt0/src/datatypes.jl:76 [inlined]
 [35] read_data(f::JLD2.JLDFile{JLD2.MmapIO}, dataspace::JLD2.ReadDataspace, datatype_class::UInt8, datatype_offset::Int64, data_offset::Int64, data_length::Int64, filter_id::UInt16, header_offset::JLD2.RelOffset, attributes::Vector{JLD2.ReadAttribute})
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/datasets.jl:152
 [36] load_dataset(f::JLD2.JLDFile{JLD2.MmapIO}, offset::JLD2.RelOffset)
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/datasets.jl:92
 [37] getindex(g::JLD2.Group{JLD2.JLDFile{JLD2.MmapIO}}, name::String)
    @ JLD2 ~/.julia/packages/JLD2/k9Gt0/src/groups.jl:109
 [38] getindex
    @ ~/.julia/packages/JLD2/k9Gt0/src/JLD2.jl:393 [inlined]
 [39] open_dataset(model::Symbol; kwargs::Base.Pairs{Symbol, Int64, Tuple{Symbol, Symbol}, NamedTuple{(:N, :s), Tuple{Int64, Int64}}})
    @ Main ~/.julia/dev/Dojo/examples/system_identification/methods/utils.jl:236
 [40] top-level scope
    @ ~/.julia/dev/Dojo/examples/system_identification/hardware_examples/visualization.jl:58
 [41] include(fname::String)
    @ Base.MainInclude ./client.jl:451
 [42] top-level scope
    @ ~/.julia/dev/Dojo/examples/system_identification/learning.jl:25
 [43] include(fname::String)
    @ Base.MainInclude ./client.jl:451
 [44] top-level scope
    @ REPL[5]:1
rejuvyesh commented 2 years ago

I think overall the changes here are still useful but would require your input to fully fix the issue. I would recommend reviewing the changes and merge if it makes sense (or just push your fixes to this branch directly), when you have the time to work on this.

simon-lc commented 2 years ago

Thanks Jayesh for looking into this! I'll try to build on top of your changes to fully fix the issue

simon-lc commented 2 years ago

Hello Jayesh, I've finally had some time to go through the System Identification examples. It was broken because all the changes we've made to Dojo/src. All the examples work now on the main branch.

https://github.com/dojo-sim/Dojo.jl/commit/1734ce57d6ea669a89826bbe86c4fdc993a19012

Here is a simple system identification demo on a 2D box: https://github.com/dojo-sim/Dojo.jl/blob/main/examples/system_identification/examples/synthetic/block2d.jl

janbruedigam commented 1 year ago

I would close this for now since there are again two working sysid examples, but feel free to reopen if there are changes you think make sense incorporating.