Closed chelseas closed 8 months ago
Hey,
this is probably some kind of bug in the type reconstruction.
However, this reconstruction is only meant as a last resort, anyway.
Can you make sure to load JuMP
and MathOptInterface
. Data generated by those packages appears to be in the file but the packages are not loaded in your session.
┌ Warning: type JuMP.VariableRef does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/DcnTD/src/data/reconstructing_datatypes.jl:450
┌ Warning: type MathOptInterface.VariableIndex does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/DcnTD/src/data/reconstructing_datatypes.jl:450
Ok that does help. I have fewer error messages. I do still get this though:
julia> variable = Basic(:θ)
θ
julia> jldsave("test2.jld2"; variable)
julia> data = load("test2.jld2")
Dict{String, Any} with 1 entry:Error showing value of type Dict{String, Any}:
ERROR: Trying to print an uninitialized SymEngine Basic variable.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] toString(b::Basic)
@ SymEngine ~/.julia/packages/SymEngine/OE2Ff/src/display.jl:5
[3] show(io::IOContext{IOBuffer}, b::Basic)
@ SymEngine ~/.julia/packages/SymEngine/OE2Ff/src/display.jl:13
[4] sprint(f::Function, args::Basic; context::IOContext{Base.TTY}, sizehint::Int64)
@ Base ./strings/io.jl:103
[5] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, t::Dict{String, Any})
@ Base ./show.jl:111
[6] (::REPL.var"#38#39"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:220
[7] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:462
[8] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:213
[9] display(d::REPL.REPLDisplay, x::Any)
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:225
[10] display(x::Any)
@ Base.Multimedia ./multimedia.jl:328
[11] (::Media.var"#15#16"{Dict{String, Any}})()
@ Media ~/.julia/packages/Media/ItEPc/src/compat.jl:28
[12] hookless(f::Media.var"#15#16"{Dict{String, Any}})
@ Media ~/.julia/packages/Media/ItEPc/src/compat.jl:14
[13] render(#unused#::Media.NoDisplay, x::Dict{String, Any})
@ Media ~/.julia/packages/Media/ItEPc/src/compat.jl:27
[14] render(x::Dict{String, Any})
@ Media ~/.julia/packages/Media/ItEPc/src/system.jl:160
[15] display(#unused#::Media.DisplayHook, x::Dict{String, Any})
@ Media ~/.julia/packages/Media/ItEPc/src/compat.jl:9
[16] display(x::Any)
@ Base.Multimedia ./multimedia.jl:328
[17] #invokelatest#2
@ ./essentials.jl:708 [inlined]
[18] invokelatest
@ ./essentials.jl:706 [inlined]
[19] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:247
[20] (::REPL.var"#40#41"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:231
[21] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:462
[22] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:229
[23] (::REPL.var"#do_respond#61"{Bool, Bool, REPL.var"#72#82"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:798
[24] #invokelatest#2
@ ./essentials.jl:708 [inlined]
[25] invokelatest
@ ./essentials.jl:706 [inlined]
[26] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
@ REPL.LineEdit /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/LineEdit.jl:2441
[27] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
@ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:1126
[28] (::REPL.var"#44#49"{REPL.LineEditREPL, REPL.REPLBackendRef})()
@ REPL ./task.jl:411
Oh, I just had a look at SymEngine.jl
.
SymEngine.jl
is a wrapper around a C library and a SymEngine Basic variable
contains an actual memory pointer. It does not make sense to store such a variable in a file, since in a new session, the target memory of such a pointer no longer exists. (JLD2 tries anyway, and recreates the variable with NULL pointers. Hence the uninitialized
error)
If you don't care about the integrity of this symbolic variable / the lacking pointer, then it's all good. The above error was just related to the show
ing of the data. This happens after loading.
If this is not enough: Someone with sufficient knowledge of SymEngine
could potentially (?) implement
JLD2 specific custom serialization
methods to allow storing and loading of symbolic variables. However, I am not certain, if this is feasible, as I know too little about SymEngine
.
Cool! Makes sense why it would fail. I have gotten around this error by converting the Basic variables to Expr type before saving. The conversion between this and Basic is lossless, to my knowledge. Maybe that could be the basis of a custom JLD2 save method for SymEngine Basic variables/expressions?
On Tue, Dec 14, 2021, 11:35 PM JonasIsensee @.***> wrote:
Oh, I just had a look at SymEngine.jl.
SymEngine.jl is a wrapper around a C library and a SymEngine Basic variable contains an actual memory pointer. It does not make sense to store such a variable in a file, since in a new session, the target memory of such a pointer no longer exists. (JLD2 tries anyway, and recreates the variable with NULL pointers. Hence the uninitialized error)
If you don't care about the integrity of this symbolic variable / the lacking pointer, then it's all good. The above error was just related to the showing of the data. This happens after loading.
If this is not enough: Someone with sufficient knowledge of SymEngine could potentially (?) implement JLD2 specific custom serialization methods to allow storing and loading of symbolic variables. However, I am not certain, if this is feasible, as I know too little about SymEngine.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JuliaIO/JLD2.jl/issues/362#issuecomment-994427801, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRQXSSU4CWMID333H36CN3URBAMJANCNFSM5KAHCPLQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
That is great to hear!
If the authors of SymEngine
think this is a good idea, you could add the corresponding definitions to that library.
Also thank you again for this knowledge that the SymEngine Basic variables wrap a memory pointer! I have been having other memory issues (segfaults) when trying to parallelize my code and knowing that this might be the culprit has helped a lot!
@JonasIsensee, a SymEngine author here. We have a method in the C library to save a Basic
expression to a set of bytes and a method to recreate the object using that set of bytes. How can that be incorporated into JLD2.jl?
Hi @isuruf ! That shouldn't be too hard to do. Please have a look at https://juliaio.github.io/JLD2.jl/dev/customserialization/
What you would need to do is to define an appropriate julia struct that contains all the relevant info (e.g. SerializedBasic
), implement the conversion methods, and define
JLD2.writeas(::Type{Basic}) = SerializedBasic
somewhere inside SymEngine.jl
(possibly via requires, if you don't want to add JLD2 as a dependency)
After that, JLD2 would automatically call the conversion methods when saving and loading.
EDIT: Actually, you may not even need a dedicated struct. I think, this might also work, if you can convert your Basic
thing to a byte vector.
JLD2.writeas(::Type{Basic}) = Vector{UInt8}
Base.convert(::Type{Vector{UInt8}}, x::Basic) = convert_to_bytes(x)
Base.convert(::Type{Basic}, x::Vector{UInt8}) = convert_from_bytes(x)
This is my error message....can any kind soul help?