Error loading model parameters with BSON

I’m running into an error when trying to load saved model parameters using BSON. I am saving the model parameters with

@save model_path model_params_save

and then trying to load them as per the examples with

@load model_path model_params_loaded

but when I do so I get an error:

ERROR: UndefVarError: ComponentArrays not defined
Stacktrace:
  [1] (::BSON.var"#31#32")(m::Module, f::String)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\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:362 [inlined]
  [7] #mapreduce#765
    @ .\reducedim.jl:357 [inlined]
  [8] #reduce#767
    @ .\reducedim.jl:406 [inlined]
  [9] resolve(fs::Vector{Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\extensions.jl:21
 [10] (::BSON.var"#35#36")(d::Dict{Symbol, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\extensions.jl:64
 [11] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:80
 [12] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:93
 [13] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:98
 [14] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\BSON.jl:26
 [15] raise_recursive
    @ C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:98 [inlined]
 [16] (::BSON.var"#17#20"{IdDict{Any, Any}, Module})(x::Vector{Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:80
 [17] applychildren!(f::BSON.var"#17#20"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\BSON.jl:19
--- the last 7 lines are repeated 2 more times ---
 [32] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:80
 [33] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:93
 [34] (::BSON.var"#49#50")(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\extensions.jl:167
 [35] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:92
 [36] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:98
 [37] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\BSON.jl:26
 [38] raise_recursive
    @ C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:98 [inlined]
 [39] (::BSON.var"#17#20"{IdDict{Any, Any}, Module})(x::Vector{Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:80
 [40] applychildren!(f::BSON.var"#17#20"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\BSON.jl:19
 [41] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:80
 [42] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:93
--- the last 7 lines are repeated 2 more times ---
 [57] (::BSON.var"#18#21"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:82
 [58] applychildren!(f::BSON.var"#18#21"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\BSON.jl:19
 [59] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:82
 [60] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:93
 [61] (::BSON.var"#17#20"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:80
 [62] applychildren!(f::BSON.var"#17#20"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\BSON.jl:19
 [63] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:80
 [64] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:93
 [65] (::BSON.var"#23#24"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:98
 [66] applychildren!(f::BSON.var"#23#24"{IdDict{Any, Any}, Module}, x::Vector{Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\BSON.jl:26
 [67] raise_recursive
    @ C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:98 [inlined]
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:92
 [81] (::BSON.var"#19#22"{IdDict{Any, Any}, Module})(x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:86
 [82] applychildren!(f::BSON.var"#19#22"{IdDict{Any, Any}, Module}, x::Dict{Symbol, Any})
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\BSON.jl:19
 [83] _raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:86
 [84] raise_recursive(d::Dict{Symbol, Any}, cache::IdDict{Any, Any}, init::Module)
    @ BSON C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:93
 [85] raise_recursive
    @ C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:103 [inlined]
 [86] load (repeats 2 times)
    @ C:\Users\Stefan\.julia\packages\BSON\73cTU\src\read.jl:108 [inlined]
 [87] macro expansion
    @ C:\Users\Stefan\.julia\packages\BSON\73cTU\src\BSON.jl:50 [inlined]
 [88] UDE_tests(model_name::String, val_df::DataFrames.SubDataFrame{DataFrames.DataFrame, DataFrames.Index, Vector{Int64}}, par::ComponentArrays.ComponentVector{Float32, Vector{Float32}, Tuple{ComponentArrays.Axis{(ωn = 1, μ = 2, b = 3, ν = 4, ρ = 5, ω = 6, A = 7, B = 8, ugain = 9)}}})
    @ Main.EnergyHarvesterModel c:\Users\Stefan\VScode projects\EnergyHarvester\src\models\UDEModel.jl:167

It is saying that I haven’t defined ComponentArrays but I have using ComponentArrays at the top of my file. What am I doing wrong here?
Thanks.

Excluding this problem, are you sure “@load model_path model_params_loaded” is what you expect?

I guess you need “@load model_path model_params_save”, because the bson file you save maybe doesn’t contain the key named “model_params_loaded”.