Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization of empty julia containers forgets type parameters #3983

Open
lgoettgens opened this issue Jul 30, 2024 · 0 comments
Open

Serialization of empty julia containers forgets type parameters #3983

lgoettgens opened this issue Jul 30, 2024 · 0 comments
Labels
bug Something isn't working serialization

Comments

@lgoettgens
Copy link
Member

Describe the bug
Consider an empty vector of type Vector{Foo{Bar}}, i.e. the eltype of the vector itself has a type parameter. If I save this vector, and load it again (it does not matter if loading happens in the same session or a new one), it will be the empty vector of type Vector{Foo}.
In particular, running test_save_load_rountrip from https://github.com/oscar-system/Oscar.jl/blob/master/test/Serialization/setup_tests.jl with such a vector fails.
The same problem arises for 0x0 matrices and empty dicts instead of vectors

To Reproduce
Steps to reproduce the behavior, please provide a code snippet that triggers
the bug.

using Oscar, Test

x1 = Vector{Vector{Int}}() # empty vector
save("tmp.mrdi", x1)
x2 = load("tmp.mrdi")
@test x2 isa typeof(x1)

using JSONSchema
include("test/Serialization/setup_tests.jl")
mktempdir() do path
  test_save_load_roundtrip(path, x1) do loaded
    # nothing here
  end
end

the same problem arises for e.g.
x1 = Vector{MPolyRingElem{QQFieldElem}}()
x1 = Dict{MPolyRingElem{QQFieldElem}, Int}()
x1 = Dict{Int, MPolyRingElem{QQFieldElem}}()

For the following two empty containers, even trying to load raises a KeyError.
x1 = Matrix{QQMatrix}(undef, 0, 0) (will no longer error but still have the problem once #3980 is merged)
x1 = Dict{QQMatrix, Int}()
x1 = Dict{Int, QQMatrix}()

Expected behavior
All of the above containers should remember its eltype when saving and loading, as they already do if they contain some elements.

System (please complete the following information):

julia> Oscar.versioninfo(full=true)
OSCAR version 1.2.0-DEV - #master, bfcfee360a -- 2024-07-28 10:10:11 +0000
  combining:
    AbstractAlgebra.jl   v0.42.0
    GAP.jl               v0.10.4
    Hecke.jl             v0.33.0
    Nemo.jl              v0.46.0
    Polymake.jl          v0.11.19
    Singular.jl          v0.23.4
  building on:
    FLINT_jll               v300.100.300+0
    GAP_jll                 v400.1200.200+9
    Singular_jll            v404.0.301+0
    libpolymake_julia_jll   v0.12.0+0
    libsingular_julia_jll   v0.45.2+0
    polymake_jll            v400.1200.1+0
See `]st -m` for a full list of dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working serialization
Projects
None yet
Development

No branches or pull requests

1 participant