Skip to content

Commit

Permalink
[FTheoryTools] Save more attributes upon serialization
Browse files Browse the repository at this point in the history
HereAround authored and antonydellavecchia committed Jul 22, 2024
1 parent 461760c commit 6cf5724
Showing 6 changed files with 49 additions and 16 deletions.
17 changes: 12 additions & 5 deletions experimental/FTheoryTools/src/Serialization/hypersurface_models.jl
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ 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),
@@ -50,9 +50,13 @@ function save_object(s::SerializerState, h::HypersurfaceModel)
end
save_object(s, hypersurface_equation(h), :hypersurface_equation)
save_object(s, hypersurface_equation_parametrization(h), :hypersurface_equation_parametrization)
save_data_array(s, :boolean_data) do
save_object(s, is_partially_resolved(h))
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
!isempty(attrs_dict) && save_typed_object(s, attrs_dict, :__attrs)
end
end

@@ -61,14 +65,17 @@ end
# This function loads a hypersurface model
##########################################

function load_object(s::DeserializerState, ::Type{<: HypersurfaceModel}, params::Tuple{NormalToricVariety, NormalToricVariety, NormalToricVariety, <:MPolyRing, <:MPolyRing})
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)
model.defining_classes = defining_classes
set_attribute!(model, :partially_resolved, load_object(s, Vector{Bool}, :boolean_data)[1])
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
13 changes: 10 additions & 3 deletions experimental/FTheoryTools/src/Serialization/tate_models.jl
Original file line number Diff line number Diff line change
@@ -52,9 +52,13 @@ function save_object(s::SerializerState, gtm::GlobalTateModel)
!isempty(data) && save_typed_object(s, data, key)
end
save_object(s, tate_polynomial(gtm), :tate_polynomial)
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

@@ -71,6 +75,9 @@ function load_object(s::DeserializerState, ::Type{<: GlobalTateModel}, params::T
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)
model.defining_classes = defining_classes
set_attribute!(model, :partially_resolved, load_object(s, Vector{Bool}, :boolean_data)[1])
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
13 changes: 10 additions & 3 deletions experimental/FTheoryTools/src/Serialization/weierstrass_models.jl
Original file line number Diff line number Diff line change
@@ -52,9 +52,13 @@ function save_object(s::SerializerState, w::WeierstrassModel)
!isempty(data) && save_typed_object(s, data, key)
end
save_object(s, weierstrass_polynomial(w), :weierstrass_polynomial)
save_data_array(s, :boolean_data) do
save_object(s, is_partially_resolved(w))
attrs_dict = Dict{Symbol, Any}()
for (key, value) in w.__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

@@ -71,6 +75,9 @@ function load_object(s::DeserializerState, ::Type{<: WeierstrassModel}, params::
defining_classes = haskey(s, :defining_classes) ? load_typed_object(s, :defining_classes) : Dict{String, ToricDivisorClass}()
model = WeierstrassModel(explicit_model_sections, defining_section_parametrization, pw, base_space, ambient_space)
model.defining_classes = defining_classes
set_attribute!(model, :partially_resolved, load_object(s, Vector{Bool}, :boolean_data)[1])
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
10 changes: 7 additions & 3 deletions experimental/FTheoryTools/test/hypersurface_models.jl
Original file line number Diff line number Diff line change
@@ -46,17 +46,21 @@ end
Kbar = anticanonical_divisor(B3)
foah1_B3 = literature_model(arxiv_id = "1408.4808", equation = "3.4", type = "hypersurface", base_space = B3, defining_classes = Dict("s7" => Kbar, "s9" => Kbar), completeness_check = false)

@testset "Saving and loading hypersurface literature model" begin
@testset "Saving and loading hypersurface literature model and some of their attributes" begin
mktempdir() do path
test_save_load_roundtrip(path, foah1_B3) do loaded
@test hypersurface_equation(foah1_B3) == hypersurface_equation(loaded)
@test base_space(foah1_B3) == base_space(loaded)
@test is_base_space_fully_specified(foah1_B3) == is_base_space_fully_specified(loaded)
@test ambient_space(foah1_B3) == ambient_space(loaded)
@test fiber_ambient_space(foah1_B3) == fiber_ambient_space(loaded)
@test is_base_space_fully_specified(foah1_B3) == is_base_space_fully_specified(loaded)
@test is_partially_resolved(foah1_B3) == is_partially_resolved(loaded)
@test explicit_model_sections(foah1_B3) == explicit_model_sections(loaded)
@test defining_classes(foah1_B3) == defining_classes(loaded)
for (key, value) in foah1_B3.__attrs
if value isa String || value isa Vector{String} || value isa Bool
@test foah1_B3.__attrs[key] == loaded.__attrs[key]
end
end
end
end
end
6 changes: 5 additions & 1 deletion experimental/FTheoryTools/test/tate_models.jl
Original file line number Diff line number Diff line change
@@ -48,7 +48,11 @@ t2 = literature_model(arxiv_id = "1109.3454", equation = "3.1", base_space = B3,
@test base_space(t2) == base_space(loaded)
@test ambient_space(t2) == ambient_space(loaded)
@test is_base_space_fully_specified(t2) == is_base_space_fully_specified(loaded)
@test is_partially_resolved(t2) == is_partially_resolved(loaded)
for (key, value) in t2.__attrs
if value isa String || value isa Vector{String} || value isa Bool
@test t2.__attrs[key] == loaded.__attrs[key]
end
end
end
end
end
6 changes: 5 additions & 1 deletion experimental/FTheoryTools/test/weierstrass_models.jl
Original file line number Diff line number Diff line change
@@ -43,10 +43,14 @@ w3 = literature_model(arxiv_id = "1208.2695", equation = "B.19", base_space = B2
@test base_space(w3) == base_space(loaded)
@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)
for (key, value) in w3.__attrs
if value isa String || value isa Vector{String} || value isa Bool
@test w3.__attrs[key] == loaded.__attrs[key]
end
end
end
end
end

0 comments on commit 6cf5724

Please sign in to comment.