From 7556ab6edf136ac55a85f94784a5947f676b60d9 Mon Sep 17 00:00:00 2001 From: Martin Bies Date: Sat, 20 Jul 2024 14:32:02 +0200 Subject: [PATCH] [FTheoryTools] Overhaul serialization of hypersurface models --- .../src/Serialization/hypersurface_models.jl | 87 ++++++------------- .../FTheoryTools/test/hypersurface_models.jl | 20 +++++ 2 files changed, 45 insertions(+), 62 deletions(-) diff --git a/experimental/FTheoryTools/src/Serialization/hypersurface_models.jl b/experimental/FTheoryTools/src/Serialization/hypersurface_models.jl index f4035e5d3f96..2be54578cc75 100644 --- a/experimental/FTheoryTools/src/Serialization/hypersurface_models.jl +++ b/experimental/FTheoryTools/src/Serialization/hypersurface_models.jl @@ -1,36 +1,23 @@ @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 ############################################################################ @@ -41,71 +28,47 @@ function load_type_params(s::DeserializerState, ::Type{<: HypersurfaceModel}) 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) - 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 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 + set_attribute!(model, :partially_resolved, load_object(s, Vector{Bool}, :boolean_data)[1]) return model end diff --git a/experimental/FTheoryTools/test/hypersurface_models.jl b/experimental/FTheoryTools/test/hypersurface_models.jl index 36c242eabb10..975a71d00dea 100644 --- a/experimental/FTheoryTools/test/hypersurface_models.jl +++ b/experimental/FTheoryTools/test/hypersurface_models.jl @@ -37,6 +37,26 @@ end @test fiber_ambient_space(h) == fiber_ambient_space(loaded) @test is_base_space_fully_specified(h) == is_base_space_fully_specified(loaded) @test is_partially_resolved(h) == is_partially_resolved(loaded) + @test explicit_model_sections(h) == explicit_model_sections(loaded) + @test defining_classes(h) == defining_classes(loaded) + end + end +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 + 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 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) end end end