Skip to content

Commit

Permalink
[FTheoryTools] Overhaul serialization of Weierstrass models
Browse files Browse the repository at this point in the history
  • Loading branch information
HereAround committed Jul 19, 2024
1 parent 8e30c2c commit 133d1c4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 63 deletions.
96 changes: 33 additions & 63 deletions experimental/FTheoryTools/src/Serialization/weierstrass_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ function save_type_params(s::SerializerState, w::WeierstrassModel)
base = base_space(w)
ambient = ambient_space(w)
weierstrass_polynomial_ring = parent(weierstrass_polynomial(w))
explicit_model_section_ring = parent(w.explicit_model_sections["f"])
parametrizing_sections = collect(keys(defining_section_parametrization(w)))
if length(parametrizing_sections) > 0
defining_section_parametrization_ring = parent(w.defining_section_parametrization[parametrizing_sections[1]])
else
defining_section_parametrization_ring = explicit_model_section_ring
end

save_data_dict(s, :params) do
if serialize_with_id(base)
Expand All @@ -42,40 +35,24 @@ function save_type_params(s::SerializerState, w::WeierstrassModel)
save_typed_object(s, weierstrass_polynomial_ring, :weierstrass_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)
end

end
end
end

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

function load_type_params(s::DeserializerState, ::Type{<: WeierstrassModel})
return (
load_typed_object(s, :base_space),
load_typed_object(s, :ambient_space),
load_typed_object(s, :weierstrass_polynomial_ring),
load_typed_object(s, :explicit_model_section_ring),
load_typed_object(s, :defining_section_parametrization_ring)
load_typed_object(s, :weierstrass_polynomial_ring)
)
end

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

function save_object(s::SerializerState, w::WeierstrassModel)
Expand All @@ -86,75 +63,68 @@ function save_object(s::SerializerState, w::WeierstrassModel)
# 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(w)
save_object(s, key)
end
# Save explicit_model_sections(w)
if !is_empty(explicit_model_sections(w))
save_typed_object(s, explicit_model_sections(w), :explicit_model_sections)
end

# Save values of explicit_model_sections
save_data_array(s, :explicit_model_section_values) do
for (key, value) in explicit_model_sections(w)
save_object(s, value)
end
# Save defining_section_parametrization(w)
if !is_empty(defining_section_parametrization(w))
save_typed_object(s, defining_section_parametrization(w), :defining_section_parametrization)
end

# Save keys of defining_section_parametrization
save_data_array(s, :defining_section_parametrization_keys) do
for (key, value) in defining_section_parametrization(w)
save_object(s, key)
end
# save_defining_classes(w)
if !is_empty(defining_classes(w))
save_typed_object(s, defining_classes(w), :defining_classes)
end

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

# Tate polynomial
# Weierstrass polynomial
save_object(s, weierstrass_polynomial(w), :weierstrass_polynomial)

# Boolean values, that are always known for Tate models
# Boolean values, that are always known for Weierstrass models
save_data_array(s, :boolean_data) do
save_object(s, is_partially_resolved(w))
end
end
end

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

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

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

# Extract Tate polynomial
# Extract Weierstrass polynomial
pw = load_object(s, MPolyDecRingElem, params[3], :weierstrass_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]
if haskey(s, :explicit_model_sections)
explicit_model_sections = load_typed_object(s, :explicit_model_sections)
else
explicit_model_sections = Dict{String, MPolyRingElem}()
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]
if haskey(s, :defining_section_parametrization)
defining_section_parametrization = load_typed_object(s, :defining_section_parametrization)
else
defining_section_parametrization = Dict{String, MPolyRingElem}()
end

# Extract defining_classes
if haskey(s, :defining_classes)
defining_classes = load_typed_object(s, :defining_classes)
else
defining_classes = Dict{String, ToricDivisorClass}()
end

# Construct the model
model = WeierstrassModel(explicit_model_sections, defining_section_parametrization, pw, base_space, ambient_space)
model.defining_classes = defining_classes

# Set boolean attributes
bools = load_object(s, Vector, Bool, :boolean_data)
Expand Down
3 changes: 3 additions & 0 deletions experimental/FTheoryTools/test/weierstrass_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ w3 = literature_model(arxiv_id = "1208.2695", equation = "B.19", base_space = B2
@test ambient_space(w3) == ambient_space(loaded)
@test is_base_space_fully_specified(w3) == is_base_space_fully_specified(loaded)
@test is_partially_resolved(w3) == is_partially_resolved(loaded)
@test explicit_model_sections(w3) == explicit_model_sections(loaded)
@test defining_section_parametrization(w3) == defining_section_parametrization(loaded)
@test defining_classes(w3) == defining_classes(loaded)
end
end
end
Expand Down

0 comments on commit 133d1c4

Please sign in to comment.