Skip to content

Commit

Permalink
Revert "Merge remote-tracking branch 'origin/adv/ipc-serialize' into …
Browse files Browse the repository at this point in the history
…adv/ipc-serialize"

This reverts commit 424e014, reversing
changes made to a5fab69.
  • Loading branch information
antonydellavecchia committed Jan 20, 2025
1 parent 424e014 commit af1675c
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 180 deletions.
2 changes: 0 additions & 2 deletions gap/OscarInterface/gap/OscarInterface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ DeclareProperty( "GroupGeneratorsDefinePresentation", IsGroup );

# Use GAP operations for the serialization of GAP objects.
# (The methods will be Julia functions.)
DeclareOperation( "SerializationInOscarDependentObjects", [ IsObject ] );
DeclareOperation( "SerializeInOscar", [ IsObject, IsObject ] );
DeclareConstructor( "DeserializeInOscar", [ IsObject, IsObject, IsObject ] );
DeclareConstructor( "DeserializeInOscar", [ IsObject, IsObject, IsObject, IsObject ] );
19 changes: 3 additions & 16 deletions gap/OscarInterface/gap/OscarInterface.gi
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ InstallMethod( GroupGeneratorsDefinePresentation,
############################################################################


Perform( Oscar._GAP_type_params,
function( entry )
InstallMethod( SerializationInOscarDependentObjects,
[ JuliaToGAP( IsString, entry[1] ) ],
Julia.GAP.WrapJuliaFunc( entry[2] ) );
end );

Perform( Oscar._GAP_serializations,
function( entry )
InstallMethod( SerializeInOscar,
Expand All @@ -143,15 +136,9 @@ Perform( Oscar._GAP_serializations,

Perform( Oscar._GAP_deserializations,
function( entry )
if entry[3] then
InstallMethod( DeserializeInOscar,
[ JuliaToGAP( IsString, entry[1] ), "IsObject", "IsObject", "IsObject" ],
Julia.GAP.WrapJuliaFunc( entry[2] ) );
else
InstallMethod( DeserializeInOscar,
[ JuliaToGAP( IsString, entry[1] ), "IsObject", "IsObject" ],
Julia.GAP.WrapJuliaFunc( entry[2] ) );
fi;
InstallMethod( DeserializeInOscar,
[ JuliaToGAP( IsString, entry[1] ), "IsObject", "IsObject" ],
Julia.GAP.WrapJuliaFunc( entry[2] ) );
end );

############################################################################
Expand Down
155 changes: 61 additions & 94 deletions src/Serialization/GAP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@
#
# utilities for installing methods depending on GAP filters
#
const _GAP_type_params = Pair{Symbol, Function}[]
const _GAP_serializations = Pair{Symbol, Function}[]
const _GAP_deserializations = Tuple{Symbol, Function, Bool}[]

function install_GAP_type_params(filtsymbol::Symbol, meth::Function)
push!(_GAP_type_params, filtsymbol => meth)
return
end
const _GAP_deserializations = Pair{Symbol, Function}[]

function install_GAP_serialization(filtsymbol::Symbol, meth::Function)
push!(_GAP_serializations, filtsymbol => meth)
return
end

function install_GAP_deserialization(filtsymbol::Symbol, with_params::Bool, meth::Function)
push!(_GAP_deserializations, (filtsymbol, meth, with_params))
function install_GAP_deserialization(filtsymbol::Symbol, meth::Function)
push!(_GAP_deserializations, filtsymbol => meth)
return
end

Expand All @@ -39,9 +33,14 @@ end
#
@register_serialization_type GapObj uses_id


function type_params(X::GapObj)
return GapObj, GAP.Globals.SerializationInOscarDependentObjects(X)::Union{Nothing,GapObj}
if GAP.Globals.HasIsWholeFamily(X) && GAPWrap.IsWholeFamily(X)
return GapObj, nothing
else
elfam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(X))
F = GAP.getbangproperty(elfam, :freeGroup)::GapObj
return GapObj, F
end
end

function save_object(s::SerializerState, X::GapObj)
Expand Down Expand Up @@ -96,18 +95,7 @@ install_GAP_serialization(:IsFamily,

# - `IsFreeGroup`:
# full free group or subgroup of it,
# distinguished by type parameter `:freeGroup` and presence of `:gens`
# in case of a subgroup
install_GAP_type_params(:IsFreeGroup,
function(X::GapObj)
if GAP.Globals.HasIsWholeFamily(X) && GAPWrap.IsWholeFamily(X)
return nothing
else
elfam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(X))
return GAP.getbangproperty(elfam, :freeGroup)::GapObj
end
end)

# distinguished by presence of `:freeGroup` and `:gens` in case of a subgroup
install_GAP_serialization(:IsFreeGroup,
function(X::GapObj, s::SerializerState)
elfam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(X))
Expand Down Expand Up @@ -151,9 +139,8 @@ install_GAP_serialization(:IsFreeGroup,
end
end)

# no type parameters: create a full free group
install_GAP_deserialization(
:IsFreeGroup, false,
:IsFreeGroup,
function(filt::GapObj, s::DeserializerState, T)
load_node(s) do d
# Create a new full free group.
Expand All @@ -178,41 +165,28 @@ install_GAP_deserialization(
end
G = GAP.Globals.FreeGroup(wfilt, init)::GapObj
end
return G
end
return G
end)

# with type parameters: create a subgroup of a full free group
install_GAP_deserialization(
:IsFreeGroup, true,
:IsFreeGroup,
function(filt::GapObj, s::DeserializerState, T, F)
load_node(s) do d
# Deserialize the generators.
generators = load_object(s, Vector{Vector{Int}}, :gens)
generators = load_object(s, Vector, (Vector{Int}, Int), :gens)
fam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(F))
Ggens = [GAPWrap.ObjByExtRep(fam, GapObj(x, true)) for x in generators]
# Create the subgroup.
return GAP.Globals.SubgroupNC(F, GapObj(Ggens))::GapObj
G = GAP.Globals.SubgroupNC(F, GapObj(Ggens))::GapObj
end
return G
end)


# - `IsSubgroupFpGroup`:
# full f.p. group or subgroup of it,
# distinguished by type parameter `:freeGroup` and presence of `:relators`
# in case of a full group, or
# type parameter `:wholeGroup` and presence of `:gens` in case of a subgroup
install_GAP_type_params(:IsSubgroupFpGroup,
function(X::GapObj)
Xfam = GAPWrap.FamilyObj(X)
if GAP.Globals.HasIsWholeFamily(X) && GAPWrap.IsWholeFamily(X)
elfam = GAPWrap.ElementsFamily(Xfam)
F = GAP.getbangproperty(elfam, :freeGroup)::GapObj
else
F = GAP.getbangproperty(Xfam, :wholeGroup)::GapObj
end
return F
end)

# distinguished by presence of `:wholeGroup` and `:gens` in case of a subgroup
install_GAP_serialization(:IsSubgroupFpGroup,
function(X::GapObj, s::SerializerState)
Xfam = GAPWrap.FamilyObj(X)
Expand All @@ -221,46 +195,49 @@ install_GAP_serialization(:IsSubgroupFpGroup,
# full f.p. group: Save the defining data.
save_data_dict(s) do
save_object(s, "IsSubgroupFpGroup", :GapType)
# underlying free group
freegroup = GAP.getbangproperty(elfam, :freeGroup)::GapObj
# relators
relators = GAP.getbangproperty(elfam, :relators)::GapObj
save_object(s, [Vector{Int}(GAPWrap.ExtRepOfObj(x)) for x in relators], :relators)
end
else
# subgroup of a full f.p. group: save the full group and generators
save_data_dict(s) do
F = GAP.getbangproperty(Xfam, :wholeGroup)::GapObj
save_object(s, "IsSubgroupFpGroup", :GapType)
save_typed_object(s, F, :wholeGroup)
# store generators
save_object(s, [Vector{Int}(GAPWrap.ExtRepOfObj(x)) for x in GAPWrap.GeneratorsOfGroup(X)], :gens)
end
end
end)

# we have always a type parameter,
# in case of a full f.p. group the underlying free group,
# in case of a subgroup the full f.p. group
install_GAP_deserialization(
:IsSubgroupFpGroup, true,
function(filt::GapObj, s::DeserializerState, T, F)
:IsSubgroupFpGroup,
function(filt::GapObj, s::DeserializerState, T)
load_node(s) do d
if haskey(s, :gens)
if haskey(s, :wholeGroup) && haskey(s, :gens)
# Deserialize the full f.p. group.
F = load_typed_object(s, :wholeGroup)
Ffam = GAPWrap.FamilyObj(F)
elfam = GAPWrap.ElementsFamily(Ffam)
freegroup = GAP.getbangproperty(elfam, :freeGroup)::GapObj
freefam = GAPWrap.FamilyObj(freegroup)
elfreefam = GAPWrap.ElementsFamily(freefam)
# Deserialize the generators.
generators = load_object(s, Vector{Vector{Int}}, :gens)
generators = load_object(s, Vector, (Vector{Int}, Int), :gens)
gens = [GAPWrap.ObjByExtRep(elfreefam, GapObj(x, true)) for x in generators]
Ggens = [GAPWrap.ElementOfFpGroup(elfam, x) for x in gens]
# Create the subgroup.
G = GAP.Globals.SubgroupNC(F, GapObj(Ggens))::GapObj
else
# Create a new full f.p. group.
relators = load_object(s, Vector{Vector{Int}}, :relators)
F = load_typed_object(s, :freeGroup)
relators = load_object(s, Vector, (Vector{Int}, Int), :relators)
elfreefam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(F))
rels = [GAPWrap.ObjByExtRep(elfreefam, GapObj(x, true)) for x in relators]
G = F/GapObj(rels)::GapObj
G = F/GapObj(rels)
end
return G
end
Expand All @@ -272,17 +249,6 @@ install_GAP_deserialization(
# we do not support (de)serialization of the stored rws,
# thus we need not (de)serialize its underlying free group etc.

install_GAP_type_params(:IsPcGroup,
function(X::GapObj)
elfam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(X))
fullpcgs = GAP.getbangproperty(elfam, :DefiningPcgs)::GapObj
if fullpcgs === GAPWrap.Pcgs(X)
return nothing
else
return GAP.getbangproperty(fullpcgs, :GroupOfPcgs)::GapObj
end
end)

# utility, turn an exponent vector `[a_1, a_2, ..., a_n]`
# into `[1, a_1, 2, a_2, ..., n, a_n]`
function _free_group_extrep_from_exponents(exps::Vector{Int})
Expand Down Expand Up @@ -332,44 +298,45 @@ install_GAP_serialization(:IsPcGroup,
save_object(s, rels, :comm_rels)
end
else
# save generators w.r.t. the full group
# save full group and generators
save_data_dict(s) do
save_object(s, "IsPcGroup", :GapType)
G = GAP.getbangproperty(fullpcgs, :GroupOfPcgs)::GapObj
save_typed_object(s, G, :fullGroup)
save_object(s, [Vector{Int}(GAP.Globals.ExponentsOfPcElement(fullpcgs, x)::GapObj)
for x in GAP.Globals.InducedPcgsWrtHomePcgs(X)::GapObj], :gens)
end
end
end)

# no type parameters: create a full pc group
install_GAP_deserialization(
:IsPcGroup, false,
:IsPcGroup,
function(filt::GapObj, s::DeserializerState, T)
relord = load_object(s, Vector{Int}, :relord)
F = GAP.Globals.FreeGroup(GAP.Globals.IsSyllableWordsFamily,
length(relord))::GapObj
fam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(F))
rws = GAP.Globals.SingleCollector(F, GapObj(relord))::GapObj
for (i, elm) in load_object(s, Vector{Tuple{Int, Vector{Int}}}, :power_rels)
GAP.Globals.SetPower(rws, i, GAPWrap.ObjByExtRep(fam, GapObj(elm)))
end
for (j, i, elm) in load_object(s, Vector{Tuple{Int, Int, Vector{Int}}}, :comm_rels)
GAP.Globals.SetCommutator(rws, j, i, GAPWrap.ObjByExtRep(fam, GapObj(elm)))
if haskey(s, :relord)
# full pc group
relord = load_object(s, Vector, Int, :relord)
F = GAP.Globals.FreeGroup(GAP.Globals.IsSyllableWordsFamily,
length(relord))::GapObj
fam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(F))
rws = GAP.Globals.SingleCollector(F, GapObj(relord))::GapObj
for (i, elm) in load_object(s, Vector, (Tuple, [Int, [Vector, Int]]), :power_rels)
GAP.Globals.SetPower(rws, i, GAPWrap.ObjByExtRep(fam, GapObj(elm)))
end
for (j, i, elm) in load_object(s, Vector, (Tuple, [Int, Int, [Vector, Int]]), :comm_rels)
GAP.Globals.SetCommutator(rws, j, i, GAPWrap.ObjByExtRep(fam, GapObj(elm)))
end
G = GAP.Globals.GroupByRwsNC(rws)::GapObj
else
# Deserialize the full pc group.
F = load_typed_object(s, :fullGroup)
elfam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(F))
fullpcgs = GAP.getbangproperty(elfam, :DefiningPcgs)::GapObj
# Deserialize the generators.
generators = load_object(s, Vector, (Vector{Int}, Int), :gens)
Ggens = [GAP.Globals.PcElementByExponentsNC(fullpcgs, GapObj(x, true))::GapObj
for x in generators]
# Create the subgroup.
G = GAP.Globals.SubgroupNC(F, GapObj(Ggens))::GapObj
end
return GAP.Globals.GroupByRwsNC(rws)::GapObj
end)

# with type parameters: create a subgroup of a full pc group
install_GAP_deserialization(
:IsPcGroup, true,
function(filt::GapObj, s::DeserializerState, T, F)
# Deserialize the full pc group.
elfam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(F))
fullpcgs = GAP.getbangproperty(elfam, :DefiningPcgs)::GapObj
# Deserialize the generators.
generators = load_object(s, Vector{Vector{Int}}, :gens)
Ggens = [GAP.Globals.PcElementByExponentsNC(fullpcgs, GapObj(x, true))::GapObj
for x in generators]
# Create the subgroup.
return GAP.Globals.SubgroupNC(F, GapObj(Ggens))::GapObj
return G
end)
10 changes: 5 additions & 5 deletions src/Serialization/Groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
# `GAPGroupElem` objects get serialized together with their parents.
const GrpElemUnionType = Union{GAPGroupElem, FinGenAbGroupElem}

