Skip to content

Commit

Permalink
Merge pull request #4 from probcomp/ian/serialization
Browse files Browse the repository at this point in the history
Add serialization for Gen Dynamic DSL traces and some combinators
  • Loading branch information
limarta authored May 9, 2024
2 parents 900c731 + e386cd3 commit 8f702f7
Show file tree
Hide file tree
Showing 36 changed files with 2,097 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.0'
- '1.9'
- '1.10'
- 'nightly'
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Ian Limarta
Copyright (c) 2023 Ian

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[compat]
julia = "1"
Gen = "0.4.6"

[extras]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"

[targets]
test = ["Test"]
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# GenSerialization
# GenSerialization.jl

[![Build Status](https://github.com/limarta/GenSerialization.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/limarta/GenSerialization.jl/actions/workflows/CI.yml?query=branch%3Amain)
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.
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manifest.toml
7 changes: 7 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Gen = "ea4f424c-a589-11e8-07c0-fd5c91b9da4a"
GenSerialization = "21e319bb-9f6a-4cc8-b556-663507cd964d"

[compat]
Documenter = "1.0"
1 change: 1 addition & 0 deletions docs/build/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-17T09:43:45","documenter_version":"1.3.0"}}
Loading

0 comments on commit 8f702f7

Please sign in to comment.