Closed koehlerson closed 2 years ago
Hi @koehlerson,
this is a neat little bug you found there.
Dictionaries with their hash tables and all that use CustomSerialization themselves to store the data as a Vector{Pair{K,V}}
.
Two things are going wrong at the same time here:
In your case, what is happening is that JLD2 seemingly cannot directly nest this CustomSerialization
.
This means, JLD2 will indeed attempt to actually serialize all the hash-tables. (This surprisingly works....)
When loading, you see a second error. The object is cached prior to conversion. In principle, this could probably be fixed but there are also easy workarounds. There are plausible workarounds:
Vector{Any})
or Vector{Pair}
)
julia> struct TestStruct
x::Int
y::Float64
end
julia> struct SerializedTestStruct d::Dict{String,Any} end
julia> JLD2.rconvert(::Type{TestStruct}, x::SerializedTestStruct) = TestStruct(x.d["x"], x.d["y"])
julia> JLD2.wconvert(::Type{SerializedTestStruct}, x::TestStruct) = SerializedTestStruct(Dict{String,Any}("x"=>x.x, "y"=>x.y))
julia> JLD2.writeas(::Type{TestStruct}) = SerializedTestStruct
cool! thank you very much for the quick response. I thought about having a wrapper struct in the beginning but then I decided to remove it since it seemed unnecessary (which it isn't obviously :D). Your MWE transfered to my use case:
julia> file = jldopen("data/simulations/test/hyperelastic-demo/NeoHooke_λ=5.769230769230769_μ=3.846153846153846_nele=1000_quadorder=2_NewtonSolver_restol-1.0e-8_dtol-1.0e-8_linsolve-cg_hyperdemo.jld2")
JLDFile /Datadisk/repos/convexified-damage/data/simulations/test/hyperelastic-demo/NeoHooke_λ=5.769230769230769_μ=3.846153846153846_nele=1000_quadorder=2_NewtonSolver_restol-1.0e-8_dtol-1.0e-8_linsolve-cg_hyperdemo.jld2 (read-only)
├─🔢 model
├─📂 t=0.1
│ ├─🔢 d
│ ├─🔢 reaction
│ └─🔢 materialstate
├─📂 t=0.2
│ ├─🔢 d
│ ├─🔢 reaction
│ └─🔢 materialstate
└─ ⋯ (3 more entries)
julia> file["model"]
┌ Warning: standard reconstruction of struct of type: NeumannBC
└ @ ConvexDamage /Datadisk/repos/convexified-damage/src/solver.jl:843
┌ Warning: standard reconstruction of struct of type: NewtonSolver
└ @ ConvexDamage /Datadisk/repos/convexified-damage/src/solver.jl:843
┌ Warning: standard reconstruction of struct of type: Grid
└ @ ConvexDamage /Datadisk/repos/convexified-damage/src/solver.jl:843
FE Model
julia> file["model"]
┌ Warning: standard reconstruction of struct of type: NeumannBC
└ @ ConvexDamage /Datadisk/repos/convexified-damage/src/solver.jl:843
┌ Warning: standard reconstruction of struct of type: NewtonSolver
└ @ ConvexDamage /Datadisk/repos/convexified-damage/src/solver.jl:843
┌ Warning: standard reconstruction of struct of type: Grid
└ @ ConvexDamage /Datadisk/repos/convexified-damage/src/solver.jl:843
FE Model
Do you think it's worth to add your explanations to the docs? I can take care of it, if you want to.
Do you think it's worth to add your explanations to the docs? I can take care of it, if you want to.
Yes, that would be great.
Alright, I'll add it to https://github.com/JuliaIO/JLD2.jl/pull/407
Hey, I'm using the new functionality to store a custom serialization. I have some type, called
StructuralModel
, that stores everything related to a solid mechanics PDE discretization. Now I dispatchedrconvert,wconvert
andwriteas
such that I store on disk instead of my custom type aDict
because aDict
is more stable to its definition than my type that can change from time to time.In general it works, however when I read in the
StructuralModel
a second time, I get instead of theStructuralModel
it'sDict
disk representation:Is this bug within my code or something related to the new custom serialization?