type_params(p::T) where T <: GrpElemUnionType = T, parent(p)
type_params(p::T) where T <: GrpElemUnionType = parent(p)


#############################################################################
Expand Down Expand Up @@ -140,7 +140,7 @@ end

function load_object(s::DeserializerState, ::Type{PermGroup})
n = load_object(s, Int, :degree)
generators = load_object(s, Vector{Vector{Int}}, :gens)
generators = load_object(s, Vector, (Vector{Int}, Int), :gens)
G = permutation_group(n, [perm(x) for x in generators])
load_attrs(s, G)
return G
Expand All @@ -162,7 +162,7 @@ function save_object(s::SerializerState, p::PermGroupElem)
end

function load_object(s::DeserializerState, T::Type{PermGroupElem}, parent_group::PermGroup)
imgs = load_object(s, Vector{Int})
imgs = load_object(s, Vector, Int)
return perm(parent_group, imgs)
end

Expand Down Expand Up @@ -204,7 +204,7 @@ typecombinations = (

for (eltype, type) in typecombinations
@eval function load_object(s::DeserializerState, ::Type{$eltype}, parent_group::$type)
lo = load_object(s, Vector{Int})
lo = load_object(s, Vector, Int)
fam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(GapObj(parent_group)))
if GAPWrap.IsElementOfFpGroupFamily(fam)
# go via the underlying free group
Expand Down Expand Up @@ -259,7 +259,7 @@ typecombinations = (

for (eltype, type) in typecombinations
@eval function load_object(s::DeserializerState, ::Type{$eltype}, parent_group::$type)
lo = load_object(s, Vector{Int})
lo = load_object(s, Vector, Int)
elfam = GAPWrap.ElementsFamily(GAPWrap.FamilyObj(GapObj(parent_group)))
fullpcgs = GAP.getbangproperty(elfam, :DefiningPcgs)::GapObj
gapelm = GAPWrap.PcElementByExponentsNC(fullpcgs, GapObj(lo, true))::GapObj
Expand Down
Loading

0 comments on commit af1675c

Please sign in to comment.