Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FTheoryTools] Overhaul Serialization #3932

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 34 additions & 64 deletions experimental/FTheoryTools/src/Serialization/hypersurface_models.jl
Original file line number Diff line number Diff line change
@@ -1,111 +1,81 @@
@register_serialization_type HypersurfaceModel uses_params



###########################################################################
############################################################################
# This function saves the types of the data that define a hypersurface model
###########################################################################
############################################################################

function save_type_params(s::SerializerState, h::HypersurfaceModel)
save_data_dict(s) do
save_object(s, encode_type(HypersurfaceModel), :name)
base = base_space(h)
ambient = ambient_space(h)
fiber_amb_space = fiber_ambient_space(h)
hypersurface_equation_ring = parent(hypersurface_equation(h))
hypersurface_equation_parametrization_ring = parent(h.hypersurface_equation_parametrization)
explicit_model_section_ring = parent(hypersurface_equation(h))
explicit_model_section_keys = collect(keys(h.explicit_model_sections))
if length(explicit_model_section_keys) > 0
explicit_model_section_ring = parent(explicit_model_sections(h)[explicit_model_section_keys[1]])
end

save_data_dict(s, :params) do
save_typed_object(s, base, :base_space)
save_typed_object(s, ambient, :ambient_space)
save_typed_object(s, fiber_amb_space, :fiber_ambient_space)
save_typed_object(s, hypersurface_equation_ring, :hypersurface_equation_ring)
save_typed_object(s, hypersurface_equation_parametrization_ring, :hypersurface_equation_parametrization_ring)
save_typed_object(s, explicit_model_section_ring, :explicit_model_section_ring)
save_typed_object(s, base_space(h), :base_space)
save_typed_object(s, ambient_space(h), :ambient_space)
save_typed_object(s, fiber_ambient_space(h), :fiber_ambient_space)
save_typed_object(s, parent(hypersurface_equation(h)), :hypersurface_equation_ring)
save_typed_object(s, parent(hypersurface_equation_parametrization(h)), :hypersurface_equation_parametrization_ring)
end
end
end


############################################################################
# This function loads the types of the data that define a hypersurface model
############################################################################

function load_type_params(s::DeserializerState, ::Type{<: HypersurfaceModel})
function load_type_params(s::DeserializerState, ::Type{<:HypersurfaceModel})
return (
load_typed_object(s, :base_space),
load_typed_object(s, :ambient_space),
load_typed_object(s, :fiber_ambient_space),
load_typed_object(s, :hypersurface_equation_ring),
load_typed_object(s, :hypersurface_equation_parametrization_ring),
load_typed_object(s, :explicit_model_section_ring)
load_typed_object(s, :hypersurface_equation_parametrization_ring)
)
end


##########################################
# This function saves a hypersurface model
##########################################

function save_object(s::SerializerState, h::HypersurfaceModel)
# Currently, only serialize hypersurface models with toric defining data
@req base_space(h) isa NormalToricVariety "Currently, we only serialize hypersurface models defined over a toric base space"
@req ambient_space(h) isa NormalToricVariety "Currently, we only serialize hypersurface models defined within a toric ambient space"

# Save information
save_data_dict(s) do

# hypersurace equation and parametrization
for (data, key) in [
(explicit_model_sections(h), :explicit_model_sections),
(defining_classes(h), :defining_classes)
]
!isempty(data) && save_typed_object(s, data, key)
end
save_object(s, hypersurface_equation(h), :hypersurface_equation)
save_object(s, hypersurface_equation_parametrization(h), :hypersurface_equation_parametrization)

# Save keys of explicit_model_sections
save_data_array(s, :explicit_model_section_keys) do
for (key, value) in explicit_model_sections(h)
save_object(s, key)
attrs_dict = Dict{Symbol, Any}()
for (key, value) in h.__attrs
if value isa String || value isa Vector{String} || value isa Bool
attrs_dict[key] = value
end
end

# Save values of explicit_model_sections
save_data_array(s, :explicit_model_section_values) do
for (key, value) in explicit_model_sections(h)
save_object(s, value)
end
end

# Boolean values, that are always known for Tate models
save_data_array(s, :boolean_data) do
save_object(s, is_partially_resolved(h))
end
!isempty(attrs_dict) && save_typed_object(s, attrs_dict, :__attrs)
end
end


##########################################
# This function loads a hypersurface model
##########################################

function load_object(s::DeserializerState, ::Type{<: HypersurfaceModel}, params::Tuple{NormalToricVariety, NormalToricVariety, NormalToricVariety, <:MPolyRing, <:MPolyRing, <:MPolyRing})
# load basic data
base_space = params[1]
ambient_space = params[2]
fiber_ambient_space = params[3]
defining_equation = load_object(s, MPolyRingElem, params[4], :hypersurface_equation)
defining_equation_parametrization = load_object(s, MPolyRingElem, params[5], :hypersurface_equation_parametrization)

