Skip to content

Commit

Permalink
progress on polyhedral objects
Browse files Browse the repository at this point in the history
  • Loading branch information
antonydellavecchia committed Jan 30, 2025
1 parent 0fd56a2 commit 54ce61d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
38 changes: 37 additions & 1 deletion src/Serialization/PolyhedralGeometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ function type_params(obj::T) where {S, T <: PolyhedralObject{S}}
return type_params(_polyhedral_object_as_dict(obj))
end

function save_type_params(s::SerializerState, obj::PolyhedralObject{S}) where S <: Union{QQFieldElem, Float64}
save_type_params(s, typeof(obj), type_params(obj))
end

function save_type_params(s::SerializerState, obj::T) where {S, T <: PolyhedralObject{S}}
dict = _polyhedral_object_as_dict(obj)
params = type_params(obj)
save_data_dict(s) do
save_object(s, encode_type(T), :name)
save_data_dict(s, :params) do
for key in keys(dict)
save_type_params(s, typeof(dict[key]), params[key], key)
end
end
end
end

function load_type_params(s::DeserializerState, T::Type{<:PolyhedralObject})
load_node(s, :params) do obj
if obj isa String || haskey(s, :params)
U = decode_type(s)
params = load_type_params(s, U)[2]
return T{U}, params
else # handle cases where type_params is a dict of params
params = Dict{Symbol, Any}()
for (k, _) in obj
params[k] = load_node(s, k) do _
U = decode_type(s)
load_type_params(s, U)[2]
end
end
return T{EmbeddedNumFieldElem}, params
end
end
end

function save_object(s::SerializerState, obj::PolyhedralObject{S}) where S <: Union{QQFieldElem, Float64}
save_object(s, pm_object(obj))
end
Expand Down Expand Up @@ -74,7 +110,7 @@ end

function load_object(s::DeserializerState, T::Type{<:PolyhedralObject{S}},
dict::Dict) where S <: FieldElem
polymake_dict = load_object(s, Dict{String, Any}, dict)
polymake_dict = load_object(s, Dict{Symbol, Any}, dict)
bigobject = _dict_to_bigobject(polymake_dict)
if Base.issingletontype(dict["_coeff"][1])
field = dict["_coeff"][1]()
Expand Down
1 change: 0 additions & 1 deletion src/Serialization/main.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# This type should not be exported and should be before serializers
const BasicTypeUnion = Union{String, QQFieldElem, Symbol,
Number, ZZRingElem, TropicalSemiringElem}
Expand Down
10 changes: 5 additions & 5 deletions src/Serialization/polymake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ _pmdata_for_oscar(s::Polymake.Set, coeff::Field) = Set(_pmdata_for_oscar(e, coef


function _bigobject_to_dict(bo::Polymake.BigObject, coeff::Field)
data = Dict{String,Any}()
data = Dict{Symbol,Any}()
for pname in Polymake.list_properties(bo)
p = Polymake.give(bo, pname)
if p isa Polymake.PropertyValue
@debug "missing c++ mapping: skipping $pname of type $(Polymake.typeinfo_string(p, true))"
else
try
obj = _pmdata_for_oscar(p, coeff)
data[pname] = obj
data[Symbol(pname)] = obj
catch e
if e isa MethodError
@debug "failed to convert $pname of type $(typeof(p)) to Oscar, skipping"
Expand All @@ -136,16 +136,16 @@ function _bigobject_to_dict(bo::Polymake.BigObject, coeff::Field)
description = Polymake.getdescription(bo)

if !isempty(description)
data["_description"] = String(description)
data[:_description] = String(description)
end
data
end

function _polyhedral_object_as_dict(x::Oscar.PolyhedralObjectUnion)
bo = Oscar.pm_object(x)
data = _bigobject_to_dict(bo, coefficient_field(x))
data["_type"] = Polymake.bigobject_qualifiedname(bo)
data["_coeff"] = coefficient_field(x)
data[:_type] = Polymake.bigobject_qualifiedname(bo)
data[:_coeff] = coefficient_field(x)
return data
end

Expand Down

0 comments on commit 54ce61d

Please sign in to comment.