Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for loading old .jld2 files #262

Open
ArneSpang opened this issue Mar 6, 2025 · 9 comments
Open

Workaround for loading old .jld2 files #262

ArneSpang opened this issue Mar 6, 2025 · 9 comments

Comments

@ArneSpang
Copy link
Contributor

ArneSpang commented Mar 6, 2025

If you are loading an old .jld2 file that contains a GeoUnits object, you will encounter this warning

┌ Warning: saved type GeoUnits{GEO} is missing field chemicaldiffusion in workspace type; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/nPYlZ/src/data/reconstructing_datatypes.jl:193

If you then want to use dimensionalize with this GeoUnits object, you will get an error message because JLD2 was not able to properly load it. I discussed this with @albert-de-montserrat and we did not find a way to fix this, so I am showing a workaround for people that run into the same problem. This assumes that the GeoUnits object in your old file is called CD

julia> using GeoParams, JLD2

julia> d = load("oldFile.jld2");
┌ Warning: saved type GeoUnits{GEO} is missing field chemicaldiffusion in workspace type; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/nPYlZ/src/data/reconstructing_datatypes.jl:193

julia> CD = d["CD"];

julia> CD2 = GEO_units(length=CD.length, temperature=CD.temperature, stress=CD.stress, viscosity=CD.viscosity);

You can now use CD2 to inside dimensionalize and nondimensionalize again

@boriskaus
Copy link
Member

thanks for reporting. Perhaps its worthwhile to add an upgrade_GeoUnits function to GeoParams that does this?

@albert-de-montserrat
Copy link
Member

Note that this happens only if one tries to open a JLD2 file saved on GeoParams <= 0.6.8 using GeoParams >=0.7.0. The reasons is that chemical diffusion was added to GeoUnits in the latest GP versions so the old JLD2 file does not have it.

@boriskaus
Copy link
Member

I see that; yet it cannot be excluded that we have further additions in the future, which would be handled in that case by upgrading the function

@ArneSpang
Copy link
Contributor Author

ArneSpang commented Mar 6, 2025

function upgrade_GeoUnits(a) 
    return GEO_units(length=a.length, temperature=a.temperature, stress=a.stress, viscosity=a.viscosity) 
end

This would do the trick currently

@boriskaus
Copy link
Member

I would slightly modify it:

function upgrade_GeoUnits(a::GEO_units) 
    return GEO_units(length=a.length, temperature=a.temperature, stress=a.stress, viscosity=a.viscosity) 
end

can you make a PR?

@ArneSpang
Copy link
Contributor Author

I would slightly modify it:

function upgrade_GeoUnits(a::GEO_units)
return GEO_units(length=a.length, temperature=a.temperature, stress=a.stress, viscosity=a.viscosity)
end

can you make a PR?

I don't think this one works because a will be some weird type

julia> CD = d["CD"]
Reconstruct@GeoUnits{GEO}(Any[600 °C, 10 km, 100 MPa, 0.03168808781402895 ❓, 1.0e20 Pa s, 17463//20 K, 1.0e12 s, 10000 m, 100000000 Pa, 1.0e36 kg, 10000 m, 1.0e36 kg, 1.0e12 s, 17463//20 K, 1 mol, 1.0e12 s, 1.0e16 kg m s^-2.0, 1.0e20 kg m^2.0 s^-2.0, 1.0e8 kg m^2.0 s^-3.0, 100000000 m^2.0, 1000000000000 m^3.0, 1.0e-8 m s^-1.0, 1.0e24 kg m^-3.0, 1.0e-20 m s^-2.0, 1.0e16 kg m s^-2.0, 1.0e-12 s^-1.0, 1.1452785890167782e-19 m^2.0 K^-1.0 s^-2.0, 11.452785890167783 kg m K^-1.0 s^-3.0, 3.15576e7, 1.0e6, 3.15576e9])

@ArneSpang
Copy link
Contributor Author

Would have to be this:

function upgrade_GeoUnits(a::JLD2.ReconstructedMutable)
    return GEO_units(length=a.length, temperature=a.temperature, stress=a.stress, viscosity=a.viscosity) 
end

for a PR, where would I put it?

@albert-de-montserrat
Copy link
Member

I guess it should go into Units.jl

@albert-de-montserrat
Copy link
Member

albert-de-montserrat commented Mar 6, 2025

Would have to be this:

function upgrade_GeoUnits(a::JLD2.ReconstructedMutable)
return GEO_units(length=a.length, temperature=a.temperature, stress=a.stress, viscosity=a.viscosity)
end

for a PR, where would I put it?

This will fail as JLD2 is not in the Project.toml of GeoParams. I would leave it fully generic without type signature. It will crash anyway if a is of the wrong type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants