-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into th/buuuump
- Loading branch information
Showing
23 changed files
with
503 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 34 additions & 64 deletions
98
experimental/FTheoryTools/src/Serialization/hypersurface_models.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,81 @@ | ||
@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 | ||
############################################################################ | ||
|
||
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), | ||
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) | ||
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 | ||
|
||
# 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 | ||
!isempty(attrs_dict) && save_typed_object(s, attrs_dict, :__attrs) | ||
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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.