Skip to content

Commit

Permalink
Progress on serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
HechtiDerLachs committed Sep 18, 2024
1 parent 5e0aa27 commit 7ac8e7d
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 25 deletions.
38 changes: 13 additions & 25 deletions src/Serialization/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
188 changes: 188 additions & 0 deletions src/Serialization/Schemes.jl
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions test/Serialization/schemes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit 7ac8e7d

Please sign in to comment.