WIP tool to serialize Gen.jl traces using Julia's serialization
library. Gen.jl traces often contain ephemeral data related to the generative model (a function), and this script decouples their dependency. Both traced and untraced randomness are considered.
In the package manager, run
add https://github.com/probcomp/GenSerialization.jl.git
See the example for a typical use case. The general workflow is as follows:
- Produce traces from a generative function and then call
serialize
.
using Gen
using GenSerialization
@gen function model(p)
x ~ bernoulli(p)
end
trace = simulate(model, (0.2))
serialize("coin_flip.gen", trace)
- Read in a trace by passing in the generative function:
saved_trace = deserialize("coin_flip.gen", model)
- Portability hasn't been tested. For example, machines with different endianness may fail to deserialize a given file.
- The generative function is dropped.
Serialization.jl
is used as the backend, so this package runs into similar pitfalls. For example, if your model samples functions, then unfortunately there are no guarantees that serialization will work properly.