https://github.com/probcomp/genserialization.jl
Gen.jl Trace Serialization
https://github.com/probcomp/genserialization.jl
Last synced: 4 months ago
JSON representation
Gen.jl Trace Serialization
- Host: GitHub
- URL: https://github.com/probcomp/genserialization.jl
- Owner: probcomp
- License: mit
- Created: 2023-07-02T02:35:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-09T15:51:45.000Z (about 2 years ago)
- Last Synced: 2025-07-11T05:35:34.726Z (11 months ago)
- Language: Julia
- Size: 276 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GenSerialization.jl
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.
## Installation
In the package manager, run
```
add https://github.com/probcomp/GenSerialization.jl.git
```
## Usage
See the example for a typical use case. The general workflow is as follows:
1. Produce traces from a generative function and then call `serialize`.
```julia
using Gen
using GenSerialization
@gen function model(p)
x ~ bernoulli(p)
end
trace = simulate(model, (0.2))
serialize("coin_flip.gen", trace)
```
2. Read in a trace by passing in the generative function:
```julia
saved_trace = deserialize("coin_flip.gen", model)
```
## Warnings
- 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.