JuliaIO / JLD2.jl

HDF5-compatible file format in pure Julia
Other
560 stars 92 forks source link

DRAFT: env + binary blobs #377

Closed JonasIsensee closed 1 month ago

JonasIsensee commented 2 years ago

This is a demonstration implementation of two things inspired by JLSO.jl

It adds definition write_env(f), has_env(f), read_env(f) and Pkg.activate(f::JLDFile) to write, check, read, and activate an environment stored in a file.

It also adds a proof of concept custom serialization Blob. Blob has a single field of type Any that gets serialized using Serialization.serialize.

julia> f = jldopen("test2.jld2", "w")
JLDFile /home/jonas/.julia/dev/JLD2/test2.jld2 (read/write)
  (no datasets)

julia> JLD2.write_blob(f, "h", ()->rand(2,2))

julia> close(f)

## new session

julia> d = load("test2.jld2")
Dict{String, Any} with 1 entry:
  "h" => Blob(#7)

julia> d["h"].obj()
2×2 Matrix{Float64}:
 0.983637  0.0874438
 0.641339  0.81356

alternatively write jldsave("test.jld2"; a=JLD2.Blob(()->rand(3,3)))

a proper API for wrapping and unwrapping in Blobs could of course be built.

EDIT: it might be better to store the enviroment metadata as attributes.

codecov[bot] commented 2 years ago

Codecov Report

Base: 88.57% // Head: 83.26% // Decreases project coverage by -5.30% :warning:

Coverage data is based on head (3abc785) compared to base (35baacc). Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #377 +/- ## ========================================== - Coverage 88.57% 83.26% -5.31% ========================================== Files 29 32 +3 Lines 2896 4136 +1240 ========================================== + Hits 2565 3444 +879 - Misses 331 692 +361 ``` | [Impacted Files](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO) | Coverage Δ | | |---|---|---| | [src/JLD2.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL0pMRDIuamw=) | `89.65% <0.00%> (-2.90%)` | :arrow_down: | | [src/metadata.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL21ldGFkYXRhLmps) | `0.00% <0.00%> (ø)` | | | [src/write\_blob.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL3dyaXRlX2Jsb2Iuamw=) | `0.00% <0.00%> (ø)` | | | [src/object\_headers.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL29iamVjdF9oZWFkZXJzLmps) | `38.37% <0.00%> (-43.11%)` | :arrow_down: | | [src/data/number\_types.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL2RhdGEvbnVtYmVyX3R5cGVzLmps) | `73.68% <0.00%> (-20.44%)` | :arrow_down: | | [src/backwards\_compatibility.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL2JhY2t3YXJkc19jb21wYXRpYmlsaXR5Lmps) | `37.00% <0.00%> (-18.56%)` | :arrow_down: | | [src/misc.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL21pc2Muamw=) | `76.82% <0.00%> (-16.51%)` | :arrow_down: | | [src/attributes.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL2F0dHJpYnV0ZXMuamw=) | `89.65% <0.00%> (-10.35%)` | :arrow_down: | | [src/data/specialcased\_types.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL2RhdGEvc3BlY2lhbGNhc2VkX3R5cGVzLmps) | `90.20% <0.00%> (-5.83%)` | :arrow_down: | | [src/global\_heaps.jl](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO#diff-c3JjL2dsb2JhbF9oZWFwcy5qbA==) | `93.90% <0.00%> (-3.51%)` | :arrow_down: | | ... and [14 more](https://codecov.io/gh/JuliaIO/JLD2.jl/pull/377/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO) | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaIO)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

JonasIsensee commented 2 years ago

Hey @oxinabox, your ridiculously fast response to me closing issue #57 inspired me to give this some thought again. I'm still not sure what the best option is or whether there's a good way to integrate JLD2/HDF5 as an "object" format in JLSO.

However, I noticed that I can actually add some of the nice features of JLSO to JLD2 with fairly little effort. Just pinging for your thoughts / opinion

oxinabox commented 2 years ago

I think this is a nice idea