Saving/exporting objects on hard drive

I am trying to save/export objects in memory to my hard drive. I have found two packages that should allow me to do that: JLD and JLD2. However, both only return errors.
Has anyone an idea on how to do that/where my error is?
Here is a minimal example:

# With JLD
using JLD
A = [1 2 3 4
     1 2 3 4]
B = "somestring"

status_dict = Dict([("A",A),
                    ("B", B)])
save("my_obj.jld", "status_dict",status_dict)

This returns the error:

β”Œ Warning: JLD incorrectly extends FileIO functions (see FileIO documentation)
β”” @ FileIO C:\Users\user\.julia\packages\FileIO\aP78L\src\loadsave.jl:217
Error encountered while save File{DataFormat{:JLD}, String}("my_obj.jld").

Fatal error:
ERROR: type DataType has no field mutable

When I try to use JLD2 instead the following happens

# With JLD2
using JLD2, FileIO

A = [1 2 3 4
     1 2 3 4]
B = "somestring"

status_dict = Dict([("A",A),
                    ("B", B)])

@save "example.jld2" status_dict

The same error appears

ERROR: type DataType has no field mutable

The same error appears when I use the save() function instead of the macro as described in their Readme (Readme Β· JLD2.jl).

One post I read suggested that this might be caused by having an old version of JLD and JLD2. However, when I try to update both, they stay on their old versions:

βŒƒ [4138dd39] JLD v0.10.0
βŒƒ [033835bb] JLD2 v0.4.3

even though there should be newer versions available. Any idea on why they are not updating?

Your code works for me, I obtained [4138dd39] JLD v0.13.2 when I tried.

Any idea on why they are not updating?

If you’re on Julia 1.8, there’s help in:

pkg> status --outdated which shows any packages that are not at their latest version and if any packages are holding them back.

1 Like

JLD2 v0.4.3 is also quite outdated.
The most recent release is v0.4.28

1 Like

Thanks!
The result shows that they are way behind the latest version:

βŒƒ [4138dd39] JLD v0.10.0 (<v0.13.2)
βŒƒ [033835bb] JLD2 v0.4.3 (<v0.4.28)

The green hat on the left even indicates that a new version is available and can be installed. However, when I update packages with Pkg.update() it stays on the same version.

OK, I removed both packages and reinstalled them with the specific newest version number. It seems like at least for JLD2.jl, Plots.jl and JuliaDB.jl prevented the update. Which is a bit weird because it was not shown when I ran Pkg> status --outdated -m. Deinstalling both resolved the issue.

It works now. However, there is an error when I try to save a Dictionary:

ERROR: HDF5.API.H5Error: Error getting the number of members

Any ideas?

However, when I update packages with Pkg.update() it stays on the same version.

Yes, this is a commonly experienced issue:

1 Like