From 7ac8e7d64a07ce7a70aa19224f189515066ea92b Mon Sep 17 00:00:00 2001 From: HechtiDerLachs Date: Wed, 18 Sep 2024 17:03:26 +0200 Subject: [PATCH] Progress on serialization. --- src/Serialization/Rings.jl | 38 +++---- src/Serialization/Schemes.jl | 188 ++++++++++++++++++++++++++++++++++ test/Serialization/schemes.jl | 16 +++ 3 files changed, 217 insertions(+), 25 deletions(-) create mode 100644 src/Serialization/Schemes.jl diff --git a/src/Serialization/Rings.jl b/src/Serialization/Rings.jl index 23e62fe5ff73..06dd66d3b034 100644 --- a/src/Serialization/Rings.jl +++ b/src/Serialization/Rings.jl @@ -736,6 +736,19 @@ function load_object(s::DeserializerState, ::Type{MPolyQuoRing}) return MPolyQuoRing(R, I, o) end +@register_serialization_type MPolyQuoRingElem uses_params + +function save_object(s::SerializerState, a::MPolyQuoRingElem) + save_object(s, lift(a)) +end + +function load_object(s::DeserializerState, ::Type{<:MPolyQuoRingElem}, prts::Vector) + Q = prts[end]::MPolyQuoRing + R = base_ring(Q) + rep = load_object(s, elem_type(R), R) + return Q(rep) +end + ### Serialization of Monomial orderings @register_serialization_type MonomialOrdering uses_params @@ -892,31 +905,6 @@ end ### Morphisms of the four types of rings -#= -@register_serialization_type MPolyAnyMap uses_id - -function save_object(s::SerializerState, phi::MPolyAnyMap) - save_data_dict(s) do - save_typed_object(s, domain(phi), :domain) - save_typed_object(s, codomain(phi), :codomain) - _has_coefficient_map(phi) && save_object(s, coefficient_map(phi), :coeff_map) - save_object(s, _images(phi), :img_gens) - end -end - -function load_object(s::DeserializerState, ::Type{<:MPolyAnyMap}) - dom = load_typed_object(s, :domain) - cod = load_typed_object(s, :codomain) - img_gens = load_object(s, :img_gens) - if haskey(s, :coeff_map) - coeff_map = load_object(s, :coeff_map) - return hom(dom, cod, coeff_map, img_gens) - end - return hom(dom, cod, img_gens) -end -=# - - @register_serialization_type MPolyLocalizedRingHom uses_id function save_object(s::SerializerState, phi::MPolyLocalizedRingHom) diff --git a/src/Serialization/Schemes.jl b/src/Serialization/Schemes.jl new file mode 100644 index 000000000000..0aa62217e9f5 --- /dev/null +++ b/src/Serialization/Schemes.jl @@ -0,0 +1,188 @@ +### affine schemes + +@register_serialization_type AffineScheme uses_id + +function save_object(s::SerializerState, X::AffineScheme) + save_data_dict(s) do + save_typed_object(s, OO(X), :coordinate_ring) + end +end + +function load_object(s::DeserializerState, ::Type{<:AffineScheme}) + R = load_typed_object(s, :coordinate_ring) + return AffineScheme(R) +end + +@register_serialization_type AffineVariety uses_id + +function save_object(s::SerializerState, X::AffineVariety) + save_data_dict(s) do + save_typed_object(s, underlying_scheme(X), :underlying_scheme) + end +end + +function load_object(s::DeserializerState, ::Type{<:AffineVariety}) + X = load_typed_object(s, :underlying_scheme) + return AffineVariety(X; check=false) +end + +@register_serialization_type AffineAlgebraicSet uses_id + +function save_object(s::SerializerState, X::AffineAlgebraicSet) + save_data_dict(s) do + save_typed_object(s, underlying_scheme(X), :underlying_scheme) + # TODO: Also save the reduced version of X if any. + end +end + +function load_object(s::DeserializerState, ::Type{<:AffineAlgebraicSet}) + X = load_typed_object(s, :underlying_scheme) + return AffineAlgebraicSet(X) +end + +@register_serialization_type PrincipalOpenSubset uses_id + +function save_object(s::SerializerState, X::PrincipalOpenSubset) + save_data_dict(s) do + save_typed_object(s, underlying_scheme(X), :underlying_scheme) + save_typed_object(s, ambient_scheme(X), :ambient_scheme) + save_typed_object(s, complement_equations(X), :comp_eqns) + end +end + +function load_object(s::DeserializerState, ::Type{<:PrincipalOpenSubset}) + U = load_typed_object(s, :underlying_scheme) + eqns = load_typed_object(s, :comp_eqns) + X = load_typed_object(s, :ambient_scheme) + return PrincipalOpenSubset(X, U, eqns; check=false) +end + +@register_serialization_type AffineSchemeMor uses_id + +function save_object(s::SerializerState, f::AffineSchemeMor) + save_data_dict(s) do + save_typed_object(s, domain(f), :domain) + save_typed_object(s, codomain(f), :codomain) + save_typed_object(s, pullback(f), :pullback) + end +end + +function load_object(s::DeserializerState, ::Type{<:AffineSchemeMor}) + X = load_typed_object(s, :domain) + Y = load_typed_object(s, :codomain) + pbf = load_typed_object(s, :pullback) + return AffineSchemeMor(X, Y, pbf; check=false) +end + +@register_serialization_type SimpleGluing uses_id + +function save_object(s::SerializerState, glue::SimpleGluing) + save_data_dict(s) do + A, B = patches(glue) + f, g = gluing_morphisms(glue) + save_typed_object(s, A, :first_patch) + save_typed_object(s, B, :second_patch) + save_typed_object(s, f, :first_map) + save_typed_object(s, g, :second_map) + end +end + +function load_object(s::DeserializerState, ::Type{<:SimpleGluing}) + A = load_typed_object(s, :first_patch) + B = load_typed_object(s, :second_patch) + f = load_typed_object(s, :first_map) + g = load_typed_object(s, :second_map) + return SimpleGluing(A, B, f, g; check=false) +end + +@register_serialization_type LazyGluing uses_id + +function save_object(s::SerializerState, glue::LazyGluing) + save_data_dict(s) do + A, B = patches(glue) + gd = glue.GD + save_typed_object(s, A, :first_patch) + save_typed_object(s, B, :second_patch) + save_typed_object(s, gd, :gluing_data) + end +end + +function load_object(s::DeserializerState, ::Type{<:LazyGluing}) + A = load_typed_object(s, :first_patch) + B = load_typed_object(s, :second_patch) + gd = load_typed_object(s, :gluing_data) + return LazyGluing(A, B, gd) +end + +@register_serialization_type Covering uses_id + +function save_object(s::SerializerState, cov::Covering) + save_data_dict(s) do + save_typed_object(s, patches(cov), :patches) + # Sep. 18, 2024: Antony wants to refactor serialization of dictionaries. + # When that is done, we should clean up this bit here. + list = Tuple([(a, b) for (a, b) in gluings(cov)]) + save_typed_object(s, list, :gluings) + end +end + +function load_object(s::DeserializerState, ::Type{<:Covering}) + U = load_typed_object(s, :patches) + list = load_typed_object(s, :gluings) + dict = IdDict{Tuple{AbsAffineScheme, AbsAffineScheme}, AbsGluing}(a => b for (a, b) in list) + return Covering(U, dict; check=false) +end + +@register_serialization_type CoveredScheme uses_id + +function save_object(s::SerializerState, X::CoveredScheme) + save_data_dict(s) do + save_typed_object(s, default_covering(X), :default_covering) + # TODO: Look into whether or not to store refinements + # It might be possible that we do not even need this, but we probably + # have to clarify the assumptions made throughout the code here. + end +end + +function load_object(s::DeserializerState, ::Type{<:CoveredScheme}) + cov = load_typed_object(s, :default_covering) + return CoveredScheme(cov) +end + +@register_serialization_type CoveringMorphism uses_id + +function save_object(s::SerializerState, phi::CoveringMorphism) + save_data_dict(s) do + save_typed_object(s, domain(phi), :domain) + save_typed_object(s, codomain(phi), :codomain) + # TODO: Also clean up this part once the dicts are done. + list = Tuple([(U, f) for (U, f) in morphisms(phi)]) + save_typed_object(s, list, :morphisms) + end +end + +function load_object(s::DeserializerState, ::Type{<:CoveringMorphism}) + X = load_typed_object(s, :domain) + Y = load_typed_object(s, :codomain) + list = load_typed_object(s, :morphisms) + dict = IdDict{AbsAffineScheme, AbsAffineSchemeMor}(a => b for (a, b) in list) + return CoveringMorphism(X, Y, dict; check=false) +end + +@register_serialization_type CoveredSchemeMorphism uses_id + +function save_object(s::SerializerState, phi::CoveredSchemeMorphism) + save_data_dict(s) do + save_typed_object(s, domain(phi), :domain) + save_typed_object(s, codomain(phi), :codomain) + save_typed_object(s, covering_morphism(phi), :covering_morphism) + end +end + +function load_object(s::DeserializerState, ::Type{<:CoveredSchemeMorphism}) + X = load_typed_object(s, :domain) + Y = load_typed_object(s, :codomain) + cov_mor = load_typed_object(s, :covering_morphism) + return CoveredSchemeMorphism(X, Y, cov_mor) +end + diff --git a/test/Serialization/schemes.jl b/test/Serialization/schemes.jl index 7878fe26c9d5..f3ae550f5c85 100644 --- a/test/Serialization/schemes.jl +++ b/test/Serialization/schemes.jl @@ -113,6 +113,10 @@ end mktempdir() do path IP = projective_space(GF(29), 3) X = covered_scheme(IP) + test_save_load_roundtrip(path, X) do loaded + @test length(patches(default_covering(X))) == 4 + @test length(gluings(default_covering(X))) == 16 + end cov = default_covering(X) for U in affine_charts(X) for V in affine_charts(X) @@ -129,3 +133,15 @@ end end +@testset "covered schemes II" begin + mktempdir() do path + IA3 = affine_space(QQ, 3) + I = ideal(OO(IA3), gens(OO(IA3))) + pr = blow_up(IA3, I) + Y = domain(pr) + und = Oscar.underlying_morphism(pr) + test_save_load_roundtrip(path, und) do loaded + @test length(patches(default_covering(domain(und)))) == 3 + end + end +end