JLD2.jl icon indicating copy to clipboard operation
JLD2.jl copied to clipboard

Warning on attempt to save anonymous function

Open thisrod opened this issue 5 years ago • 2 comments

Consider the following.

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.3.0 (2019-11-26)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using JLD2

julia> A = Any[x->x]
1-element Array{var"#7#8",1}:
 var"#7#8"()

julia> @save "A.jld2" A

julia> exit()
$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.3.0 (2019-11-26)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using JLD2

julia> @load "A.jld2" A
┌ Warning: type Main.#9#10 does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/dev/JLD2/src/data.jl:1066
1-element Array{Symbol,1}:
 :A
    

I understand that it will never be practical to save anonymous functions in a HDF file. However, it would be helpful if @save raised a warning when you tried to do that.

Among other things, it would save users from repeatedly raising this issue.

I ran across this when I tried to save a DifferentialEquations.ODESolution. That is the kind of thing you want to save, and it would be nice to get a warning when the ODESolution for dx/dt = f(t,x) includes f as an anonymous function. Unless you read the source of DifferentialEquations, there is no reason you would guess that it did.

Related issues: #13 #86

thisrod avatar Jan 21 '20 04:01 thisrod

I ran across this when I tried to save a DifferentialEquations.ODESolution. That is the kind of thing you want to save, and it would be nice to get a warning when the ODESolution for dx/dt = f(t,x) includes f as an anonymous function. Unless you read the source of DifferentialEquations, there is no reason you would guess that it did.

Hmm, that explains my problem. However, a warning that I'm saving an anonymous function is not really a solution to the problem that we'd still want (need!) to save a DifferentialEquations.ODESolution.

Do I understand correctly, that this issue will be fixed with https://github.com/JuliaIO/JLD2.jl/pull/316

TS-CUBED avatar Jul 20 '21 08:07 TS-CUBED

This will be fixed with #316 . However, there is still quite some work to do, in particular, since methods changed from 1.6 to 1.7.

JonasIsensee avatar Jul 20 '21 08:07 JonasIsensee