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

Reopening of previous PR #309

Merged
merged 262 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
262 commits
Select commit Hold shift + click to select a range
a0c05f3
fixed some signatures for Model
torfjelde May 31, 2021
307cd7e
fixed a method call
torfjelde May 31, 2021
5972771
fixed method signatures
torfjelde Jun 1, 2021
c4ecd0e
sort of fixed the matchingvalue functionality for model
torfjelde Jun 1, 2021
a34b51c
formatting
torfjelde Jun 1, 2021
b89ff7e
removed redundant _tilde method
torfjelde Jun 1, 2021
6368282
Merge branch 'tor/tilde-simplification' into tor/sampler-context
torfjelde Jun 1, 2021
e4a2cf8
removed left-over acclogp! that should not be here anymore
torfjelde Jun 1, 2021
7605785
export SamplingContext
torfjelde Jun 1, 2021
354ac52
use context instead of ctx to refer to contexts
torfjelde Jun 1, 2021
b7a2b3b
formatting
torfjelde Jun 1, 2021
9e0fc9a
use context instead of ctx for variables
torfjelde Jun 1, 2021
7a4a1a3
use context instead of ctx to refer to contexts
torfjelde Jun 1, 2021
7899473
Update src/compiler.jl
torfjelde Jun 2, 2021
1630476
Update src/context_implementations.jl
torfjelde Jun 2, 2021
6892d2b
Apply suggestions from code review
torfjelde Jun 2, 2021
13da1b4
added some whitespace to some docstrings
torfjelde Jun 2, 2021
d76e5b3
deprecated tilde and dot_tilde plus exported new versions
torfjelde Jun 2, 2021
8059669
formatting
torfjelde Jun 2, 2021
4343896
Merge branch 'master' into tor/tilde-simplification
yebai Jun 2, 2021
43ef8d1
minor version bump
torfjelde Jun 2, 2021
fec00b6
Merge branch 'master' into tor/sampler-context
torfjelde Jun 3, 2021
ffb4933
Merge branch 'master' into tor/sampler-context
torfjelde Jun 4, 2021
43356a2
Merge branch 'master' into tor/tilde-simplification
torfjelde Jun 4, 2021
671e0b7
Merge branch 'master' into tor/tilde-simplification
torfjelde Jun 7, 2021
30c8345
Merge branch 'tor/tilde-simplification' into tor/sampling-context-simple
torfjelde Jun 7, 2021
1015f0e
added impl of matchingvalue for contexts
torfjelde Jun 7, 2021
23c86a7
reverted the change that makes assume always resample
torfjelde Jun 7, 2021
17f5abe
removed the inds arguments from assume and dot_assume to stay non-bre…
torfjelde Jun 7, 2021
dbd61f0
Update src/context_implementations.jl
yebai Jun 7, 2021
b10ba3f
added missing sampler arg to tilde_observe
torfjelde Jun 7, 2021
43779e8
Merge branch 'tor/sampling-context-simple' of github.com:TuringLang/D…
torfjelde Jun 7, 2021
bc5029f
added missing sampler argument in dot_tilde_observe
torfjelde Jun 7, 2021
7eac33d
fixed order of arguments in some dot_assume calls
torfjelde Jun 7, 2021
8599481
formatting
torfjelde Jun 7, 2021
90a8c45
formatting
torfjelde Jun 7, 2021
f9d4ff8
added missing sampler argument in tilde_observe for SamplingContext
torfjelde Jun 7, 2021
e424fe7
added missing word in a docstring
torfjelde Jun 7, 2021
70957d2
updated submodel macro
torfjelde Jun 8, 2021
d00cdcf
removed unwrap_childcontext and related since its not needed for this PR
torfjelde Jun 8, 2021
639fd6e
updated submodel macro
torfjelde Jun 8, 2021
c9a06fb
fixed evaluation implementations of dot_assume
torfjelde Jun 8, 2021
2fe5f40
updated pointwise_loglikelihoods and related
torfjelde Jun 8, 2021
b532ca6
added proper tests for pointwise_loglikelihoods
torfjelde Jun 8, 2021
4e2274e
updated DPPL tests to reflect recent changes
torfjelde Jun 8, 2021
ef6da43
bump minor version since this will be breaking
torfjelde Jun 8, 2021
dbb48c5
Merge branch 'tor/tilde-simplification' into tor/sampling-context-simple
torfjelde Jun 8, 2021
10899f3
formatting
torfjelde Jun 8, 2021
1f21ce4
formatting
torfjelde Jun 8, 2021
7004506
renamed mean_of_mean_models used in tests
torfjelde Jun 8, 2021
fa6c4d6
bumped dppl version in integration tests
torfjelde Jun 9, 2021
684d829
Apply suggestions from code review
torfjelde Jun 9, 2021
07bb284
Apply suggestions from code review
torfjelde Jun 9, 2021
c7c6a3c
fixed ambiguity error
torfjelde Jun 9, 2021
c259999
Merge branch 'tor/sampling-context-simple' of github.com:TuringLang/D…
torfjelde Jun 9, 2021
06d319c
Introduction of `SamplingContext`: keeping it simple (#259)
torfjelde Jun 9, 2021
cb996c6
Update src/DynamicPPL.jl
torfjelde Jun 9, 2021
300f4b6
Merge branch 'master' into tor/tilde-simplification
torfjelde Jun 9, 2021
0437d39
Merge branch 'tor/tilde-simplification' into tor/simple-varinfo-v2
torfjelde Jun 9, 2021
03c9285
added initial impl of SimpleVarInfo
torfjelde Jun 10, 2021
f91952d
remove unnecessary debug statements to be compat with Zygote
torfjelde Jun 10, 2021
4d4b489
make reconstruct slightly more generic
torfjelde Jun 10, 2021
1506773
Merge branch 'master' into tor/simple-varinfo-v2
torfjelde Jun 10, 2021
a68c045
added a couple of convenience constructors
torfjelde Jun 18, 2021
9766aec
formatting
torfjelde Jun 18, 2021
46b1c78
small fix
torfjelde Jun 18, 2021
3a645d6
return var_info from tilde-statements, allowing impl of immutable ver…
torfjelde Jun 20, 2021
a2ec0bd
allow usage of non-Ref types in SimpleVarInfo
torfjelde Jun 20, 2021
1d9bc37
update submodel-macro
torfjelde Jun 20, 2021
cfd7f21
formatting and docstring for submodel-macro
torfjelde Jun 20, 2021
c200e73
attempt at supporting implicit returns too
torfjelde Jun 20, 2021
efeb812
added a small comment
torfjelde Jun 20, 2021
14b9495
simplifed submodel macro a bit
torfjelde Jun 20, 2021
c3d9e7b
formatting
torfjelde Jun 20, 2021
416e773
fixed typo
torfjelde Jun 20, 2021
ac2b68d
Merge branch 'tor/simple-varinfo-v2' of github.com:TuringLang/Dynamic…
torfjelde Jun 20, 2021
b4b8b03
use bang-bang convention
torfjelde Jun 20, 2021
a725a27
updated PointwiseLikelihoodContext
torfjelde Jun 20, 2021
5512670
fixed issue where we unnecessarily replace the return-statement
torfjelde Jun 20, 2021
4c1ee70
check subtype in the retval
torfjelde Jun 20, 2021
26590b5
formatting
torfjelde Jun 20, 2021
42fd414
fixed type-instability in retval check
torfjelde Jun 20, 2021
f219545
introduced evaluate method for model
torfjelde Jun 20, 2021
ce13566
remove unnecessary type-requirement
torfjelde Jun 20, 2021
3556b11
make return-value check much nicer
torfjelde Jun 20, 2021
599d094
removed redundant creation of anonymous function
torfjelde Jun 20, 2021
22b170c
dont use UnionAll in return_values
torfjelde Jun 28, 2021
4606f16
updated tests for submodel to reflect new syntax
torfjelde Jun 28, 2021
68cb021
moved to using BangBang-convention for most methods
torfjelde Jun 30, 2021
cb1fd8b
remove SimpleVarInfo from this branch
torfjelde Jun 30, 2021
5936dd0
added a comment
torfjelde Jun 30, 2021
426c465
reverted submodel macro to use = rather than ~
torfjelde Jun 30, 2021
208b62c
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Jun 30, 2021
a8e55bd
updated SimpleVarInfo impl
torfjelde Jun 30, 2021
149229f
added a couple of missing deprecations
torfjelde Jun 30, 2021
809d23f
updated tests
torfjelde Jun 30, 2021
8ea80d7
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Jun 30, 2021
07f684b
updated implementations of logjoint and others
torfjelde Jun 30, 2021
d317bd8
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Jun 30, 2021
b00ae47
formatting
torfjelde Jun 30, 2021
a88f8ea
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Jun 30, 2021
bfd7c78
added eltype impl for SimpleVarInfo
torfjelde Jul 2, 2021
acb15eb
formatting
torfjelde Jul 2, 2021
4828aab
fixed eltype for SimpleVarInfo
torfjelde Jul 6, 2021
167976f
implement setindex!! in prep for allowing sampling with immutable vi
torfjelde Jul 9, 2021
b56024e
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Jul 9, 2021
e4f0ad2
formatting
torfjelde Jul 9, 2021
ccfd112
initial work on allowing sampling using SimpleVarInfo
torfjelde Jul 9, 2021
d660433
formatting
torfjelde Jul 9, 2021
c925b07
Merge branch 'master' into tor/simple-varinfo-v2
torfjelde Jul 16, 2021
3ec72c6
Merge branch 'tor/simple-varinfo-v2' of github.com:TuringLang/Dynamic…
torfjelde Jul 16, 2021
90cf754
add constructor for SimpleVarInfo using model
torfjelde Jul 16, 2021
0ab9d8b
improved leftover to_namedtuple_expr, fixing a bug when used with Zygote
torfjelde Jul 16, 2021
42ad552
bumped patch version
torfjelde Jul 16, 2021
975184d
Merge branch 'tor/allargs-construction-improvement' into tor/simple-v…
torfjelde Jul 16, 2021
a0cd0c4
Merge branch 'master' into tor/simple-varinfo-v2
torfjelde Jul 19, 2021
aa706ef
Merge branch 'master' into tor/immutable-varinfo-support
torfjelde Jul 19, 2021
744a032
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Jul 19, 2021
0f1def9
fixed set_flag!!
torfjelde Jul 20, 2021
54a1be7
Merge branch 'master' into tor/immutable-varinfo-support
torfjelde Jul 20, 2021
76daca6
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Jul 20, 2021
596d63b
Merge branch 'master' into tor/immutable-varinfo-support
torfjelde Jul 22, 2021
6f947f7
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Jul 22, 2021
53596fb
forgot the return in the replace_returns
torfjelde Jul 23, 2021
4076f63
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Jul 23, 2021
45b3a76
Merge branch 'master' into tor/immutable-varinfo-support
torfjelde Jul 29, 2021
57b5d47
bigboy update to benchmarks
torfjelde Aug 2, 2021
d0a08f6
fixed some issues and added support for usage of Dict in SimpleVarInfo
torfjelde Aug 5, 2021
0ab59eb
Merge branch 'master' into tor/immutable-varinfo-support
torfjelde Aug 5, 2021
4002318
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Aug 5, 2021
ff75ddc
added docstring and improved indexing behvaior for SimpleVarInfo
torfjelde Aug 5, 2021
d29dd8f
formatting
torfjelde Aug 5, 2021
a72594f
dont allow sampling with indexing when using SimpleVarInfo with Named…
torfjelde Aug 5, 2021
be35be0
_setval_kernel and others are only supported by VarInfo atm
torfjelde Aug 12, 2021
c3da562
Merge branch 'master' into tor/immutable-varinfo-support
torfjelde Aug 14, 2021
3f3d8d3
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Aug 14, 2021
4d4eeb3
fixed typo in comment
torfjelde Aug 14, 2021
b7862a8
added more values_as impls
torfjelde Aug 14, 2021
39619cd
removed redundant values_from_metadata
torfjelde Aug 14, 2021
294cd0f
Merge branch 'master' into tor/immutable-varinfo-support
torfjelde Aug 15, 2021
bcb1e46
Merge branch 'tor/immutable-varinfo-support' into tor/simple-varinfo-v2
torfjelde Aug 15, 2021
e67901b
fixed bug in push!! for SimpleVarInfo
torfjelde Aug 17, 2021
e7c0a76
Merge branch 'master' into tor/benchmark-update
torfjelde Aug 19, 2021
7309fb7
fixed a couple of bugs in SimpleVarInfo
torfjelde Aug 19, 2021
d7dad31
forgot which branch Im on
torfjelde Aug 19, 2021
6ec2d29
added handling of short defs in replace_returns and more docstrings
torfjelde Aug 21, 2021
dfd9dc5
fixed bug in generate_tilde introduced in a merge
torfjelde Aug 23, 2021
18ed817
fixed a bug in isfuncdef
torfjelde Aug 23, 2021
b61a9be
fixed tests
torfjelde Aug 23, 2021
8d2dc71
formatting
torfjelde Aug 23, 2021
9cff93f
uncomment mistakenly commented code
torfjelde Aug 24, 2021
6c3bd62
Merge branch 'master' into tor/simple-varinfo-v2
torfjelde Aug 24, 2021
af6427a
bumped version
torfjelde Sep 9, 2021
81d6369
Merge branch 'master' into tor/simple-varinfo-v2
torfjelde Sep 9, 2021
7b5dbce
updated doctests
torfjelde Sep 9, 2021
a6e2ffb
dont carry over bang-bang versions that we dont need for general vari…
torfjelde Sep 9, 2021
49c1157
Apply suggestions from @phipsgabler
torfjelde Sep 9, 2021
f601d5d
updated tests
torfjelde Sep 9, 2021
4e36c09
Merge branch 'master' into tor/simple-varinfo-v2
torfjelde Nov 3, 2021
72d2f53
removed unnecessary BangBang methods
torfjelde Nov 6, 2021
df212b7
fixed zygote rule for dot_observe
torfjelde Nov 6, 2021
74bfd4e
fixed Setfield.jl + returning VarInfo bug in model-macro
torfjelde Nov 6, 2021
b759535
updated tests
torfjelde Nov 6, 2021
9d421a5
Merge branch 'master' into tor/simple-varinfo-v2
torfjelde Nov 6, 2021
a61eef2
fixed docs
torfjelde Nov 6, 2021
8bc72ff
formatting
torfjelde Nov 6, 2021
cfb1a2c
Merge branch 'master' into tor/simple-varinfo-v2
torfjelde Nov 6, 2021
cdd88d0
fixed issues when using ThreadSafeVarInfo
torfjelde Nov 6, 2021
3faa883
fixed _pointwise_observe for ThreadSafeVarInfo
torfjelde Nov 7, 2021
e14930e
updated ThreadSafeVarInfo
torfjelde Nov 7, 2021
fc93782
made SimpleVarInfo compat with ThreadSafeVarInfo and added show
torfjelde Nov 7, 2021
b6939f6
added some tests for return-values of models
torfjelde Nov 7, 2021
8903523
formatting
torfjelde Nov 7, 2021
d90a6cd
fixed doctest for SimpleVarInfo
torfjelde Nov 8, 2021
082b2ef
formatting
torfjelde Nov 8, 2021
9ad362d
removed comparison of show from doctest for SimpleVarInfo
torfjelde Nov 8, 2021
4a39846
Merge branch 'master' into tor/simple-varinfo-v2
torfjelde Nov 8, 2021
7109596
Update src/compiler.jl
torfjelde Nov 8, 2021
d5345d9
Apply suggestions from code review
torfjelde Nov 8, 2021
42bf1c5
removed OrderedCollections from docs
torfjelde Nov 8, 2021
e14506f
some additional fixes
torfjelde Nov 9, 2021
715ef89
fixed method ambiguity and some ill-defined map
torfjelde Nov 9, 2021
2991db2
renamed evaluate to evaluate!!
torfjelde Nov 11, 2021
2fbbd5e
added implementations of haskey, getindex and setindex!! for SimpleVa…
torfjelde Nov 12, 2021
016f485
formatting
torfjelde Nov 12, 2021
7a8d9a1
dropped redundant definition
torfjelde Nov 12, 2021
b76b1d1
use getproperty instead of getindex
torfjelde Nov 12, 2021
bbdabd1
fixed method-ambiguity and added some comments
torfjelde Nov 12, 2021
5a3ada5
fixed docstring of SimpleVarInfo
torfjelde Nov 12, 2021
ee6c111
fixed docstrings
torfjelde Nov 12, 2021
7fa379d
fixed Project.toml for docs
torfjelde Nov 12, 2021
0ea28b7
fixed docstring of canview
torfjelde Nov 12, 2021
59d61f6
fixed docstrings
torfjelde Nov 12, 2021
ab06c9c
another attempt at fixing docstrings
torfjelde Nov 12, 2021
b5e6876
added a TODO comment
torfjelde Nov 17, 2021
a36c085
remove some output from docstring of SimpleVarInfo
torfjelde Nov 17, 2021
74a9781
fixed haskey and hasvalue for AbstractDict
torfjelde Nov 17, 2021
dc28ceb
updated some comments
torfjelde Nov 17, 2021
4c12498
updated some errors
torfjelde Nov 17, 2021
37a1e2e
added sampling dot_assume for SimpleVarInfo
torfjelde Nov 17, 2021
41c2d80
added true versions of density computations to TestUtils
torfjelde Nov 17, 2021
35445ba
added tests specific for SimpleVarInfo
torfjelde Nov 17, 2021
acdedc7
also document TestUtils
torfjelde Nov 17, 2021
95f67c0
added TestUtils to docs
torfjelde Nov 17, 2021
8b5729c
fixed setindex!! for SimpleVarInfo using AbstractDict
torfjelde Nov 17, 2021
04dab05
added more tests
torfjelde Nov 17, 2021
251eb80
formatting
torfjelde Nov 17, 2021
142d93b
dont use BangBang for setall!
torfjelde Nov 17, 2021
3c91d2f
revert unnecessary changes to settrans!
torfjelde Nov 17, 2021
1ffb83c
revert unnecessary changes to set_flag!
torfjelde Nov 17, 2021
871b8cd
revert some changes to docstrings
torfjelde Nov 17, 2021
df4e514
fixed some comments and docstrings
torfjelde Nov 17, 2021
037a8c9
added more convenient logjoint, logprior, and loglikelihood methods
torfjelde Nov 17, 2021
7a9af3c
removed unnecessary export
torfjelde Nov 17, 2021
71bd8bc
fixed export
torfjelde Nov 17, 2021
969bb65
use the Setfield impl of getindex, etc. as default and specialize on …
torfjelde Nov 20, 2021
92dd5b8
fixed docstrings of logjoint, etc.
torfjelde Nov 22, 2021
de936a5
Apply suggestions from code review
torfjelde Nov 23, 2021
147e9f5
fixed docstring for model
torfjelde Nov 26, 2021
aeb4fa1
replaced return_values by capturing return-value from tilde-statement…
torfjelde Nov 26, 2021
abb07b3
added some tests for return-value of model
torfjelde Nov 26, 2021
25cacd3
added broadcast_foreach
torfjelde Dec 2, 2021
87ce03b
Apply suggestions from @devmotion
torfjelde Dec 6, 2021
46a5019
Merge branch 'tor/simple-varinfo-v2' of github.com:TuringLang/Dynamic…
torfjelde Dec 6, 2021
4bdeca3
remove broadcast_foreach for now
torfjelde Dec 6, 2021
80ee8f4
some fixes to ThreadSafeVarInfo
torfjelde Dec 6, 2021
496ec3d
Apply suggestions from code review
torfjelde Dec 6, 2021
9c33e67
fixed docstrings
torfjelde Dec 6, 2021
6ad0e43
forgot qualification for set
torfjelde Dec 6, 2021
0d217c4
formatting
torfjelde Dec 6, 2021
57dda81
added comment about why we cant use MacroTools.isdef
torfjelde Dec 6, 2021
c4c6412
remove unnecessary deprecation
torfjelde Dec 6, 2021
791c181
udpated some docstrings
torfjelde Dec 6, 2021
49165b6
fixed more docstrings
torfjelde Dec 6, 2021
987d7ea
make overloads of BangBang methods qualified
torfjelde Dec 6, 2021
d514b99
remove overloading of values and instead use values_as without the ty…
torfjelde Dec 6, 2021
0eb27b6
Apply suggestions from code review
torfjelde Dec 6, 2021
0bab3e6
renamed hasvalue for SimpleVarInfo to _haskey
torfjelde Dec 6, 2021
fa3f430
revert changes from previous commit
torfjelde Dec 6, 2021
b9a987a
minor version bump
torfjelde Dec 7, 2021
56a5106
fixed sampling with ThreadSafeVarInfo
torfjelde Dec 8, 2021
e00498a
fixed setindex!! for ThreadSafeVarInfo
torfjelde Dec 8, 2021
64945e6
fixed eltype for ThreadSafeVarInfo wrapping a SimpleVarInfo
torfjelde Dec 8, 2021
640551b
fixed a test
torfjelde Dec 8, 2021
00dfdbd
relax atol in serialization tests a bit
torfjelde Dec 8, 2021
db1b033
temporarily disable Julia 1.3
torfjelde Dec 8, 2021
6a63e15
relax atol for a prior check
torfjelde Dec 8, 2021
d65fc74
Improvements to `@submodel` in #309 (#348)
torfjelde Dec 8, 2021
a8c368c
fixed a test case using submodel
torfjelde Dec 11, 2021
64819a1
improved docstring according to comments by @devmotion
torfjelde Dec 11, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
version:
- '1.3' # minimum supported version
# - '1.3' # minimum supported version
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is what we want to do, but as mentioned in the comments the tests are currently failing on 1.3 because of FFTW.jl failing to build or something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FFTW should work just fine with Julia 1.3, this seems strange.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the artifacts are cached incorrectly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the artifacts are cached incorrectly?

Possibly. I'm not an expert on GH actions though, so I have no current intuition of how to fix this (other than to start googling).

- '1' # current stable version
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.16.2"
version = "0.17.0"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"

[compat]
Distributions = "0.25"
Documenter = "0.27"
Setfield = "0.7.1, 0.8"
StableRNGs = "1"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ makedocs(;
sitename="DynamicPPL",
format=Documenter.HTML(),
modules=[DynamicPPL],
pages=["Home" => "index.md"],
pages=["Home" => "index.md", "TestUtils" => "test_utils.md"],
strict=true,
checkdocs=:exports,
doctestfilters=[
Expand Down
5 changes: 5 additions & 0 deletions docs/src/test_utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# DynamicPPL.TestUtils

```@autodocs
Modules = [DynamicPPL.TestUtils]
```
30 changes: 29 additions & 1 deletion src/DynamicPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using ChainRulesCore: ChainRulesCore
using MacroTools: MacroTools
using ZygoteRules: ZygoteRules
using BangBang: BangBang
using Setfield: Setfield

using Setfield: Setfield
using BangBang: BangBang
Expand All @@ -31,15 +32,23 @@ import Base:
keys,
haskey

using BangBang: push!!, empty!!, setindex!!

# VarInfo
export AbstractVarInfo,
VarInfo,
UntypedVarInfo,
TypedVarInfo,
SimpleVarInfo,
push!!,
empty!!,
getlogp,
setlogp!,
acclogp!,
resetlogp!,
setlogp!!,
acclogp!!,
resetlogp!!,
get_num_produce,
set_num_produce!,
reset_num_produce!,
Expand Down Expand Up @@ -139,13 +148,32 @@ include("distribution_wrappers.jl")
include("contexts.jl")
include("varinfo.jl")
include("threadsafe.jl")
include("simple_varinfo.jl")
include("context_implementations.jl")
include("compiler.jl")
include("prob_macro.jl")
include("compat/ad.jl")
include("loglikelihoods.jl")
include("submodel_macro.jl")

include("test_utils.jl")

# Deprecations
@deprecate empty!(vi::VarInfo) empty!!(vi::VarInfo)
@deprecate push!(vi::AbstractVarInfo, vn::VarName, r, dist::Distribution) push!!(
vi::AbstractVarInfo, vn::VarName, r, dist::Distribution
)
@deprecate push!(
vi::AbstractVarInfo, vn::VarName, r, dist::Distribution, sampler::AbstractSampler
) push!!(vi::AbstractVarInfo, vn::VarName, r, dist::Distribution, sampler::AbstractSampler)
@deprecate push!(vi::AbstractVarInfo, vn::VarName, r, dist::Distribution, gid::Selector) push!!(
vi::AbstractVarInfo, vn::VarName, r, dist::Distribution, gid::Selector
)
@deprecate push!(
vi::AbstractVarInfo, vn::VarName, r, dist::Distribution, gid::Set{Selector}
) push!!(vi::AbstractVarInfo, vn::VarName, r, dist::Distribution, gid::Set{Selector})

@deprecate setlogp!(vi, logp) setlogp!!(vi, logp)
@deprecate acclogp!(vi, logp) acclogp!!(vi, logp)
@deprecate resetlogp!(vi) resetlogp!!(vi)

end # module
4 changes: 2 additions & 2 deletions src/compat/ad.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# See https://github.com/TuringLang/Turing.jl/issues/1199
ChainRulesCore.@non_differentiable push!(
ChainRulesCore.@non_differentiable push!!(
vi::VarInfo, vn::VarName, r, dist::Distribution, gidset::Set{Selector}
)

Expand All @@ -16,7 +16,7 @@ ZygoteRules.@adjoint function dot_observe(
)
function dot_observe_fallback(spl, dists, value, vi)
increment_num_produce!(vi)
return sum(map(Distributions.loglikelihood, dists, value))
return sum(map(Distributions.loglikelihood, dists, value)), vi
end
return ZygoteRules.pullback(__context__, dot_observe_fallback, spl, dists, value, vi)
end
120 changes: 100 additions & 20 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,12 @@ end

function generate_tilde_literal(left, right)
# If the LHS is a literal, it is always an observation
@gensym value
return quote
$(DynamicPPL.tilde_observe!)(
$value, __varinfo__ = $(DynamicPPL.tilde_observe!!)(
__context__, $(DynamicPPL.check_tilde_rhs)($right), $left, __varinfo__
)
$value
end
end

Expand All @@ -373,7 +375,7 @@ function generate_tilde(left, right)

# Otherwise it is determined by the model or its value,
# if the LHS represents an observation
@gensym vn isassumption
@gensym vn isassumption value

# HACK: Usage of `drop_escape` is unfortunate. It's a consequence of the fact
# that in DynamicPPL we the entire function body. Instead we should be
Expand All @@ -389,32 +391,38 @@ function generate_tilde(left, right)
$left = $(DynamicPPL.getvalue_nested)(__context__, $vn)
end

$(DynamicPPL.tilde_observe!)(
$value, __varinfo__ = $(DynamicPPL.tilde_observe!!)(
__context__,
$(DynamicPPL.check_tilde_rhs)($right),
$(maybe_view(left)),
$vn,
__varinfo__,
)
$value
end
end
end

function generate_tilde_assume(left, right, vn)
expr = :(
$left = $(DynamicPPL.tilde_assume!)(
# HACK: Because the Setfield.jl macro does not support assignment
# with multiple arguments on the LHS, we need to capture the return-values
# and then update the LHS variables one by one.
@gensym value
expr = :($left = $value)
if left isa Expr
expr = AbstractPPL.drop_escape(
Setfield.setmacro(BangBang.prefermutation, expr; overwrite=true)
)
end

return quote
$value, __varinfo__ = $(DynamicPPL.tilde_assume!!)(
__context__,
$(DynamicPPL.unwrap_right_vn)($(DynamicPPL.check_tilde_rhs)($right), $vn)...,
__varinfo__,
)
)

return if left isa Expr
AbstractPPL.drop_escape(
Setfield.setmacro(BangBang.prefermutation, expr; overwrite=true)
)
else
return expr
$expr
$value
end
end

Expand All @@ -428,7 +436,7 @@ function generate_dot_tilde(left, right)

# Otherwise it is determined by the model or its value,
# if the LHS represents an observation
@gensym vn isassumption
@gensym vn isassumption value
return quote
$vn = $(AbstractPPL.drop_escape(varname(left)))
$isassumption = $(DynamicPPL.isassumption(left))
Expand All @@ -440,13 +448,14 @@ function generate_dot_tilde(left, right)
$left .= $(DynamicPPL.getvalue_nested)(__context__, $vn)
end

$(DynamicPPL.dot_tilde_observe!)(
$value, __varinfo__ = $(DynamicPPL.dot_tilde_observe!!)(
__context__,
$(DynamicPPL.check_tilde_rhs)($right),
$(maybe_view(left)),
$vn,
__varinfo__,
)
$value
end
end
end
Expand All @@ -455,15 +464,82 @@ function generate_dot_tilde_assume(left, right, vn)
# We don't need to use `Setfield.@set` here since
# `.=` is always going to be inplace + needs `left` to
# be something that supports `.=`.
return :(
$left .= $(DynamicPPL.dot_tilde_assume!)(
@gensym value
return quote
$value, __varinfo__ = $(DynamicPPL.dot_tilde_assume!!)(
__context__,
$(DynamicPPL.unwrap_right_left_vns)(
$(DynamicPPL.check_tilde_rhs)($right), $(maybe_view(left)), $vn
)...,
__varinfo__,
)
)
$left .= $value
$value
end
end

# Note that we cannot use `MacroTools.isdef` because
# of https://github.com/FluxML/MacroTools.jl/issues/154.
"""
isfuncdef(expr)

Return `true` if `expr` is any form of function definition, and `false` otherwise.
"""
function isfuncdef(e::Expr)
return if Meta.isexpr(e, :function)
# Classic `function f(...)`
true
elseif Meta.isexpr(e, :->)
# Anonymous functions/lambdas, e.g. `do` blocks or `->` defs.
true
elseif Meta.isexpr(e, :(=)) && Meta.isexpr(e.args[1], :call)
# Short function defs, e.g. `f(args...) = ...`.
true
else
false
end
phipsgabler marked this conversation as resolved.
Show resolved Hide resolved
end

"""
replace_returns(expr)

Return `Expr` with all `return ...` statements replaced with
`return ..., DynamicPPL.return_values(__varinfo__)`.

Note that this method will _not_ replace `return` statements within function
definitions. This is checked using [`isfuncdef`](@ref).
"""
replace_returns(e) = e
phipsgabler marked this conversation as resolved.
Show resolved Hide resolved
function replace_returns(e::Expr)
if isfuncdef(e)
phipsgabler marked this conversation as resolved.
Show resolved Hide resolved
return e
end

if Meta.isexpr(e, :return)
# NOTE: `return` always has an argument. In the case of
# an empty `return`, the lowered expression will be `return nothing`.
# Hence we don't need any special handling for empty returns.
retval_expr = if length(e.args) > 1
Expr(:tuple, e.args...)
else
e.args[1]
end

return :(return ($retval_expr, __varinfo__))
end

return Expr(e.head, map(replace_returns, e.args)...)
end

# If it's just a symbol, e.g. `f(x) = 1`, then we make it `f(x) = return 1`.
make_returns_explicit!(body) = Expr(:return, body)
function make_returns_explicit!(body::Expr)
# If the last statement is a return-statement, we don't do anything.
# Otherwise we replace the last statement with a `return` statement.
if !Meta.isexpr(body.args[end], :return)
body.args[end] = Expr(:return, body.args[end])
end
return body
end

const FloatOrArrayType = Type{<:Union{AbstractFloat,AbstractArray}}
Expand Down Expand Up @@ -496,10 +572,14 @@ function build_output(modelinfo, linenumbernode)
# Replace the user-provided function body with the version created by DynamicPPL.
# We use `MacroTools.@q begin ... end` instead of regular `quote ... end` to ensure
# that no new `LineNumberNode`s are added apart from the reference `linenumbernode`
# to the call site
# to the call site.
# NOTE: We need to replace statements of the form `return ...` with
# `return (..., __varinfo__)` to ensure that the second
# element in the returned value is always the most up-to-date `__varinfo__`.
# See the docstrings of `replace_returns` for more info.
evaluatordef[:body] = MacroTools.@q begin
$(linenumbernode)
$(modelinfo[:body])
$(replace_returns(make_returns_explicit!(modelinfo[:body])))
end

## Build the model function.
Expand Down
Loading