Skip to content

Commit 1a4e4f3

Browse files
committed
Merge remote-tracking branch 'origin/breaking' into mhauru/accumulators-stage2
2 parents 175b633 + 3af63d5 commit 1a4e4f3

Some content is hidden

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

59 files changed

+873
-1050
lines changed

.github/workflows/CompatHelper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
env:
1515
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1616
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
17-
run: julia -e 'using CompatHelper; CompatHelper.main(; subdirs = ["", "docs", "test"])'
17+
run: julia -e 'using CompatHelper; CompatHelper.main(; subdirs = ["", "docs", "test", "benchmarks"])'

.github/workflows/DocTest.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# We want to only run doctests on a single version of Julia, because
2+
# things like error messages / output can change between versions and
3+
# is fragile to test against.
4+
name: Doctests
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
pull_request:
11+
merge_group:
12+
types: [checks_requested]
13+
14+
# needed to allow julia-actions/cache to delete old caches that it has created
15+
permissions:
16+
actions: write
17+
contents: read
18+
19+
# Cancel existing tests on the same PR if a new commit is added to a pull request
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
22+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
23+
24+
jobs:
25+
test:
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- uses: julia-actions/setup-julia@v2
32+
with:
33+
version: '1'
34+
35+
- uses: julia-actions/cache@v2
36+
37+
- uses: julia-actions/julia-buildpkg@v1
38+
39+
- uses: julia-actions/julia-runtest@v1
40+
env:
41+
GROUP: Doctests

.github/workflows/Docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ concurrency:
1717

1818
permissions:
1919
contents: write
20-
pull-requests: read
20+
pull-requests: write
2121

2222
jobs:
2323
docs:

.github/workflows/Enzyme.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Enzyme on demo models
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
# needed to allow julia-actions/cache to delete old caches that it has created
10+
permissions:
11+
actions: write
12+
contents: read
13+
14+
# Cancel existing tests on the same PR if a new commit is added to a pull request
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
17+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
18+
19+
jobs:
20+
enzyme:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- uses: julia-actions/setup-julia@v2
26+
with:
27+
version: "1"
28+
29+
- uses: julia-actions/cache@v2
30+
31+
- name: Run AD with Enzyme on demo models
32+
working-directory: test/integration/enzyme
33+
run: |
34+
julia --project=. --color=yes -e 'using Pkg; Pkg.instantiate()'
35+
julia --project=. --color=yes main.jl

.github/workflows/JuliaPre.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ permissions:
1414
jobs:
1515
test:
1616
runs-on: ubuntu-latest
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
test_group:
22+
- Group1
23+
- Group2
24+
1725
steps:
1826
- uses: actions/checkout@v4
1927
- uses: julia-actions/setup-julia@v2
@@ -22,3 +30,5 @@ jobs:
2230
- uses: julia-actions/cache@v2
2331
- uses: julia-actions/julia-buildpkg@v1
2432
- uses: julia-actions/julia-runtest@v1
33+
env:
34+
GROUP: ${{ matrix.test_group }}

HISTORY.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,97 @@ This release overhauls how VarInfo objects track variables such as the log joint
1818
- `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`.
1919
- 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.
2020

