Skip to content

Commit 6c4bc4a

Browse files
authored
Merge branch 'py/init-prior-uniform' into py/actually-use-init
2 parents 7a8e7e3 + 6492b0d commit 6c4bc4a

File tree

8 files changed

+248
-229
lines changed

8 files changed

+248
-229
lines changed

HISTORY.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
## 0.37.0
44

5-
**Breaking changes**
5+
DynamicPPL 0.37 comes with a substantial reworking of its internals.
6+
Fundamentally, there is no change to the actual modelling syntax: if you are a Turing.jl user, for example, this release is unlikely to affect you much.
7+
However, if you are a package developer or someone who uses DynamicPPL's functionality directly, you will notice a number of changes.
8+
9+
To avoid overwhelming the reader, we begin by listing the most important, user-facing changes, before explaining the changes to the internals in more detail.
10+
11+
Note that virtually all changes listed here are breaking.
12+
13+
**Public-facing changes**
614

715
### Submodel macro
816

@@ -19,6 +27,32 @@ There is now also an `rng` keyword argument to help seed parameter generation.
1927
Finally, instead of specifying `value_atol` and `grad_atol`, you can now specify `atol` and `rtol` which are used for both value and gradient.
2028
Their semantics are the same as in Julia's `isapprox`; two values are equal if they satisfy either `atol` or `rtol`.
2129

30+
### `DynamicPPL.TestUtils.check_model`
31+
32+
You now need to explicitly pass a `VarInfo` argument to `check_model` and `check_model_and_trace`.
33+
Previously, these functions would generate a new VarInfo for you (using an optionally provided `rng`).
34+
35+
### Removal of `PriorContext` and `LikelihoodContext`
36+
37+
A number of DynamicPPL's contexts have been removed, most notably `PriorContext` and `LikelihoodContext`.
38+
Although these are not the only _exported_ contexts, we consider unlikely that anyone was using _other_ contexts manually: if you have a question about contexts _other_ than these, please continue reading the 'Internals' section below.
39+
40+
Previously, during evaluation of a model, DynamicPPL only had the capability to store a _single_ log probability (`logp`) field.
41+
`DefaultContext`, `PriorContext`, and `LikelihoodContext` were used to control what this field represented: they would accumulate the log joint, log prior, or log likelihood, respectively.
42+
43+
Now, we have reworked DynamicPPL's `VarInfo` object such that it can track multiple log probabilities at once (see the 'Accumulators' section below).
44+
If you were evaluating a model with `PriorContext`, you can now just evaluate it with `DefaultContext`, and instead of calling `getlogp(varinfo)`, you can call `getlogprior(varinfo)` (and similarly for the likelihood).
45+
46+
If you were constructing a `LogDensityFunction` with `PriorContext`, you can now stick to `DefaultContext`.
47+
`LogDensityFunction` now has an extra field, called `getlogdensity`, which represents a function that takes a `VarInfo` and returns the log density you want.
48+
Thus, if you pass `getlogprior` as the value of this parameter, you will get the same behaviour as with `PriorContext`.
49+
50+
The other case where one might use `PriorContext` was to use `@addlogprob!` to add to the log prior.
51+
Previously, this was accomplished by manually checking `__context__ isa DynamicPPL.PriorContext`.
52+
Now, you can write `@addlogprob (; logprior=x, loglikelihood=y)` to add `x` to the log-prior and `y` to the log-likelihood.
53+
54+
**Internals**
55+
2256
### Accumulators
2357

2458
This release overhauls how VarInfo objects track variables such as the log joint probability. The new approach is to use what we call accumulators: Objects that the VarInfo carries on it that may change their state at each `tilde_assume!!` and `tilde_observe!!` call based on the value of the variable in question. They replace both variables that were previously hard-coded in the `VarInfo` object (`logp` and `num_produce`) and some contexts. This brings with it a number of breaking changes:

Project.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ DynamicPPLMooncakeExt = ["Mooncake"]
4747
[compat]
4848
ADTypes = "1"
4949
AbstractMCMC = "5"
50-
AbstractPPL = "0.11, 0.12"
50+
AbstractPPL = "0.13"
5151
Accessors = "0.1"
5252
BangBang = "0.4.1"
5353
Bijectors = "0.13.18, 0.14, 0.15"
@@ -75,6 +75,3 @@ Requires = "1"
7575
Statistics = "1"
7676
Test = "1.6"
7777
julia = "1.10.8"
78-
79-
[sources]
80-
AbstractPPL = {url = "https://github.com/TuringLang/AbstractPPL.jl", rev = "py/hasgetvalue"}

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
1414
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
1515

1616
[compat]
17-
AbstractPPL = "0.11, 0.12"
17+
AbstractPPL = "0.13"
1818
Accessors = "0.1"
1919
DataStructures = "0.18"
2020
Distributions = "0.25"

src/accumulators.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ function accumulate_observe!! end
5353
5454
Update `acc` in a `tilde_assume!!` call. Returns the updated `acc`.
5555
56-
`vn` is the name of the variable being assumed, `val` is the value of the variable, and
57-
`right` is the distribution on the RHS of the tilde statement. `logjac` is the log
58-
determinant of the Jacobian of the transformation that was done to convert the value of `vn`
59-
as it was given (e.g. by sampler operating in linked space) to `val`.
56+
`vn` is the name of the variable being assumed, `val` is the value of the variable (in the
57+
original, unlinked space), and `right` is the distribution on the RHS of the tilde
58+
statement. `logjac` is the log determinant of the Jacobian of the transformation that was
59+
done to convert the value of `vn` as it was given to `val`: for example, if the sampler is
60+
operating in linked (Euclidean) space, then logjac will be nonzero.
6061
6162
`accumulate_assume!!` may mutate `acc`, but not any of the other arguments.
6263
@@ -71,7 +72,7 @@ Return a new accumulator like `acc` but empty.
7172
7273
The precise meaning of "empty" is that that the returned value should be such that
7374
`combine(acc, split(acc))` is equal to `acc`. This is used in the context of multi-threading
74-
where different threads may accumulate independently and the results are the combined.
75+
where different threads may accumulate independently and the results are then combined.
7576
7677
See also: [`combine`](@ref)
7778
"""
@@ -80,7 +81,8 @@ function split end
8081
"""
8182
combine(acc::AbstractAccumulator, acc2::AbstractAccumulator)
8283
83-
Combine two accumulators of the same type. Returns a new accumulator.
84+
Combine two accumulators which have the same type (but may, in general, have different type
85+
parameters). Returns a new accumulator of the same type.
8486
8587
See also: [`split`](@ref)
8688
"""

0 commit comments

Comments
 (0)