Add write_jld2, reformat code

This commit is contained in:
2023-06-08 11:36:08 -05:00
parent b82a984ab1
commit d6025c5f4a
14 changed files with 137 additions and 121 deletions

View File

@@ -8,6 +8,7 @@ Clp = "e2554f3b-3117-50c0-817c-e040a3ddf72d"
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
@@ -15,3 +16,7 @@ MIPLearn = "2b1277c3-b477-4c49-a15e-7ba350325c68"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[compat]
JuMP = "1"
julia = "1"

BIN
test/fixtures/bell5.h5 vendored

Binary file not shown.

View File

@@ -3,9 +3,16 @@
# Released under the modified BSD license. See COPYING.md for more details.
using MIPLearn
using JLD2
struct _TestStruct
n::Int
q::Vector{Float64}
end
function test_io()
test_pkl_gz()
test_jld2()
test_h5()
end
@@ -32,6 +39,26 @@ function test_h5()
h5.close()
end
function test_jld2()
dirname = mktempdir()
data = [
_TestStruct(1, [0.0, 0.0, 0.0]),
_TestStruct(2, [1.0, 2.0, 3.0]),
_TestStruct(3, [3.0, 3.0, 3.0]),
]
filenames = write_jld2(data, dirname, prefix="obj")
@test all(
filenames .==
["$dirname/obj00001.jld2", "$dirname/obj00002.jld2", "$dirname/obj00003.jld2"],
)
@assert isfile("$dirname/obj00001.jld2")
@assert isfile("$dirname/obj00002.jld2")
@assert isfile("$dirname/obj00003.jld2")
recovered = read_jld2("$dirname/obj00002.jld2")
@test recovered.n == 2
@test all(recovered.q .== [1.0, 2.0, 3.0])
end
function _test_roundtrip_scalar(h5, original)
h5.put_scalar("key", original)
recovered = h5.get_scalar("key")