# Extract explicit_model_sections
values = load_object(s, Vector, params[6], :explicit_model_section_values)
keys = load_object(s, Vector, String, :explicit_model_section_keys)
explicit_model_sections = Dict{String, MPolyRingElem}()
for i in 1:length(keys)
explicit_model_sections[keys[i]] = values[i]
end

# create and return model
function load_object(s::DeserializerState, ::Type{<:HypersurfaceModel}, params::Tuple{NormalToricVariety, NormalToricVariety, NormalToricVariety, <:MPolyRing, <:MPolyRing})
base_space, ambient_space, fiber_ambient_space, R1, R2 = params
defining_equation = load_object(s, MPolyRingElem, R1, :hypersurface_equation)
defining_equation_parametrization = load_object(s, MPolyRingElem, R2, :hypersurface_equation_parametrization)
explicit_model_sections = haskey(s, :explicit_model_sections) ? load_typed_object(s, :explicit_model_sections) : Dict{String, MPolyRingElem}()
defining_classes = haskey(s, :defining_classes) ? load_typed_object(s, :defining_classes) : Dict{String, ToricDivisorClass}()
model = HypersurfaceModel(explicit_model_sections, defining_equation_parametrization, defining_equation, base_space, ambient_space, fiber_ambient_space)
bools = load_object(s, Vector, Bool, :boolean_data)
set_attribute!(model, :partially_resolved, bools[1])
model.defining_classes = defining_classes
attrs_data = haskey(s, :__attrs) ? load_typed_object(s, :__attrs) : Dict{Symbol, Any}()
for (key, value) in attrs_data
set_attribute!(model, Symbol(key), value)
end
return model
end
150 changes: 34 additions & 116 deletions experimental/FTheoryTools/src/Serialization/tate_models.jl
Original file line number Diff line number Diff line change
@@ -1,65 +1,27 @@
@register_serialization_type GlobalTateModel uses_params



###########################################################################
# This function saves the types of the data that define a global Tate model
###########################################################################

function save_type_params(s::SerializerState, gtm::GlobalTateModel)
save_data_dict(s) do
save_object(s, encode_type(GlobalTateModel), :name)
base = base_space(gtm)
ambient = ambient_space(gtm)
tate_polynomial_ring = parent(tate_polynomial(gtm))
explicit_model_section_ring = parent(gtm.explicit_model_sections["a1"])
parametrizing_sections = collect(keys(gtm.defining_section_parametrization))
if length(parametrizing_sections) > 0
defining_section_parametrization_ring = parent(gtm.defining_section_parametrization[parametrizing_sections[1]])
else
defining_section_parametrization_ring = explicit_model_section_ring
end
base, ambient, tp_ring = base_space(gtm), ambient_space(gtm), parent(tate_polynomial(gtm))

save_data_dict(s, :params) do
if serialize_with_id(base)
parent_ref = save_as_ref(s, base)
save_object(s, parent_ref, :base_space)
else
save_typed_object(s, base, :base_space)
end

if serialize_with_id(ambient)
parent_ref = save_as_ref(s, ambient)
save_object(s, parent_ref, :ambient_space)
else
save_typed_object(s, ambient, :ambient_space)
end

if serialize_with_id(tate_polynomial_ring)
parent_ref = save_as_ref(s, tate_polynomial_ring)
save_object(s, parent_ref, :tate_polynomial_ring)
else
save_typed_object(s, tate_polynomial_ring, :tate_polynomial_ring)
end

if serialize_with_id(explicit_model_section_ring)
parent_ref = save_as_ref(s, explicit_model_section_ring)
save_object(s, parent_ref, :explicit_model_section_ring)
else
save_typed_object(s, explicit_model_section_ring, :explicit_model_section_ring)
end

if serialize_with_id(defining_section_parametrization_ring)
parent_ref = save_as_ref(s, defining_section_parametrization_ring)
save_object(s, parent_ref, :defining_section_parametrization_ring)
else
save_typed_object(s, defining_section_parametrization_ring, :defining_section_parametrization_ring)
for (obj, key) in [(base, :base_space), (ambient, :ambient_space), (tp_ring, :tate_polynomial_ring)]
if serialize_with_id(obj)
save_object(s, save_as_ref(s, obj), key)
else
save_typed_object(s, obj, key)

Check warning on line 17 in experimental/FTheoryTools/src/Serialization/tate_models.jl

View check run for this annotation

Codecov / codecov/patch

experimental/FTheoryTools/src/Serialization/tate_models.jl#L17

Added line #L17 was not covered by tests
end
end

end
end
end


