Reconstructing warning when dealing with Module?

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)

this is a guess but

as the error message says

type Main.Simulation does not exist in workspace

module test

export Simulation

might fix it

2 Likes

Ok, you opened a new thread with the same issue you already asked here How to save a structure instance (inside module) in JLD2, to load it later correctly?

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.

julia> Sim = load("$(@__DIR__)/generatedElements.jld2"; typemap=Dict("Main.Simulation" => Simulation))

Please take a look at the documentation of JLD2
and in particular at Advanced Usage · Julia Data Format

load returns a Dict of all objects stored in the file.

data = load("$(@__DIR__)/generatedElements.jld2"; typemap=Dict("Main.Simulation" => Simulation))
Sim = data["Sim"]
1 Like