Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into adv/serialize-many-…
Browse files Browse the repository at this point in the history
…to-one
  • Loading branch information
antonydellavecchia committed Nov 21, 2024
2 parents c84fb14 + 5a737af commit 4d1a3ff
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Serialization/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function save_object(s::SerializerState, K::FqField)
save_object(s, order(K))
else
save_data_dict(s) do
save_typed_object(s, defining_polynomial(K))
save_typed_object(s, defining_polynomial(K), :def_pol)
end
end
end
Expand All @@ -202,7 +202,7 @@ function load_object(s::DeserializerState, ::Type{<: FqField})
order = ZZRingElem(node)
return finite_field(order)[1]
else
def_pol = load_typed_object(s)
def_pol = load_typed_object(s, :def_pol)
return finite_field(def_pol, cached=false)[1]
end
end
Expand Down
24 changes: 24 additions & 0 deletions src/Serialization/Upgrades/1.3.0.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
push!(upgrade_scripts_set, UpgradeScript(
v"1.3.0",
function upgrade_1_3_0(s::UpgradeState, dict::Dict)
upgraded_dict = dict
if haskey(dict, :_type) && dict[:_type] == "FqField"
if dict[:data] isa Dict
if !(haskey(dict[:data], :def_pol))
upgraded_dict[:data][:def_pol] = copy(dict[:data])
end
end
elseif haskey(dict, :data) && dict[:data] isa Dict
upgraded_dict[:data] = upgrade_1_3_0(s, dict[:data])
end
if haskey(dict, :_refs)
upgraded_refs = Dict()
for (k, v) in dict[:_refs]
upgraded_refs[k] = upgrade_1_3_0(s, v)
end
upgraded_dict[:_refs] = upgraded_refs
end

return upgraded_dict
end
))
1 change: 1 addition & 0 deletions src/Serialization/Upgrades/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ include("0.13.0.jl")
include("0.15.0.jl")
include("1.1.0.jl")
include("1.2.0.jl")
include("1.3.0.jl")

const upgrade_scripts = collect(upgrade_scripts_set)
sort!(upgrade_scripts; by=version)
Expand Down
38 changes: 23 additions & 15 deletions test/Serialization/loading.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
@testset "loading" begin

@testset "loading Vector{LinearProgram}" begin
c = cube(3)
LP0 = linear_program(c, [2,2,-3])
LP1 = linear_program(c, [2,2,4])
v = [LP0, LP1]
loaded = load(joinpath(@__DIR__,"vlp.json"))
@test length(v) == length(loaded)
@test feasible_region(loaded[1]) == feasible_region(loaded[2])
@test feasible_region(loaded[1]) == feasible_region(LP0)
@test objective_function(loaded[1]) == objective_function(v[1])
@test objective_function(loaded[2]) == objective_function(v[2])
@test optimal_value(loaded[1]) == optimal_value(v[1])
@test optimal_value(loaded[2]) == optimal_value(v[2])
end
@testset "loading file format paper example" begin
F = GF(7, 2)
o = gen(F)
Fyz, (y, z) = F[:x, :y]
load(joinpath(@__DIR__,"polynomial-example.mrdi");)
loaded = load(joinpath(@__DIR__,"polynomial-example.mrdi"); params=Fyz)
@test loaded == 2*y^3*z^4 + 5*o*y + (o + 3)*z^2 + 1
end

