From 7e31ff80925c7e46213a71b2471370b533df18c4 Mon Sep 17 00:00:00 2001 From: Martin Bies Date: Sat, 20 Jul 2024 12:49:15 +0200 Subject: [PATCH] [FTheoryTools] Overhaul serialization of Tate models --- .../src/Serialization/tate_models.jl | 139 ++++-------------- experimental/FTheoryTools/test/tate_models.jl | 22 +++ 2 files changed, 47 insertions(+), 114 deletions(-) diff --git a/experimental/FTheoryTools/src/Serialization/tate_models.jl b/experimental/FTheoryTools/src/Serialization/tate_models.jl index 2be6a0b843da..120ed2b1c054 100644 --- a/experimental/FTheoryTools/src/Serialization/tate_models.jl +++ b/experimental/FTheoryTools/src/Serialization/tate_models.jl @@ -1,7 +1,5 @@ @register_serialization_type GlobalTateModel uses_params - - ########################################################################### # This function saves the types of the data that define a global Tate model ########################################################################### @@ -9,57 +7,21 @@ 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) + 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) + end 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) - end - end end end + ########################################################################### # This function loads the types of the data that define a global Tate model ########################################################################### @@ -68,98 +30,47 @@ function load_type_params(s::DeserializerState, ::Type{<: GlobalTateModel}) 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 - 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 + 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 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)) end 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 + set_attribute!(model, :partially_resolved, load_object(s, Vector{Bool}, :boolean_data)[1]) return model end diff --git a/experimental/FTheoryTools/test/tate_models.jl b/experimental/FTheoryTools/test/tate_models.jl index a8cf412f261c..3f2fbfb8b3b8 100644 --- a/experimental/FTheoryTools/test/tate_models.jl +++ b/experimental/FTheoryTools/test/tate_models.jl @@ -53,6 +53,28 @@ t2 = literature_model(arxiv_id = "1109.3454", equation = "3.1", base_space = B3, end end +t2_copy = global_tate_model(sample_toric_variety(); completeness_check = false) + +@testset "Saving and loading Weierstrass models over concrete base space" begin + mktempdir() do path + test_save_load_roundtrip(path, t2_copy) do loaded + @test tate_polynomial(t2_copy) == tate_polynomial(loaded) + @test tate_section_a1(t2_copy) == tate_section_a1(loaded) + @test tate_section_a2(t2_copy) == tate_section_a2(loaded) + @test tate_section_a3(t2_copy) == tate_section_a3(loaded) + @test tate_section_a4(t2_copy) == tate_section_a4(loaded) + @test tate_section_a6(t2_copy) == tate_section_a6(loaded) + @test base_space(t2_copy) == base_space(loaded) + @test ambient_space(t2_copy) == ambient_space(loaded) + @test is_base_space_fully_specified(t2_copy) == is_base_space_fully_specified(loaded) + @test is_partially_resolved(t2_copy) == is_partially_resolved(loaded) + @test explicit_model_sections(t2_copy) == explicit_model_sections(loaded) + @test defining_section_parametrization(t2_copy) == defining_section_parametrization(loaded) + @test defining_classes(t2_copy) == defining_classes(loaded) + end + end +end + Kbar = anticanonical_bundle(base_space(t)) my_choice = Dict("a1" => basis_of_global_sections(Kbar)[1]) my_choice["a2"] = basis_of_global_sections(Kbar^2)[1]