Skip to content

Commit

Permalink
Add serialization of attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Jul 30, 2024
1 parent 27dc2b2 commit bc8c609
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
50 changes: 45 additions & 5 deletions experimental/LieAlgebras/src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,15 +26,18 @@ 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

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
Expand All @@ -45,6 +51,7 @@ function save_object(s::SerializerState, L::DirectSumLieAlgebra)
save_object(s, ref)
end
end
save_attrs(s, L)
end
end

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Serialization/serializers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bc8c609

Please sign in to comment.