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: problem while saving a list of tuples of matrices with varying sizes #4567

Open
StevellM opened this issue Feb 10, 2025 · 2 comments · May be fixed by #4162
Open

Serialization: problem while saving a list of tuples of matrices with varying sizes #4567

StevellM opened this issue Feb 10, 2025 · 2 comments · May be fixed by #4162
Labels
bug Something isn't working serialization

Comments

@StevellM
Copy link
Member

Describe the bug
It seems that there is a bug while saving a list of tuples of matrices. In fact, it seems that saving or loading assumes wrong size of matrices which makes data unable to be loaded.

To Reproduce

using Oscar
julia> m = (matrix(QQ, 1, 1, [2]), matrix(QQ, 2, 2, [1//2 0; 0 1//2]))
([2], [1//2 0; 0 1//2])

julia> mm = [m, reverse(m)]
2-element Vector{Tuple{QQMatrix, QQMatrix}}:
 ([2], [1//2 0; 0 1//2])
 ([1//2 0; 0 1//2], [2])

julia> save("Schreibtisch/tmp.mrdi", mm)

julia> load("Schreibtisch/tmp.mrdi")
┌ Warning: Attempted loading file stored using a DEV version with commit 8fc7969f373c61cb9bab612fe608e89c9d2d7d0c
└ @ Oscar ~/.julia/dev/Oscar/src/Serialization/main.jl:712
ERROR: Expected dimension 1 x 1, got 2 x 2
Stacktrace:
  [1] _check_dim
    @ ~/.julia/packages/AbstractAlgebra/bL4Gd/src/Matrix.jl:46 [inlined]
  [2] _check_dim
    @ ~/.julia/packages/AbstractAlgebra/bL4Gd/src/Matrix.jl:44 [inlined]
  [3] (::MatSpace{QQFieldElem})(arr::Matrix{QQFieldElem})
    @ Nemo ~/.julia/packages/Nemo/E8ekQ/src/flint/fmpq_mat.jl:718
  [4] load_object(s::Oscar.DeserializerState{Oscar.JSONSerializer}, ::Type{MatElem}, parents::Vector{Union{Ring, FreeAssociativeAlgebra, MatSpace, SMatSpace}})
    @ Oscar ~/.julia/dev/Oscar/src/Serialization/Rings.jl:417
[...]
 [31] load(filename::String)
    @ Oscar ~/.julia/dev/Oscar/src/Serialization/main.jl:718
 [32] top-level scope
    @ REPL[13]:1
Some type information was truncated. Use `show(err)` to see complete types.

Expected behavior
Since we know how to serialize lists, tuples and matrices, I would expect to be able to serialize a list of tuples of matrices of various sizes.

System (please complete the following information):
Please paste the output of Oscar.versioninfo(full=true) below. If this does
not work, please paste the output of Julia's versioninfo() and your Oscar
version.

julia> Oscar.versioninfo(full=true)
OSCAR version 1.3.0-DEV - #main, 8fc7969f37 -- 2025-02-08 18:29:40 +0000
  combining:
    AbstractAlgebra.jl   v0.44.5
    GAP.jl               v0.13.1
    Hecke.jl             v0.35.9
    Nemo.jl              v0.48.2
    Polymake.jl          v0.11.25
    Singular.jl          v0.24.1
  building on:
    FLINT_jll               v300.100.301+0
    GAP_jll                 v400.1400.3+0
    Singular_jll            v404.1.700+0
    libpolymake_julia_jll   v0.13.1+0
    libsingular_julia_jll   v0.46.1+0
    polymake_jll            v400.1300.2+0
See `]st -m` for a full list of dependencies.

Julia Version 1.10.1
Commit 7790d6f0641 (2024-02-13 20:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Official https://julialang.org/ release
...
@StevellM StevellM added bug Something isn't working serialization labels Feb 10, 2025
@lgoettgens
Copy link
Member

IIrc from personal communication with @antonydellavecchia, the serialization in Oscar only supports "homogeneous" lists, aka all its elements need to have the same "serialization params" (usually parents, coefficient rings, etc.). I don't know how this extends to lists of tuples, but I would assume this to be somehow similar.

Unfortunately, I couldn't find anything about this in the "Serialization" chapter of the documentation.

Maybe @antonydellavecchia could have a look at this particular problem, and also add the answer to the docs?

@antonydellavecchia
Copy link
Collaborator

antonydellavecchia commented Feb 10, 2025

The expected behaviour should actually be that there is an error on save.
In the current master however this check isn't sufficient because it can only check if parent is the same for each entry of the vector and the way parent works on tuples isn't sufficient enough to throw the error.
This is fixed in #4162 .

The reason this should throw an error is because each entry of the vector should be a type that is parametrized in the same way for each entry.
In this example each entry in the vector is a tuple, but they are different tuples since for example each first entry has a different parent.
If you use a tuple instead of a list this should work, this is what the error that wasn't thrown would print.

@antonydellavecchia antonydellavecchia linked a pull request Feb 10, 2025 that will close this issue
@lgoettgens lgoettgens linked a pull request Feb 10, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants