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

Adding reference to Serialization Package #532

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pages = [
"Custom Modeling Languages" => "how_to/custom_dsl.md",
"Custom Gradients" => "how_to/custom_derivatives.md",
"Incremental Computation" => "how_to/custom_incremental_computation.md",
"Serializing Dynamic DSL Traces" => "how_to/serialization.md"
],
"API Reference" => [
"Modeling Library" => [
Expand Down
31 changes: 31 additions & 0 deletions docs/src/how_to/serialization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# [Saving Traces between REPL Sessions](@id how_to_serialize)

When saving a trace to disk, it is likely to run into issues using `Serialization.jl` since traces internally track function pointers (recall `Trace`s may contain function pointers). Instead, you can try the experimental [`GenSerialization.jl`](https://github.com/probcomp/GenSerialization.jl) which can discard function call data. This is most useful for check-pointing work (e.g. inference) between different REPL sessions on the same machine.

Since `Serialization.jl` is used underneath, similar restrictions apply (see [`serialize`](https://docs.julialang.org/en/v1/stdlib/Serialization/#Serialization.serialize)). Please note we do not guarantee portability between different machines and have yet to extensively test this.

!!! note
See the repository for warnings and limitations.


An example:

```julia
using Gen
using GenSerialization

@gen function model(p)
x ~ bernoulli(p)
end

trace = simulate(model, (0.2))
serialize("coin_flip.gen", trace)
```

This stores the trace in a file. Now to deserialize, run
```julia
saved_trace = deserialize("coin_flip.gen", model)
```
!!! note
The same generative function used to save out the trace must be defined at runtime before deserialization.

Loading