@testset "loading Vector{LinearProgram}" begin
c = cube(3)
LP0 = linear_program(c, [2,2,-3])
LP1 = linear_program(c, [2,2,4])
v = [LP0, LP1]
loaded = load(joinpath(@__DIR__,"vlp.json"))
@test length(v) == length(loaded)
@test feasible_region(loaded[1]) == feasible_region(loaded[2])
@test feasible_region(loaded[1]) == feasible_region(LP0)
@test objective_function(loaded[1]) == objective_function(v[1])
@test objective_function(loaded[2]) == objective_function(v[2])
@test optimal_value(loaded[1]) == optimal_value(v[1])
@test optimal_value(loaded[2]) == optimal_value(v[2])
end
end
36 changes: 36 additions & 0 deletions test/Serialization/polynomial-example.mrdi
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"_ns": { "Oscar": [ "https://github.com/oscar-system/Oscar.jl", "1.0.0" ] },
"_type": {
"name": "MPolyRingElem",
"params": "869a359a-43d3-43f4-9821-0af9346be019"
},
"data": [[["3", "4"], [["0", "2"]]],
[["0", "2"], [["0", "3"], ["1", "1"]]],
[["1", "0"], [["1", "5"]]],
[["0", "0"], [["0", "1"]]]],
"_refs": {
"152ac7bd-e85a-4b36-acc2-743ade2cad4f": {
"data": { "base_ring": { "data": "7", "_type": "FqField"},
"symbols": ["x"] },
"_type": "PolyRing"
},
"869a359a-43d3-43f4-9821-0af9346be019": {
"data": {
"base_ring": "a8309b96-caec-443c-bedb-e23bb0634c14",
"symbols": [ "y", "z" ]
},
"_type": "MPolyRing" },
"a8309b96-caec-443c-bedb-e23bb0634c14": {
"data": {
"def_pol": {
"data": [["0", "1"], ["2", "1"]],
"_type": {
"name": "PolyRingElem",
"params": "152ac7bd-e85a-4b36-acc2-743ade2cad4f"
}
}
},
"_type": "FqField"
}
}
}
11 changes: 11 additions & 0 deletions test/Serialization/upgrades/GF_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"_ns": {
"Oscar": [
"https://github.com/oscar-system/Oscar.jl",
"1.2.0"
]
},
"_type": "FqField",
"data": "2",
"id": "4e298c21-11cb-45f1-bac0-62e2df5e6454"
}
45 changes: 45 additions & 0 deletions test/Serialization/upgrades/GF_2_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"_ns": {
"Oscar": [
"https://github.com/oscar-system/Oscar.jl",
"1.2.0"
]
},
"_refs": {
"15ec4d5e-409d-4e80-a7a2-aa1b22b0db9d": {
"_type": "PolyRing",
"data": {
"base_ring": "4e298c21-11cb-45f1-bac0-62e2df5e6454",
"symbols": [
"x"
]
}
},
"4e298c21-11cb-45f1-bac0-62e2df5e6454": {
"_type": "FqField",
"data": "2"
}
},
"_type": "FqField",
"data": {
"_type": {
"name": "PolyRingElem",
"params": "15ec4d5e-409d-4e80-a7a2-aa1b22b0db9d"
},
"data": [
[
"0",
"1"
],
[
"1",
"1"
],
[
"2",
"1"
]
]
},
"id": "b2e7bf06-d89a-4fea-8bf4-215a61c16ca2"
}
110 changes: 110 additions & 0 deletions test/Serialization/upgrades/poly1.0.5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"_ns": {
"Oscar": [
"https://github.com/oscar-system/Oscar.jl",
"1.0.5"
]
},
"_type": {
"name": "MPolyRingElem",
"params": "f0885e3e-71ff-4813-88fd-7ee05eeb3657"
},
"data": [
[
[
"3",
"4"
],
[
[
"0",
"2"
]
]
],
[
[
"1",
"0"
],
[
[
"1",
"5"
]
]
],
[
[
"0",
"2"
],
[
[
"0",
"3"
],
[
"1",
"1"
]
]
],
[
[
"0",
"0"
],
[
[
"0",
"1"
]
]
]
],
"_refs": {
"f0885e3e-71ff-4813-88fd-7ee05eeb3657": {
"_type": "MPolyRing",
"data": {
"base_ring": "e06a6ac9-954b-4fb7-89c6-f2a25489440e",
"symbols": [
"y",
"z"
]
}
},
"e06a6ac9-954b-4fb7-89c6-f2a25489440e": {
"_type": "FqField",
"data": {
"_type": {
"name": "PolyRingElem",
"params": "3a66dcbd-bd73-4bb7-8b99-42d9f5177893"
},
"data": [
[
"0",
"1"
],
[
"2",
"1"
]
]
}
},
"3a66dcbd-bd73-4bb7-8b99-42d9f5177893": {
"_type": "PolyRing",
"data": {
"base_ring": "221dfa92-69df-4b5a-8f30-166aafddfaa9",
"symbols": [
"x"
]
}
},
"221dfa92-69df-4b5a-8f30-166aafddfaa9": {
"_type": "FqField",
"data": "7"
}
}
}
7 changes: 7 additions & 0 deletions test/Serialization/upgrades/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@
loaded = load(joinpath(@__DIR__, "file_version_less_than_1.2.0.json"));
@test loaded isa Dict
end

@testset "< 1.3.0 Upgrade" begin
load(joinpath(@__DIR__, "GF_2_2.json"));
load(joinpath(@__DIR__, "GF_2.json"));
Oscar.reset_global_serializer_state()
load(joinpath(@__DIR__, "poly1.0.5.json"));
end
end

0 comments on commit 4d1a3ff

Please sign in to comment.