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

Move LieTheory serialization to src; add WeightLattice serialization #4414

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 0 additions & 106 deletions experimental/LieAlgebras/src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,109 +240,3 @@ end
function load_type_params(s::DeserializerState, ::Type{<:LieAlgebraModuleElem})
return load_typed_object(s)
end

###############################################################################
#
# Root systems
#
###############################################################################

@register_serialization_type RootSystem uses_id

function save_object(s::SerializerState, R::RootSystem)
save_data_dict(s) do
save_object(s, cartan_matrix(R), :cartan_matrix)
if has_root_system_type(R)
type, type_ordering = root_system_type_with_ordering(R)
save_object(s, type, :type)
if !issorted(type_ordering) # don't save if it's the default
save_object(s, type_ordering, :type_ordering)
end
end
end
end

function load_object(s::DeserializerState, ::Type{RootSystem})
cm = load_object(s, Matrix, Int, :cartan_matrix)
R = root_system(cm; check=false, detect_type=false)
if haskey(s, :type)
type = Vector{Tuple{Symbol,Int}}(load_object(s, Vector, (Tuple, [Symbol, Int]), :type)) # coercion needed due to https://github.com/oscar-system/Oscar.jl/issues/3983
if haskey(s, :type_ordering)
type_ordering = load_object(s, Vector, Int, :type_ordering)
set_root_system_type!(R, type, type_ordering)
else
set_root_system_type!(R, type)
end
end
return R
end

@register_serialization_type RootSpaceElem uses_params
@register_serialization_type DualRootSpaceElem uses_params

function save_object(s::SerializerState, r::Union{RootSpaceElem,DualRootSpaceElem})
save_object(s, _vec(coefficients(r)))
end

function load_object(
s::DeserializerState, T::Type{<:Union{RootSpaceElem,DualRootSpaceElem}}, R::RootSystem
)
return T(R, load_object(s, Vector, QQ))
end

function save_type_params(s::SerializerState, r::Union{RootSpaceElem,DualRootSpaceElem})
save_data_dict(s) do
save_object(s, encode_type(typeof(r)), :name)
rs_x = root_system(r)
rs_ref = save_as_ref(s, rs_x)
save_object(s, rs_ref, :params)
end
end

function load_type_params(
s::DeserializerState, ::Type{<:Union{RootSpaceElem,DualRootSpaceElem}}
)
return load_typed_object(s)
end

###############################################################################
#
# Weyl groups
#
###############################################################################

@register_serialization_type WeylGroup uses_id

function save_object(s::SerializerState, W::WeylGroup)
save_data_dict(s) do
save_typed_object(s, root_system(W), :root_system)
end
end

function load_object(s::DeserializerState, ::Type{WeylGroup})
R = load_typed_object(s, :root_system)
return weyl_group(R)
end

@register_serialization_type WeylGroupElem uses_params

function save_object(s::SerializerState, x::WeylGroupElem)
save_object(s, word(x))
end

function load_object(s::DeserializerState, ::Type{WeylGroupElem}, W::WeylGroup)
return W(load_object(s, Vector, UInt8); normalize=false)
end

function save_type_params(s::SerializerState, x::WeylGroupElem)
save_data_dict(s) do
save_object(s, encode_type(typeof(x)), :name)
parent_x = parent(x)
parent_ref = save_as_ref(s, parent_x)
save_object(s, parent_ref, :params)
end
end

function load_type_params(s::DeserializerState, ::Type{WeylGroupElem})
return load_typed_object(s)
end
107 changes: 0 additions & 107 deletions experimental/LieAlgebras/test/RootSystem-test.jl

This file was deleted.

58 changes: 0 additions & 58 deletions experimental/LieAlgebras/test/WeylGroup-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,62 +118,4 @@
end
end
end

@testset "Serialization" begin
mktempdir() do path
@testset "simple saving and loading" begin
W = weyl_group((:A, 2), (:B, 4))

test_save_load_roundtrip(path, W) do loaded
# nothing, cause `W === loaded` anyway
end

x = rand(W)
test_save_load_roundtrip(path, x) do loaded
@test parent(loaded) === W
@test word(loaded) == word(x)
end

test_save_load_roundtrip(path, gens(W)) do loaded
@test length(loaded) == ngens(W)
@test all(
word(loaded[i]) == word(gen(W, i)) for i in 1:ngens(W)
)
end
end

@testset "cyclic reference between R and W survives" begin
Oscar.reset_global_serializer_state()

R_filename = joinpath(path, "R.mrdi")
W_filename = joinpath(path, "W.mrdi")

R = root_system(:D, 5)
W = weyl_group(R)

save(R_filename, R)
save(W_filename, W)

Oscar.reset_global_serializer_state()

loaded_R = load(R_filename)
loaded_W = load(W_filename)

@test loaded_R === root_system(loaded_W)
@test loaded_W === weyl_group(loaded_R)

loaded_R = loaded_W = nothing # unset all references

Oscar.reset_global_serializer_state()

loaded_W = load(W_filename)
loaded_R = load(R_filename)

@test loaded_R === root_system(loaded_W)
@test loaded_W === weyl_group(loaded_R)

loaded_R = loaded_W = nothing # unset all references
end
end
end
end
Loading
Loading