I am using createSim.jl to save an instance Sim of structure Simulation in .jld2 file, and readSim.jl to read this instance. However, I am having reconstructing. How to solve it please? createSim.jl is:
using JLD2
Base.@kwdef mutable struct Simulation
dt::Float64 = 1e-6
tmax::Float64 = 32*1e-3
end
Sim = Simulation(2,4);
save("$(@__DIR__)/generatedElements.jld2", "Sim", Sim)
readSim.jl
module test
using JLD2
Base.@kwdef mutable struct Simulation
dt::Float64 = 1e-6
tmax::Float64 = 32*1e-3
end
function readJLD()
Sim = load("$(@__DIR__)/generatedElements.jld2", "Sim")
return Sim
end
Sim = readJLD()
end
┌ Warning: type Main.Simulation does not exist in workspace; reconstructing
â”” @ JLD2 C:\Users\amroa\.julia\packages\JLD2\k9Gt0\src\data\reconstructing_datatypes.jl:461
julia> test.Sim
JLD2.ReconstructedTypes.var"##Main.Simulation#292"(2.0, 4.0)
With that you are just wasting my (and others) time to trying to help you. If you don’t get immediate answers just consider that people who already answered your question may have a different time zone and just went to bed for some time or have other things to do.
Please consider this for the future.
Dear @oheil I am sorry for this. You get me wrong or maybe I was naive in my thoughts.
In the previous one, it saving from module into .jld2 and here is the opposite. I tried by myself many times based on your help previously, but failed and I was a shy to be blamed that I am not able to solve similar issue reversely.
I am sorry again if this is improper and I can delete it here if this can solve the issue. Moreover, thanks for your note which can guide me and make posting in the community more professional. I will not do this again.
When changing the location of a struct definition, it is easiest to
tell JLD2 explicitly where to find it.
Here: Load saved type “Main.Simulation” as the new Simulation struct.