Skip to content

Commit f0ac109

Browse files
mhaurupenelopeysmtorfjeldeyebai
authored
Release v0.37 (#901)
* Bump minor version to 0.37.0 * Accumulators, stage 1 (#885) * Release 0.36 * AbstractPPL 0.11 + change prefixing behaviour (#830) * AbstractPPL 0.11; change prefixing behaviour * Use DynamicPPL.prefix rather than overloading * Remove VarInfo(VarInfo, params) (#870) * Unify `{untyped,typed}_{vector_,}varinfo` constructor functions (#879) * Unify {Untyped,Typed}{Vector,}VarInfo constructors * Update invocations * NTVarInfo * Fix tests * More fixes * Fixes * Fixes * Fixes * Use lowercase functions, don't deprecate VarInfo * Rewrite VarInfo docstring * Fix methods * Fix methods (really) * Draft of accumulators * Fix some variable names * Fix pointwise_logdensities, gut tilde_observe, remove resetlogp!! * Map rather than broadcast Co-authored-by: Tor Erlend Fjelde <[email protected]> * Start documenting accumulators * Use Val{symbols} instead of AccTypes to index * More documentation for accumulators * Link varinfo by default in AD testing utilities; make test suite run on linked varinfos (#890) * Link VarInfo by default * Tweak interface * Fix tests * Fix interface so that callers can inspect results * Document * Fix tests * Fix changelog * Test linked varinfos Closes #891 * Fix docstring + use AbstractFloat * Fix resetlogp!! and type stability for accumulators * Fix type rigidity of LogProbs and NumProduce * Fix uses of getlogp and other assorted issues * setaccs!! nicer interface and logdensity function fixes * Revert back to calling the macro @addlogprob! * Remove a dead test * Clarify a comment * Implement split/combine for PointwiseLogdensityAccumulator * Switch ThreadSafeVarInfo.accs_by_thread to be a tuple * Fix `condition` and `fix` in submodels (#892) * Fix conditioning in submodels * Simplify contextual_isassumption * Add documentation * Fix some tests * Add tests; fix a bunch of nested submodel issues * Fix fix as well * Fix doctests * Add unit tests for new functions * Add changelog entry * Update changelog Co-authored-by: Hong Ge <[email protected]> * Finish docs * Add a test for conditioning submodel via arguments * Clean new tests up a bit * Fix for VarNames with non-identity lenses * Apply suggestions from code review Co-authored-by: Markus Hauru <[email protected]> * Apply suggestions from code review * Make PrefixContext contain a varname rather than symbol (#896) --------- Co-authored-by: Hong Ge <[email protected]> Co-authored-by: Markus Hauru <[email protected]> * Revert ThreadSafeVarInfo back to Vectors and fix some AD type casting in (Simple)VarInfo * Improve accumulator docs * Add test/accumulators.jl * Docs fixes * Various small fixes * Make DynamicTransformation not use accumulators other than LogPrior * Fix variable order and name of map_accumulator!! * Typo fixing * Small improvement to ThreadSafeVarInfo * Fix demo_dot_assume_observe_submodel prefixing * Typo fixing * Miscellaneous small fixes * HISTORY entry and more miscellanea * Add more tests for accumulators * Improve accumulators docstrings * Fix a typo * Expand HISTORY entry * Add accumulators to API docs * Remove unexported functions from API docs * Add NamedTuple methods for get/set/acclogp * Fix setlogp!! with single scalar to error * Export AbstractAccumulator, fix a docs typo * Apply suggestions from code review Co-authored-by: Penelope Yong <[email protected]> * Rename LogPrior -> LogPriorAccumulator, and Likelihood and NumProduce * Type bound log prob accumulators with T<:Real * Add @addlogprior! and @addloglikelihood! * Apply suggestions from code review Co-authored-by: Penelope Yong <[email protected]> * Move default accumulators to default_accumulators.jl * Fix some tests * Introduce default_accumulators() * Go back to only having @addlogprob! * Fix tilde_observe!! prefixing * Fix default_accumulators internal type * Make unflatten more type stable, and add a test for it * Always print all benchmark results * Move NumProduce VI functions to abstract_varinfo.jl --------- Co-authored-by: Penelope Yong <[email protected]> Co-authored-by: Tor Erlend Fjelde <[email protected]> Co-authored-by: Hong Ge <[email protected]> * Replace PriorExtractorContext with PriorDistributionAccumulator (#907) * Implement values_as_in_model using an accumulator (#908) * Implement values_as_in_model using an accumulator * Make make_varname_expression a function * Refuse to combine ValuesAsInModelAccumulators with different include_colon_eqs * Fix nested context test * Bump DynamicPPL versions * Fix merge (1) * Add benchmark Pkg source * [no ci] Don't need to dev again * Disable use_closure for ReverseDiff * Revert "Disable use_closure for ReverseDiff" This reverts commit 3cb47cd. * Fix LogDensityAt struct * Try not duplicating * Update comment pointing to closure benchmarks * Remove `context` from model evaluation (use `model.context` instead) (#952) * Change `evaluate!!` API, add `sample!!` * Fix literally everything else that I broke * Fix some docstrings * fix ForwardDiffExt (look, multiple dispatch bad...) * Changelog * fix a test * Fix docstrings * use `sample!!` * Fix a couple more cases * Globally rename `sample!!` -> `evaluate_and_sample!!`, add changelog warning * Mark function as Const for Enzyme tests (#957) * Move submodel code to submodel.jl; remove `@submodel` (#959) * Move submodel code to submodel.jl * Remove `@submodel` * Fix missing field tests for 1.12 (#961) * Remove 3-argument `{_,}evaluate!!`; clean up submodel code (#960) * Clean up submodel code, remove 3-arg `_evaluate!!` * Remove 3-argument `evaluate!!` as well * Update changelog * Improve submodel error message * Fix doctest * Add error hint for three-argument evaluate!! * Improve API for AD testing (#964) * Rework API for AD testing * Fix test * Add `rng` keyword argument * Use atol and rtol * remove unbound type parameter (?) * Don't need to do elementwise check * Update changelog * Fix typo * DebugAccumulator (plus tiny bits and pieces) (#976) * DebugContext -> DebugAccumulator * Changelog * Force `conditioned` to return a dict * fix conditioned implementation * revert `conditioned` bugfix (will merge this to main instead) * fix show * Fix doctests * fix doctests 2 * Make VarInfo actually mandatory in check_model * Re-implement `missing` check * Revert `combine` signature in docstring * Revert changes to `Base.show` on AccumulatorTuple * Add TODO comment about VariableOrderAccumulator Co-authored-by: Markus Hauru <[email protected]> * Fix doctests --------- Co-authored-by: Markus Hauru <[email protected]> * VariableOrderAccumulator (#940) * Turn NumProduceAccumulator into VariableOrderAccumulator * Add comparison methods * Make VariableOrderAccumulator use regular Dict * Use copy rather than deepcopy for accumulators * Minor docstring touchup * Remove unnecessary use of NumProduceAccumulator * Fix split(VariableOrderAccumulator) * Remove NumProduceAcc from Debug * Fix set_retained_vns_del! --------- Co-authored-by: Penelope Yong <[email protected]> * Accumulators stage 2 (#925) * Give LogDensityFunction the getlogdensity field * Allow missing LogPriorAccumulator when linking * Trim whitespace * Run formatter * Fix a few typos * Fix comma -> semicolon * Fix `LogDensityAt` invocation * Fix one last test * Fix tests --------- Co-authored-by: Penelope Yong <[email protected]> * Implement more consistent tracking of logp components via `LogJacobianAccumulator` (#998) * logjac accumulator * Fix tests * Fix a whole bunch of stuff * Fix final tests * Fix docs * Fix docs/doctests * Fix maths in LogJacobianAccumulator docstring * Twiddle with a comment * Add changelog * Fix accumulator docstring * logJ -> logjac * Fix logjac accumulation for StaticTransformation * Fix behaviour of `set_retained_vns_del!` for `num_produce == 0` (#1000) * `InitContext`, part 2 - Move `hasvalue` and `getvalue` to AbstractPPL; enforce key type of `AbstractDict` (#980) * point to unmerged AbstractPPL branch * Remove code that was moved to AbstractPPL * Remove Dictionaries with Any key type * Fix bad merge conflict resolution * Fix doctests * Point to [email protected] This reverts commit 709dc9e. * Fix doctests * Fix docs AbstractPPL bound * Remove stray `Pkg.update()` * Accumulator miscellanea: Subset, merge, acclogp, and LogProbAccumulator (#999) * logjac accumulator * Fix tests * Fix a whole bunch of stuff * Fix final tests * Fix docs * Fix docs/doctests * Fix maths in LogJacobianAccumulator docstring * Twiddle with a comment * Add changelog * Simplify accs with LogProbAccumulator * Replace + with accumulate for LogProbAccs * Introduce merge and subset for accs * Improve acc tests * Fix docstring typo. Co-authored-by: Penelope Yong <[email protected]> * Fix merge --------- Co-authored-by: Penelope Yong <[email protected]> * Minor tweak to changelog wording --------- Co-authored-by: Penelope Yong <[email protected]> Co-authored-by: Tor Erlend Fjelde <[email protected]> Co-authored-by: Hong Ge <[email protected]>
1 parent 0b7213f commit f0ac109

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3601
-2811
lines changed

HISTORY.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,130 @@
11
# DynamicPPL Changelog
22

3+
## 0.37.0
4+
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 will not affect you too much (apart from the changes to `@addlogprob!`).
7+
Any such changes will be covered separately in the Turing.jl changelog when a release is made.
8+
However, if you are a package developer or someone who uses DynamicPPL's functionality directly, you will notice a number of changes.
9+
10+
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.
11+
12+
Note that virtually all changes listed here are breaking.
13+
14+
**Public-facing changes**
15+
16+
### Submodel macro
17+
18+
The `@submodel` macro is fully removed; please use `to_submodel` instead.
19+
20+
### `DynamicPPL.TestUtils.AD.run_ad`
21+
22+
The three keyword arguments, `test`, `reference_backend`, and `expected_value_and_grad` have been merged into a single `test` keyword argument.
23+
Please see the API documentation for more details.
24+
(The old `test=true` and `test=false` values are still valid, and you only need to adjust the invocation if you were explicitly passing the `reference_backend` or `expected_value_and_grad` arguments.)
25+
26+
There is now also an `rng` keyword argument to help seed parameter generation.
27+
28+
Finally, instead of specifying `value_atol` and `grad_atol`, you can now specify `atol` and `rtol` which are used for both value and gradient.
29+
Their semantics are the same as in Julia's `isapprox`; two values are equal if they satisfy either `atol` or `rtol`.
30+
31+
### `DynamicPPL.TestUtils.check_model`
32+
33+
You now need to explicitly pass a `VarInfo` argument to `check_model` and `check_model_and_trace`.
34+
Previously, these functions would generate a new VarInfo for you (using an optionally provided `rng`).
35+
36+
### Evaluating model log-probabilities in more detail
37+
38+
Previously, during evaluation of a model, DynamicPPL only had the capability to store a _single_ log probability (`logp`) field.
39+
`DefaultContext`, `PriorContext`, and `LikelihoodContext` were used to control what this field represented: they would accumulate the log joint, log prior, or log likelihood, respectively.
40+
41+
In this version, we have overhauled this quite substantially.
42+
The technical details of exactly _how_ this is done is covered in the 'Accumulators' section below, but the upshot is that the log prior, log likelihood, and log Jacobian terms (for any linked variables) are separately tracked.
43+
44+
Specifically, you will want to use the following functions to access these log probabilities:
45+
46+
- `getlogprior(varinfo)` to get the log prior. **Note:** This version introduces new, more consistent behaviour for this function, in that it always returns the log-prior of the values in the original, untransformed space, even if the `varinfo` has been linked.
47+
- `getloglikelihood(varinfo)` to get the log likelihood.
48+
- `getlogjoint(varinfo)` to get the log joint probability. **Note:** Similar to `getlogprior`, this function now always returns the log joint of the values in the original, untransformed space, even if the `varinfo` has been linked.
49+
50+
If you are using linked VarInfos (e.g. if you are writing a sampler), you may find that you need to obtain the log probability of the variables in the transformed space.
51+
To this end, you can use:
52+
53+
- `getlogjac(varinfo)` to get the log Jacobian of the link transforms for any linked variables.
54+
- `getlogprior_internal(varinfo)` to get the log prior of the variables in the transformed space.
55+
- `getlogjoint_internal(varinfo)` to get the log joint probability of the variables in the transformed space.
56+
57+
Since transformations only apply to random variables, the likelihood is unaffected by linking.
58+
59+
### Removal of `PriorContext` and `LikelihoodContext`
60+
61+
Following on from the above, a number of DynamicPPL's contexts have been removed, most notably `PriorContext` and `LikelihoodContext`.
62+
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.
63+
64+
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).
65+
66+
If you were constructing a `LogDensityFunction` with `PriorContext`, you can now stick to `DefaultContext`.
67+
`LogDensityFunction` now has an extra field, called `getlogdensity`, which represents a function that takes a `VarInfo` and returns the log density you want.
68+
Thus, if you pass `getlogprior_internal` as the value of this parameter, you will get the same behaviour as with `PriorContext`.
69+
(You should consider whether your use case needs the log prior in the transformed space, or the original space, and use (respectively) `getlogprior_internal` or `getlogprior` as needed.)
70+
71+
The other case where one might use `PriorContext` was to use `@addlogprob!` to add to the log prior.
72+
Previously, this was accomplished by manually checking `__context__ isa DynamicPPL.PriorContext`.
73+
Now, you can write `@addlogprob (; logprior=x, loglikelihood=y)` to add `x` to the log-prior and `y` to the log-likelihood.
74+
75+
**Internals**
76+
77+
### Accumulators
78+
79+
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:
80+
81+
- `PriorContext` and `LikelihoodContext` no longer exist. By default, a `VarInfo` tracks both the log prior and the log likelihood separately, and they can be accessed with `getlogprior` and `getloglikelihood`. If you want to execute a model while only accumulating one of the two (to save clock cycles), you can do so by creating a `VarInfo` that only has one accumulator in it, e.g. `varinfo = setaccs!!(varinfo, (LogPriorAccumulator(),))`.
82+
- `MiniBatchContext` does not exist anymore. It can be replaced by creating and using a custom accumulator that replaces the default `LikelihoodContext`. We may introduce such an accumulator in DynamicPPL in the future, but for now you'll need to do it yourself.
83+
- `tilde_observe` and `observe` have been removed. `tilde_observe!!` still exists, and any contexts should modify its behaviour. We may further rework the call stack under `tilde_observe!!` in the near future.
84+
- `tilde_assume` no longer returns the log density of the current assumption as its second return value. We may further rework the `tilde_assume!!` call stack as well.
85+
- For literal observation statements like `0.0 ~ Normal(blahblah)` we used to call `tilde_observe!!` without the `vn` argument. This method no longer exists. Rather we call `tilde_observe!!` with `vn` set to `nothing`.
86+
- `set/reset/increment_num_produce!` have become `set/reset/increment_num_produce!!` (note the second exclamation mark). They are no longer guaranteed to modify the `VarInfo` in place, and one should always use the return value.
87+
- `@addlogprob!` now _always_ adds to the log likelihood. Previously it added to the log probability that the execution context specified, e.g. the log prior when using `PriorContext`.
88+
- `getlogp` now returns a `NamedTuple` with keys `logprior` and `loglikelihood`. If you want the log joint probability, which is what `getlogp` used to return, use `getlogjoint`.
89+
- Correspondingly `setlogp!!` and `acclogp!!` should now be called with a `NamedTuple` with keys `logprior` and `loglikelihood`. The `acclogp!!` method with a single scalar value has been deprecated and falls back on `accloglikelihood!!`, and the single scalar version of `setlogp!!` has been removed. Corresponding setter/accumulator functions exist for the log prior as well.
90+
91+
### Evaluation contexts
92+
93+
Historically, evaluating a DynamicPPL model has required three arguments: a model, some kind of VarInfo, and a context.
94+
It's less known, though, that since DynamicPPL 0.14.0 the _model_ itself actually contains a context as well.
95+
This version therefore excises the context argument, and instead uses `model.context` as the evaluation context.
96+
97+
The upshot of this is that many functions that previously took a context argument now no longer do.
98+
There were very few such functions where the context argument was actually used (most of them simply took `DefaultContext()` as the default value).
99+
100+
`evaluate!!(model, varinfo, ext_context)` is removed, and broadly speaking you should replace calls to that with `new_model = contextualize(model, ext_context); evaluate!!(new_model, varinfo)`.
101+
If the 'external context' `ext_context` is a parent context, then you should wrap `model.context` appropriately to ensure that its information content is not lost.
102+
If, on the other hand, `ext_context` is a `DefaultContext`, then you can just drop the argument entirely.
103+
104+
**To aid with this process, `contextualize` is now exported from DynamicPPL.**
105+
106+
The main situation where one _did_ want to specify an additional evaluation context was when that context was a `SamplingContext`.
107+
Doing this would allow you to run the model and sample fresh values, instead of just using the values that existed in the VarInfo object.
108+
Thus, this release also introduces the **unexported** function `evaluate_and_sample!!`.
109+
Essentially, `evaluate_and_sample!!(rng, model, varinfo, sampler)` is a drop-in replacement for `evaluate!!(model, varinfo, SamplingContext(rng, sampler))`.
110+
**Do note that this is an internal method**, and its name or semantics are liable to change in the future without warning.
111+
112+
There are many methods that no longer take a context argument, and listing them all would be too much.
113+
However, here are the more user-facing ones:
114+
115+
- `LogDensityFunction` no longer has a context field (or type parameter)
116+
- `DynamicPPL.TestUtils.AD.run_ad` no longer uses a context (and the returned `ADResult` object no longer has a context field)
117+
- `VarInfo(rng, model, sampler)` and other VarInfo constructors / functions that made VarInfos (e.g. `typed_varinfo`) from a model
118+
- `(::Model)(args...)`: specifically, this now only takes `rng` and `varinfo` arguments (with both being optional)
119+
- If you are using the `__context__` special variable inside a model, you will now have to use `__model__.context` instead
120+
121+
And a couple of more internal changes:
122+
123+
- Just like `evaluate!!`, the other functions `_evaluate!!`, `evaluate_threadsafe!!`, and `evaluate_threadunsafe!!` now no longer accept context arguments
124+
- `evaluate!!` no longer takes rng and sampler (if you used this, you should use `evaluate_and_sample!!` instead, or construct your own `SamplingContext`)
125+
- The model evaluation function, `model.f` for some `model::Model`, no longer takes a context as an argument
126+
- The internal representation and API dealing with submodels (i.e., `ReturnedModelWrapper`, `Sampleable`, `should_auto_prefix`, `is_rhs_model`) has been simplified. If you need to check whether something is a submodel, just use `x isa DynamicPPL.Submodel`. Note that the public API i.e. `to_submodel` remains completely untouched.
127+
3128
## 0.36.15
4129

5130
Bumped minimum Julia version to 1.10.8 to avoid potential crashes with `Core.Compiler.widenconst` (which Mooncake uses).

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.36.15"
3+
version = "0.37.0"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -21,6 +21,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2121
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
2222
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
2323
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
24+
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
2425
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2526
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
2627
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
@@ -46,7 +47,7 @@ DynamicPPLMooncakeExt = ["Mooncake"]
4647
[compat]
4748
ADTypes = "1"
4849
AbstractMCMC = "5"
49-
AbstractPPL = "0.11, 0.12"
50+
AbstractPPL = "0.13"
5051
Accessors = "0.1"
5152
BangBang = "0.4.1"
5253
Bijectors = "0.13.18, 0.14, 0.15"
@@ -68,6 +69,7 @@ MCMCChains = "6, 7"
6869
MacroTools = "0.5.6"
6970
Mooncake = "0.4.95"
7071
OrderedCollections = "1"
72+
Printf = "1.10"
7173
Random = "1.6"
7274
Requires = "1"
7375
Statistics = "1"

benchmarks/Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
1515
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
1616
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
1717

18+
[sources]
19+
DynamicPPL = {path = "../"}
20+
1821
[compat]
1922
ADTypes = "1.14.0"
2023
BenchmarkTools = "1.6.0"
2124
Distributions = "0.25.117"
22-
DynamicPPL = "0.36"
25+
DynamicPPL = "0.37"
2326
ForwardDiff = "0.10.38, 1"
2427
LogDensityProblems = "2.1.2"
2528
Mooncake = "0.4"

benchmarks/benchmarks.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Pkg
2-
# To ensure we benchmark the local version of DynamicPPL, dev the folder above.
3-
Pkg.develop(; path=joinpath(@__DIR__, ".."))
42

53
using DynamicPPLBenchmarks: Models, make_suite, model_dimension
64
using BenchmarkTools: @benchmark, median, run
@@ -100,4 +98,5 @@ PrettyTables.pretty_table(
10098
header=header,
10199
tf=PrettyTables.tf_markdown,
102100
formatters=ft_printf("%.1f", [6, 7]),
101+
crop=:none, # Always print the whole table, even if it doesn't fit in the terminal.
103102
)

benchmarks/src/DynamicPPLBenchmarks.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ function make_suite(model, varinfo_choice::Symbol, adbackend::Symbol, islinked::
8181
end
8282

8383
adbackend = to_backend(adbackend)
84-
context = DynamicPPL.DefaultContext()
8584

8685
if islinked
8786
vi = DynamicPPL.link(vi, model)
8887
end
8988

90-
f = DynamicPPL.LogDensityFunction(model, vi, context; adtype=adbackend)
89+
f = DynamicPPL.LogDensityFunction(
90+
model, DynamicPPL.getlogjoint_internal, vi; adtype=adbackend
91+
)
9192
# The parameters at which we evaluate f.
9293
θ = vi[:]
9394

docs/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
1313
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
1414

1515
[compat]
16-
AbstractPPL = "0.11, 0.12"
16+
AbstractPPL = "0.13"
1717
Accessors = "0.1"
1818
Distributions = "0.25"
1919
Documenter = "1"
2020
DocumenterMermaid = "0.1, 0.2"
21-
DynamicPPL = "0.36"
21+
DynamicPPL = "0.37"
2222
FillArrays = "0.13, 1"
2323
ForwardDiff = "0.10, 1"
2424
JET = "0.9, 0.10"

docs/make.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ makedocs(;
2121
sitename="DynamicPPL",
2222
# The API index.html page is fairly large, and violates the default HTML page size
2323
# threshold of 200KiB, so we double that.
24-
format=Documenter.HTML(; size_threshold=2^10 * 400),
24+
format=Documenter.HTML(;
25+
size_threshold=2^10 * 400, mathengine=Documenter.HTMLWriter.MathJax3()
26+
),
2527
modules=[DynamicPPL, Base.get_extension(DynamicPPL, :DynamicPPLMCMCChainsExt)],
2628
pages=[
2729
"Home" => "index.md", "API" => "api.md", "Internals" => ["internals/varinfo.md"]

docs/src/api.md

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ getargnames
3636
getmissings
3737
```
3838

39+
The context of a model can be set using [`contextualize`](@ref):
40+
41+
```@docs
42+
contextualize
43+
```
44+
3945
## Evaluation
4046

4147
With [`rand`](@ref) one can draw samples from the prior distribution of a [`Model`](@ref).
@@ -140,27 +146,15 @@ to_submodel
140146

141147
Note that a `[to_submodel](@ref)` is only sampleable; one cannot compute `logpdf` for its realizations.
142148

143-
In the past, one would instead embed sub-models using [`@submodel`](@ref), which has been deprecated since the introduction of [`to_submodel(model)`](@ref)
144-
145-
```@docs
146-
@submodel
147-
```
148-
149149
In the context of including models within models, it's also useful to prefix the variables in sub-models to avoid variable names clashing:
150150

151151
```@docs
152152
DynamicPPL.prefix
153153
```
154154

155-
Under the hood, [`to_submodel`](@ref) makes use of the following method to indicate that the model it's wrapping is a model over its return-values rather than something else
156-
157-
```@docs
158-
returned(::Model)
159-
```
160-
161155
## Utilities
162156

163-
It is possible to manually increase (or decrease) the accumulated log density from within a model function.
157+
It is possible to manually increase (or decrease) the accumulated log likelihood or prior from within a model function.
164158

165159
```@docs
166160
@addlogprob!
@@ -212,6 +206,21 @@ To test and/or benchmark the performance of an AD backend on a model, DynamicPPL
212206

213207
```@docs
214208
DynamicPPL.TestUtils.AD.run_ad
209+
```
210+
211+
The default test setting is to compare against ForwardDiff.
212+
You can have more fine-grained control over how to test the AD backend using the following types:
213+
214+
```@docs
215+
DynamicPPL.TestUtils.AD.AbstractADCorrectnessTestSetting
216+
DynamicPPL.TestUtils.AD.WithBackend
217+
DynamicPPL.TestUtils.AD.WithExpectedResult
218+
DynamicPPL.TestUtils.AD.NoTest
219+
```
220+
221+
These are returned / thrown by the `run_ad` function:
222+
223+
```@docs
215224
DynamicPPL.TestUtils.AD.ADResult
216225
DynamicPPL.TestUtils.AD.ADIncorrectException
217226
```
@@ -329,10 +338,10 @@ The following functions were used for sequential Monte Carlo methods.
329338

330339
```@docs
331340
get_num_produce
332-
set_num_produce!
333-
increment_num_produce!
334-
reset_num_produce!
335-
setorder!
341+
set_num_produce!!
342+
increment_num_produce!!
343+
reset_num_produce!!
344+
setorder!!
336345
set_retained_vns_del!
337346
```
338347

@@ -346,6 +355,23 @@ Base.empty!
346355
SimpleVarInfo
347356
```
348357

358+
### Accumulators
359+
360+
The subtypes of [`AbstractVarInfo`](@ref) store the cumulative log prior and log likelihood, and sometimes other variables that change during executing, in what are called accumulators.
361+
362+
```@docs
363+
AbstractAccumulator
364+
```
365+
366+
DynamicPPL provides the following default accumulators.
367+
368+
```@docs
369+
LogPriorAccumulator
370+
LogJacobianAccumulator
371+
LogLikelihoodAccumulator
372+
VariableOrderAccumulator
373+
```
374+
349375
### Common API
350376

351377
#### Accumulation of log-probabilities
@@ -354,6 +380,18 @@ SimpleVarInfo
354380
getlogp
355381
setlogp!!
356382
acclogp!!
383+
getlogjoint
384+
getlogjoint_internal
385+
getlogjac
386+
setlogjac!!
387+
acclogjac!!
388+
getlogprior
389+
getlogprior_internal
390+
setlogprior!!
391+
acclogprior!!
392+
getloglikelihood
393+
setloglikelihood!!
394+
accloglikelihood!!
357395
resetlogp!!
358396
```
359397

@@ -416,21 +454,26 @@ DynamicPPL.varname_and_value_leaves
416454

417455
### Evaluation Contexts
418456

419-
Internally, both sampling and evaluation of log densities are performed with [`AbstractPPL.evaluate!!`](@ref).
457+
Internally, model evaluation is performed with [`AbstractPPL.evaluate!!`](@ref).
420458

421459
```@docs
422460
AbstractPPL.evaluate!!
423461
```
424462

425-
The behaviour of a model execution can be changed with evaluation contexts that are passed as additional argument to the model function.
463+
This method mutates the `varinfo` used for execution.
464+
By default, it does not perform any actual sampling: it only evaluates the model using the values of the variables that are already in the `varinfo`.
465+
To perform sampling, you can either wrap `model.context` in a `SamplingContext`, or use this convenience method:
466+
467+
```@docs
468+
DynamicPPL.evaluate_and_sample!!
469+
```
470+
471+
The behaviour of a model execution can be changed with evaluation contexts, which are a field of the model.
426472
Contexts are subtypes of `AbstractPPL.AbstractContext`.
427473

428474
```@docs
429475
SamplingContext
430476
DefaultContext
431-
LikelihoodContext
432-
PriorContext
433-
MiniBatchContext
434477
PrefixContext
435478
ConditionContext
436479
```
@@ -477,7 +520,3 @@ DynamicPPL.Experimental.is_suitable_varinfo
477520
```@docs
478521
tilde_assume
479522
```
480-
481-
```@docs
482-
tilde_observe
483-
```

0 commit comments

Comments
 (0)