21+
### Evaluation contexts
22+
23+
Historically, evaluating a DynamicPPL model has required three arguments: a model, some kind of VarInfo, and a context.
24+
It's less known, though, that since DynamicPPL 0.14.0 the _model_ itself actually contains a context as well.
25+
This version therefore excises the context argument, and instead uses `model.context` as the evaluation context.
26+
27+
The upshot of this is that many functions that previously took a context argument now no longer do.
28+
There were very few such functions where the context argument was actually used (most of them simply took `DefaultContext()` as the default value).
29+
30+
`evaluate!!(model, varinfo, ext_context)` is deprecated, and broadly speaking you should replace calls to that with `new_model = contextualize(model, ext_context); evaluate!!(new_model, varinfo)`.
31+
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.
32+
If, on the other hand, `ext_context` is a `DefaultContext`, then you can just drop the argument entirely.
33+
34+
To aid with this process, `contextualize` is now exported from DynamicPPL.
35+
36+
The main situation where one _did_ want to specify an additional evaluation context was when that context was a `SamplingContext`.
37+
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.
38+
Thus, this release also introduces the **unexported** function `evaluate_and_sample!!`.
39+
Essentially, `evaluate_and_sample!!(rng, model, varinfo, sampler)` is a drop-in replacement for `evaluate!!(model, varinfo, SamplingContext(rng, sampler))`.
40+
**Do note that this is an internal method**, and its name or semantics are liable to change in the future without warning.
41+
42+
There are many methods that no longer take a context argument, and listing them all would be too much.
43+
However, here are the more user-facing ones:
44+
45+
- `LogDensityFunction` no longer has a context field (or type parameter)
46+
- `DynamicPPL.TestUtils.AD.run_ad` no longer uses a context (and the returned `ADResult` object no longer has a context field)
47+
- `VarInfo(rng, model, sampler)` and other VarInfo constructors / functions that made VarInfos (e.g. `typed_varinfo`) from a model
48+
- `(::Model)(args...)`: specifically, this now only takes `rng` and `varinfo` arguments (with both being optional)
49+
- If you are using the `__context__` special variable inside a model, you will now have to use `__model__.context` instead
50+
51+
And a couple of more internal changes:
52+
53+
- `evaluate!!`, `evaluate_threadsafe!!`, and `evaluate_threadunsafe!!` no longer accept context arguments
54+
- `evaluate!!` no longer takes rng and sampler (if you used this, you should use `evaluate_and_sample!!` instead, or construct your own `SamplingContext`)
55+
- The model evaluation function, `model.f` for some `model::Model`, no longer takes a context as an argument
56+
57+
## 0.36.12
58+
59+
Removed several unexported functions.
60+
The only notable one is `DynamicPPL.alg_str`, which was used in old versions of AdvancedVI and the Turing test suite.
61+
62+
## 0.36.11
63+
64+
Make `ThreadSafeVarInfo` hold a total of `Threads.nthreads() * 2` logp values, instead of just `Threads.nthreads()`.
65+
This fix helps to paper over the cracks in using `threadid()` to index into the `ThreadSafeVarInfo` object.
66+
67+
## 0.36.10
68+
69+
Added compatibility with ForwardDiff 1.0.
70+
71+
## 0.36.9
72+
73+
Fixed a failure when sampling from `ProductNamedTupleDistribution` due to
74+
missing `tovec` methods for `NamedTuple` and `Tuple`.
75+
76+
## 0.36.8
77+
78+
Made `LogDensityFunction` a subtype of `AbstractMCMC.AbstractModel`.
79+
80+
## 0.36.7
81+
82+
Added compatibility with MCMCChains 7.0.
83+
84+
## 0.36.6
85+
86+
`DynamicPPL.TestUtils.run_ad` now takes an extra `context` keyword argument, which is passed to the `LogDensityFunction` constructor.
87+
88+
## 0.36.5
89+
90+
`varinfo[:]` now returns an empty vector if `varinfo::DynamicPPL.NTVarInfo` is empty, rather than erroring.
91+
92+
In its place, `check_model` now issues a warning if the model is empty.
93+
94+
## 0.36.4
95+
96+
Added compatibility with DifferentiationInterface.jl 0.7, and also with JET.jl 0.10.
97+
98+
The JET compatibility entry should only affect you if you are using DynamicPPL on the Julia 1.12 pre-release.
99+
100+
## 0.36.3
101+
102+
Moved the `bijector(model)`, where `model` is a `DynamicPPL.Model`, function from the Turing main repo.
103+
104+
## 0.36.2
105+
106+
Improved docstrings for AD testing utilities.
107+
108+
## 0.36.1
109+
110+
Fixed a missing method for `tilde_assume`.
111+
21112
## 0.36.0
22113

23114
**Breaking changes**

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ ChainRulesCore = "1"
5555
Chairmarks = "1.3.1"
5656
Compat = "4"
5757
ConstructionBase = "1.5.4"
58-
DifferentiationInterface = "0.6.41"
58+
DifferentiationInterface = "0.6.41, 0.7"
5959
Distributions = "0.25"
6060
DocStringExtensions = "0.9"
6161
EnzymeCore = "0.6 - 0.8"
62-
ForwardDiff = "0.10.12"
62+
ForwardDiff = "0.10.12, 1"
6363
InteractiveUtils = "1"
64-
JET = "0.9"
64+
JET = "0.9, 0.10"
6565
KernelAbstractions = "0.9.33"
6666
LinearAlgebra = "1.6"
6767
LogDensityProblems = "2"
68-
MCMCChains = "6"
68+
MCMCChains = "6, 7"
6969
MacroTools = "0.5.6"
7070
Mooncake = "0.4.95"
7171
OrderedCollections = "1"

benchmarks/Project.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ 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-
ForwardDiff = "0.10.38"
25+
DynamicPPL = "0.37"
26+
ForwardDiff = "0.10.38, 1"
2327
LogDensityProblems = "2.1.2"
28+
Mooncake = "0.4"
2429
PrettyTables = "2.4.0"
2530
ReverseDiff = "1.15.3"
31+
StableRNGs = "1"

benchmarks/benchmarks.jl

Lines changed: 0 additions & 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

benchmarks/src/DynamicPPLBenchmarks.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Return the dimension of `model`, accounting for linking, if any.
2323
"""
2424
function model_dimension(model, islinked)
2525
vi = VarInfo()
26-
model(vi)
26+
model(StableRNG(23), vi)
2727
if islinked
2828
vi = DynamicPPL.link(vi, model)
2929
end
@@ -81,15 +81,12 @@ 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(
91-
model, DynamicPPL.getlogjoint, vi, context; adtype=adbackend
92-
)
89+
f = DynamicPPL.LogDensityFunction(model, DynamicPPL.getlogjoint, vi; adtype=adbackend)
9390
# The parameters at which we evaluate f.
9491
θ = vi[:]
9592

0 commit comments

Comments
 (0)