Skip to content

Commit

Permalink
Add serialization of weyl groups
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Aug 19, 2024
1 parent 66ce630 commit e41fbea
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
42 changes: 42 additions & 0 deletions experimental/LieAlgebras/src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,45 @@ function load_type_params(
)
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
58 changes: 58 additions & 0 deletions experimental/LieAlgebras/test/WeylGroup-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,62 @@ include(
@test allunique(orb)
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

0 comments on commit e41fbea

Please sign in to comment.