From bc8c609c16cffa1432dd60af0b90bc817d65169d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 30 Jul 2024 20:51:23 +0200 Subject: [PATCH] Add serialization of attributes --- experimental/LieAlgebras/src/serialization.jl | 50 +++++++++++++++++-- src/Serialization/serializers.jl | 5 ++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/experimental/LieAlgebras/src/serialization.jl b/experimental/LieAlgebras/src/serialization.jl index cdfe5e24939b..90962d500b30 100644 --- a/experimental/LieAlgebras/src/serialization.jl +++ b/experimental/LieAlgebras/src/serialization.jl @@ -5,14 +5,17 @@ function save_object(s::SerializerState, L::AbstractLieAlgebra) save_typed_object(s, coefficient_ring(L), :base_ring) save_object(s, _struct_consts(L), :struct_consts) save_object(s, symbols(L), :symbols) + save_attrs(s, L) end end function load_object(s::DeserializerState, ::Type{AbstractLieAlgebra}) R = load_typed_object(s, :base_ring) struct_consts = load_object(s, Matrix, (sparse_row_type(R), R), :struct_consts) - s = load_object(s, Vector, Symbol, :symbols) - return lie_algebra(R, struct_consts, s; check=false) + symbs = load_object(s, Vector, Symbol, :symbols) + L = lie_algebra(R, struct_consts, symbs; check=false) + load_attrs!(s, L) + return L end @register_serialization_type LinearLieAlgebra uses_id @@ -23,6 +26,7 @@ function save_object(s::SerializerState, L::LinearLieAlgebra) save_object(s, L.n, :n) save_object(s, matrix_repr_basis(L), :basis) save_object(s, symbols(L), :symbols) + save_attrs(s, L) end end @@ -30,8 +34,10 @@ function load_object(s::DeserializerState, ::Type{LinearLieAlgebra}) R = load_typed_object(s, :base_ring) n = load_object(s, Int, :n) basis = load_object(s, Vector, (dense_matrix_type(R), matrix_space(R, n, n)), :basis) - s = load_object(s, Vector, Symbol, :symbols) - return lie_algebra(R, n, basis, s; check=false) + symbs = load_object(s, Vector, Symbol, :symbols) + L = lie_algebra(R, n, basis, symbs; check=false) + load_attrs!(s, L) + return L end @register_serialization_type DirectSumLieAlgebra uses_id @@ -45,6 +51,7 @@ function save_object(s::SerializerState, L::DirectSumLieAlgebra) save_object(s, ref) end end + save_attrs(s, L) end end @@ -56,7 +63,40 @@ function load_object(s::DeserializerState, ::Type{DirectSumLieAlgebra}) end, ) - return direct_sum(R, summands) + L = direct_sum(R, summands) + load_attrs!(s, L) + return L +end + +function save_attrs(s::SerializerState, L::LieAlgebra) + save_data_dict(s, :attrs) do + for bool_prop in (:is_abelian, :is_nilpotent, :is_perfect, :is_simple, :is_solvable) + if has_attribute(L, bool_prop) + save_object(s, get_attribute(L, bool_prop), bool_prop) + end + end + for symbol_prop in (:type,) + if has_attribute(L, symbol_prop) + save_object(s, get_attribute(L, symbol_prop), symbol_prop) + end + end + # TODO: handle root_system + end +end + +function load_attrs!(s::DeserializerState, L::LieAlgebra) + Oscar.load_node(s, :attrs) do _ + for bool_prop in (:is_abelian, :is_nilpotent, :is_perfect, :is_simple, :is_solvable) + if haskey(s, bool_prop) + set_attribute!(L, bool_prop, load_object(s, Bool, bool_prop)) + end + end + for symbol_prop in (:type,) + if haskey(s, symbol_prop) + set_attribute!(L, symbol_prop, load_object(s, Symbol, symbol_prop)) + end + end + end end @register_serialization_type AbstractLieAlgebraElem uses_params diff --git a/src/Serialization/serializers.jl b/src/Serialization/serializers.jl index 5873ff681aab..db9d4ccc2437 100644 --- a/src/Serialization/serializers.jl +++ b/src/Serialization/serializers.jl @@ -53,6 +53,11 @@ end function end_dict_node(s::SerializerState) write(s.io, "}") + + if s.new_level_entry + # makes sure that entries after empty dicts add comma + s.new_level_entry = false + end end function begin_array_node(s::SerializerState)