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

Serialize ImmersedBoundaryGrid by converting immersed boundary functions to arrays? #2245

Closed
glwagner opened this issue Feb 14, 2022 · 4 comments
Labels

Comments

@glwagner
Copy link
Member

Right now we just punt on serializing immersed boundary grids:

function serializeproperty!(file, location, p::ImmersedBoundaryGrid)
# Note: when we support array representations of immersed boundaries, we should save those too.
@warn "Cannot serialize ImmersedBoundaryGrid; serializing underlying grid instead."
file[location] = p.grid
return nothing
end

Mainly the issue is that we can't serialize functions. But we could convert any function-based immersed boundary implementation to an array and serialize that.

@francispoulin
Copy link
Collaborator

Sorry for the silly question but what does it mean to serialize a function? It sounds to me like it's going from parallel to serial but I don't think that's right.

@glwagner
Copy link
Member Author

"Serialization" means "saving to disk":

https://en.wikipedia.org/wiki/Serialization

Functions can't be serialized by JLD2:

julia> using JLD2

julia> file = jldopen("test.jld2", "a+")
JLDFile /Users/gregorywagner/Projects/OceanTurbulenceParameterEstimation.jl/test.jld2 (read/write)
  (no datasets)

julia> f(x) = println("Hello world!")
f (generic function with 1 method)

julia> file["f"] = f
f (generic function with 1 method)

julia> close(file)

julia> exit()

# Restart julia
$ julia   
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.5 (2021-12-19)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using JLD2

julia> file = jldopen("test.jld2")
JLDFile /Users/gregorywagner/Projects/OceanTurbulenceParameterEstimation.jl/test.jld2 (read-only)
 └─🔢 f

julia> f = file["f"]
┌ Warning: type Main.#f does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/b0tI9/src/data/reconstructing_datatypes.jl:364
JLD2.ReconstructedTypes.var"##Main.#f#257"()

julia> f(1)
ERROR: MethodError: objects of type JLD2.ReconstructedTypes.var"##Main.#f#257" are not callable
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

@glwagner
Copy link
Member Author

glwagner commented Feb 14, 2022

I guess in our terminology "saving" is a bit more restricted than "serializing". When we "save" an object, we do it in a way that might be readable from Python or MATLAB (for example). This means that we only "save" common types like numbers, arrays, strings. Anything we output to NetCDF is "saved". When we "serialize" we might embed a Julia struct in a file. So when we serialize something we can only load it back from Julia. We can only serialize with JLD2.

@glwagner
Copy link
Member Author

Done

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

No branches or pull requests

2 participants