From e41fbea5438c80e7be8cbb12eecae656afe525ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 31 Jul 2024 15:48:19 +0200 Subject: [PATCH] Add serialization of weyl groups --- experimental/LieAlgebras/src/serialization.jl | 42 ++++++++++++++ .../LieAlgebras/test/WeylGroup-test.jl | 58 +++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/experimental/LieAlgebras/src/serialization.jl b/experimental/LieAlgebras/src/serialization.jl index 91f14410fe33..f630772da5b6 100644 --- a/experimental/LieAlgebras/src/serialization.jl +++ b/experimental/LieAlgebras/src/serialization.jl @@ -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 diff --git a/experimental/LieAlgebras/test/WeylGroup-test.jl b/experimental/LieAlgebras/test/WeylGroup-test.jl index 375cbb4b5569..da8ae8a26d44 100644 --- a/experimental/LieAlgebras/test/WeylGroup-test.jl +++ b/experimental/LieAlgebras/test/WeylGroup-test.jl @@ -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