BSON.jl icon indicating copy to clipboard operation
BSON.jl copied to clipboard

Problem Loading

Open chelseas opened this issue 3 years ago • 3 comments

I am trying to use BSON. I have some custom data types in my project so I thought I'd use the @MODULE_ option, but sadly both with and without, I get an error.

For example:

julia> BSON.load("run_data/run_11977.bson", @__MODULE__)
ERROR: UndefVarError: OrderedCollections not defined
Stacktrace:
  [1] (::BSON.var"#31#32")(m::Module, f::String)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:21
  [2] BottomRF
    @ ./reduce.jl:81 [inlined]
  [3] _foldl_impl(op::Base.BottomRF{BSON.var"#31#32"}, init::Module, itr::Vector{Any})
    @ Base ./reduce.jl:58
  [4] foldl_impl
    @ ./reduce.jl:48 [inlined]
  [5] mapfoldl_impl
    @ ./reduce.jl:44 [inlined]
  [6] _mapreduce_dim
    @ ./reducedim.jl:315 [inlined]
  [7] #mapreduce#672
    @ ./reducedim.jl:310 [inlined]
  [8] #reduce#674
    @ ./reducedim.jl:359 [inlined]
  [9] resolve(fs::Vector{Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:21
 [10] (::BSON.var"#35#36")(d::Dict{Symbol, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:64
 [11] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:80
 [12] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:93
 [13] (::BSON.var"#49#50")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:147
 [14] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:92
 [15] (::BSON.var"#45#46"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:133
 [16] iterate
    @ ./generator.jl:47 [inlined]
 [17] collect_to!(dest::Vector{Any}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}}, offs::Int64, st::Int64)
    @ Base ./array.jl:724
 [18] collect_to!(dest::Vector{Int64}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}}, offs::Int64, st::Int64)
    @ Base ./array.jl:732
 [19] collect_to_with_first!(dest::Vector{Int64}, v1::Int64, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}}, st::Int64)
    @ Base ./array.jl:702
 [20] _collect(c::Vector{Any}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
    @ Base ./array.jl:696
 [21] collect_similar(cont::Vector{Any}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}})
    @ Base ./array.jl:606
 [22] map(f::Function, A::Vector{Any})
    @ Base ./abstractarray.jl:2294
 [23] newstruct_raw(cache::IdDict{Any, Any}, T::Type, d::Dict{Symbol, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:133
 [24] (::BSON.var"#49#50")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:149
--- the last 11 lines are repeated 1 more time ---
 [36] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:92
 [37] (::BSON.var"#45#46"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:133
 [38] iterate
    @ ./generator.jl:47 [inlined]
 [39] _collect(c::Vector{Any}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
    @ Base ./array.jl:691
 [40] collect_similar(cont::Vector{Any}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}})
    @ Base ./array.jl:606
 [41] map(f::Function, A::Vector{Any})
    @ Base ./abstractarray.jl:2294
 [42] newstruct_raw(cache::IdDict{Any, Any}, T::Type, d::Dict{Symbol, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:133
 [43] (::BSON.var"#49#50")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:149
--- the last 8 lines are repeated 2 more times ---
 [60] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:92
 [61] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:98
 [62] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:28
 [63] raise_recursive
    @ ~/.julia/packages/BSON/N216E/src/read.jl:98 [inlined]
 [64] (::BSON.var"#18#21"{IdDict{Any, Any}, Module})(x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:82
 [65] applychildren!(f::BSON.var"#18#21"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:21
 [66] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:82
 [67] (::BSON.var"#49#50")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:148
 [68] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:92
 [69] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:98
 [70] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:28
 [71] raise_recursive
    @ ~/.julia/packages/BSON/N216E/src/read.jl:98 [inlined]
--- the last 3 lines are repeated 1 more time ---
 [75] (::BSON.var"#18#21"{IdDict{Any, Any}, Module})(x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:82
 [76] applychildren!(f::BSON.var"#18#21"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:21
 [77] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:82
 [78] (::BSON.var"#49#50")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:148
 [79] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:92
 [80] (::BSON.var"#19#22"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:86
 [81] applychildren!(f::BSON.var"#19#22"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:21
 [82] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:86
 [83] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:93
 [84] raise_recursive
    @ ~/.julia/packages/BSON/N216E/src/read.jl:103 [inlined]
 [85] load(x::String, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:108
 [86] top-level scope
    @ REPL[6]:1

Any help? 🥲

chelseas avatar Dec 16 '21 05:12 chelseas

Another fun message:

julia> BSON.load("run_data/run_78477.bson", Main)
ERROR: MethodError: no method matching (Dict{Symbol, Vector{T}} where T<:Real)(::Dict{Symbol, Any})
Stacktrace:
  [1] convert(#unused#::Type{Dict{Symbol, Vector{T}} where T<:Real}, x::Dict{Symbol, Any})
    @ Base ./abstractdict.jl:523
  [2] newstruct!(::OverApproximation, ::Symbol, ::Vector{Float64}, ::Dict{Symbol, Any}, ::Int64, ::Vector{Any}, ::Vector{Any}, ::Vector{Any}, ::Dict{Symbol, Any}, ::Int64, ::Float64)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:107
  [3] newstruct_raw(cache::IdDict{Any, Any}, T::Type, d::Dict{Symbol, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:134
  [4] (::BSON.var"#49#50")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:149
  [5] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:92
  [6] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:98
  [7] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:28
  [8] raise_recursive
    @ ~/.julia/packages/BSON/N216E/src/read.jl:98 [inlined]
  [9] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:98
 [10] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:28
 [11] raise_recursive
    @ ~/.julia/packages/BSON/N216E/src/read.jl:98 [inlined]
 [12] (::BSON.var"#45#46"{IdDict{Any, Any}, Module})(x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:133
 [13] iterate
    @ ./generator.jl:47 [inlined]
 [14] collect_to!(dest::Vector{Vector{Any}}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}}, offs::Int64, st::Int64)
    @ Base ./array.jl:724
 [15] collect_to_with_first!(dest::Vector{Vector{Any}}, v1::Vector{Any}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}}, st::Int64)
    @ Base ./array.jl:702
 [16] _collect(c::Vector{Any}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
    @ Base ./array.jl:696
 [17] collect_similar(cont::Vector{Any}, itr::Base.Generator{Vector{Any}, BSON.var"#45#46"{IdDict{Any, Any}, Module}})
    @ Base ./array.jl:606
 [18] map(f::Function, A::Vector{Any})
    @ Base ./abstractarray.jl:2294
 [19] newstruct_raw(cache::IdDict{Any, Any}, T::Type, d::Dict{Symbol, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:133
 [20] (::BSON.var"#49#50")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:149
 [21] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:92
 [22] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:98
 [23] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:28
 [24] raise_recursive
    @ ~/.julia/packages/BSON/N216E/src/read.jl:98 [inlined]
 [25] (::BSON.var"#18#21"{IdDict{Any, Any}, Module})(x::Vector{Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:82
 [26] applychildren!(f::BSON.var"#18#21"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:21
 [27] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:82
 [28] (::BSON.var"#49#50")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/extensions.jl:148
 [29] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:92
 [30] (::BSON.var"#19#22"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:86
 [31] applychildren!(f::BSON.var"#19#22"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON ~/.julia/packages/BSON/N216E/src/BSON.jl:21
 [32] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:86
 [33] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:93
 [34] raise_recursive
    @ ~/.julia/packages/BSON/N216E/src/read.jl:103 [inlined]
 [35] load(x::String, init::Module)
    @ BSON ~/.julia/packages/BSON/N216E/src/read.jl:108
 [36] top-level scope
    @ REPL[11]:1
 [37] top-level scope
    @ ~/.julia/packages/CUDA/YpW0k/src/initialization.jl:52

chelseas avatar Dec 16 '21 05:12 chelseas

Not quite sure about the second message. For the first, have you done using OrderedCollections before loading? If you are loading in the REPL, you don't need the @__MODULE__ code.

darsnack avatar Dec 16 '21 15:12 darsnack

Did you save some data structures in OrderedCollections.jl in run_data/run_11977.bson? If so, you may need to load OrderedCollections before this can work.

singularitti avatar Aug 25 '22 04:08 singularitti