###########################################################################
# This function loads the types of the data that define a global Tate model
###########################################################################
Expand All @@ -68,98 +30,54 @@
return (
load_typed_object(s, :base_space),
load_typed_object(s, :ambient_space),
load_typed_object(s, :tate_polynomial_ring),
load_typed_object(s, :explicit_model_section_ring),
load_typed_object(s, :defining_section_parametrization_ring)
load_typed_object(s, :tate_polynomial_ring)
)
end


#########################################
# This function saves a global Tate model
#########################################

function save_object(s::SerializerState, gtm::GlobalTateModel)
# Currently, only serialize Tate models with toric defining data
@req base_space(gtm) isa NormalToricVariety "Currently, we only serialize Tate models defined over a toric base space"
@req ambient_space(gtm) isa NormalToricVariety "Currently, we only serialize Tate models defined within a toric ambient space"

# Save information
save_data_dict(s) do

# Save keys of explicit_model_sections
save_data_array(s, :explicit_model_section_keys) do
for (key, value) in explicit_model_sections(gtm)
save_object(s, key)
end
for (data, key) in [
(explicit_model_sections(gtm), :explicit_model_sections),
(defining_section_parametrization(gtm), :defining_section_parametrization),
(defining_classes(gtm), :defining_classes)
]
!isempty(data) && save_typed_object(s, data, key)
end

# Save values of explicit_model_sections
save_data_array(s, :explicit_model_section_values) do
for (key, value) in explicit_model_sections(gtm)
save_object(s, value)
end
end

# Save keys of defining_section_parametrization
save_data_array(s, :defining_section_parametrization_keys) do
for (key, value) in defining_section_parametrization(gtm)
save_object(s, key)
end
end

# Save keys of defining_section_parametrization
save_data_array(s, :defining_section_parametrization_values) do
for (key, value) in defining_section_parametrization(gtm)
save_object(s, value)
end
end

# Tate polynomial
save_object(s, tate_polynomial(gtm), :tate_polynomial)

# Boolean values, that are always known for Tate models
save_data_array(s, :boolean_data) do
save_object(s, is_partially_resolved(gtm))
attrs_dict = Dict{Symbol, Any}()
for (key, value) in gtm.__attrs
if value isa String || value isa Vector{String} || value isa Bool
attrs_dict[key] = value
end
end
!isempty(attrs_dict) && save_typed_object(s, attrs_dict, :__attrs)
end
end


#########################################
# This function loads a global Tate model
#########################################

function load_object(s::DeserializerState, ::Type{<: GlobalTateModel}, params::Tuple{NormalToricVariety, NormalToricVariety, MPolyDecRing, MPolyDecRing, <:MPolyRing})

# Extract base and ambient space
base_space = params[1]
ambient_space = params[2]

# Extract Tate polynomial
pt = load_object(s, MPolyDecRingElem, params[3], :tate_polynomial)

# Extract explicit_model_sections
values = load_object(s, Vector, params[4], :explicit_model_section_values)
keys = load_object(s, Vector, String, :explicit_model_section_keys)
explicit_model_sections = Dict{String, MPolyRingElem}()
for i in 1:length(keys)
explicit_model_sections[keys[i]] = values[i]
end

# Extract defining_section_parametrization
values = load_object(s, Vector, params[5], :defining_section_parametrization_values)
keys = load_object(s, Vector, String, :defining_section_parametrization_keys)
defining_section_parametrization = Dict{String, MPolyRingElem}()
for i in 1:length(keys)
defining_section_parametrization[keys[i]] = values[i]
end

# Construct the model
function load_object(s::DeserializerState, ::Type{<: GlobalTateModel}, params::Tuple{NormalToricVariety, NormalToricVariety, MPolyDecRing})
base_space, ambient_space, tp_ring = params
pt = load_object(s, MPolyDecRingElem, tp_ring, :tate_polynomial)
explicit_model_sections = haskey(s, :explicit_model_sections) ? load_typed_object(s, :explicit_model_sections) : Dict{String, MPolyRingElem}()
defining_section_parametrization = haskey(s, :defining_section_parametrization) ? load_typed_object(s, :defining_section_parametrization) : Dict{String, MPolyRingElem}()
defining_classes = haskey(s, :defining_classes) ? load_typed_object(s, :defining_classes) : Dict{String, ToricDivisorClass}()
model = GlobalTateModel(explicit_model_sections, defining_section_parametrization, pt, base_space, ambient_space)

# Set boolean attributes
bools = load_object(s, Vector, Bool, :boolean_data)
set_attribute!(model, :partially_resolved, bools[1])

# Return the loaded model
model.defining_classes = defining_classes
attrs_data = haskey(s, :__attrs) ? load_typed_object(s, :__attrs) : Dict{Symbol, Any}()
for (key, value) in attrs_data
set_attribute!(model, Symbol(key), value)
end
return model
end
Loading
Loading