Skip to content

Commit a76e366

Browse files
committed
Merge remote-tracking branch 'origin/breaking' into mhauru/varnamedvector-as-default
2 parents 528ccb3 + 6dc7c02 commit a76e366

File tree

9 files changed

+44
-27
lines changed

9 files changed

+44
-27
lines changed

.github/workflows/Benchmarking.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ jobs:
5959
echo "DPPL_COMMIT_URL=$COMMIT_URL" >> $GITHUB_ENV
6060
6161
- name: Find Existing Comment
62-
uses: peter-evans/find-comment@v3
62+
uses: peter-evans/find-comment@v4
6363
id: find_comment
6464
with:
6565
issue-number: ${{ github.event.pull_request.number }}
6666
comment-author: github-actions[bot]
6767

6868
- name: Post Benchmark Results as PR Comment
69-
uses: peter-evans/create-or-update-comment@v4
69+
uses: peter-evans/create-or-update-comment@v5
7070
with:
7171
issue-number: ${{ github.event.pull_request.number }}
7272
body: |

HISTORY.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
Removed the method `returned(::Model, values, keys)`; please use `returned(::Model, ::AbstractDict{<:VarName})` instead.
66

7+
## 0.38.7
8+
9+
Made a small tweak to DynamicPPL's compiler output to avoid potential undefined variables when resuming model functions midway through (e.g. with Libtask in Turing's SMC/PG samplers).
10+
11+
## 0.38.6
12+
13+
Renamed keyword argument `only_ddpl` to `only_dppl` for `Experimental.is_suitable_varinfo`.
14+
15+
## 0.38.5
16+
17+
Improve performance of VarNamedVector, mostly by changing how it handles contiguification.
18+
719
## 0.38.4
820

921
Improve performance of VarNamedVector. It should now be very nearly on par with Metadata for all models we've benchmarked on.
@@ -19,8 +31,6 @@ The generic method `returned(::Model, values, keys)` is deprecated and will be r
1931

2032
Added a compatibility entry for [email protected].
2133

22-
> > > > > > > main
23-
2434
## 0.38.1
2535

2636
Added `from_linked_vec_transform` and `from_vec_transform` methods for `ProductNamedTupleDistribution`.

ext/DynamicPPLJETExt.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ using DynamicPPL: DynamicPPL
44
using JET: JET
55

66
function DynamicPPL.Experimental.is_suitable_varinfo(
7-
model::DynamicPPL.Model, varinfo::DynamicPPL.AbstractVarInfo; only_ddpl::Bool=true
7+
model::DynamicPPL.Model, varinfo::DynamicPPL.AbstractVarInfo; only_dppl::Bool=true
88
)
99
f, argtypes = DynamicPPL.DebugUtils.gen_evaluator_call_with_types(model, varinfo)
1010
# If specified, we only check errors originating somewhere in the DynamicPPL.jl.
1111
# This way we don't just fall back to untyped if the user's code is the issue.
12-
result = if only_ddpl
12+
result = if only_dppl
1313
JET.report_call(f, argtypes; target_modules=(JET.AnyFrameModule(DynamicPPL),))
1414
else
1515
JET.report_call(f, argtypes)
@@ -18,15 +18,15 @@ function DynamicPPL.Experimental.is_suitable_varinfo(
1818
end
1919

2020
function DynamicPPL.Experimental._determine_varinfo_jet(
21-
model::DynamicPPL.Model; only_ddpl::Bool=true
21+
model::DynamicPPL.Model; only_dppl::Bool=true
2222
)
2323
# Generate a typed varinfo to test model type stability with
2424
varinfo = DynamicPPL.typed_varinfo(model)
2525

2626
# Check type stability of evaluation (i.e. DefaultContext)
2727
model = DynamicPPL.setleafcontext(model, DynamicPPL.DefaultContext())
2828
eval_issuccess, eval_result = DynamicPPL.Experimental.is_suitable_varinfo(
29-
model, varinfo; only_ddpl
29+
model, varinfo; only_dppl
3030
)
3131
if !eval_issuccess
3232
@debug "Evaluation with typed varinfo failed with the following issues:"
@@ -36,7 +36,7 @@ function DynamicPPL.Experimental._determine_varinfo_jet(
3636
# Check type stability of initialisation (i.e. InitContext)
3737
model = DynamicPPL.setleafcontext(model, DynamicPPL.InitContext())
3838
init_issuccess, init_result = DynamicPPL.Experimental.is_suitable_varinfo(
39-
model, varinfo; only_ddpl
39+
model, varinfo; only_dppl
4040
)
4141
if !init_issuccess
4242
@debug "Initialisation with typed varinfo failed with the following issues:"

src/compiler.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,16 @@ function generate_tilde(left, right)
461461
elseif $isassumption
462462
$(generate_tilde_assume(left, dist, vn))
463463
else
464-
# If `vn` is not in `argnames`, we need to make sure that the variable is defined.
465-
if !$(DynamicPPL.inargnames)($vn, __model__)
466-
$left = $(DynamicPPL.getconditioned_nested)(
464+
# If `vn` is not in `argnames`, then it's definitely been conditioned on (if
465+
# it's not in `argnames` and wasn't conditioned on, then `isassumption` would
466+
# be true).
467+
$left = if $(DynamicPPL.inargnames)($vn, __model__)
468+
# This is a no-op and looks redundant, but defining the compiler output this
469+
# way ensures that the variable `$left` is always defined. See
470+
# https://github.com/TuringLang/DynamicPPL.jl/pull/1110.
471+
$left
472+
else
473+
$(DynamicPPL.getconditioned_nested)(
467474
__model__.context, $(DynamicPPL.prefix)(__model__.context, $vn)
468475
)
469476
end

src/experimental.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Check if the `model` supports evaluation using the provided `varinfo`.
1616
- `varinfo`: The varinfo to verify the support for.
1717
1818
# Keyword Arguments
19-
- `only_ddpl`: If `true`, only consider error reports occuring in the tilde pipeline. Default: `true`.
19+
- `only_dppl`: If `true`, only consider error reports occuring in the tilde pipeline. Default: `true`.
2020
2121
# Returns
2222
- `issuccess`: `true` if the model supports the varinfo, otherwise `false`.
@@ -28,7 +28,7 @@ function is_suitable_varinfo end
2828
function _determine_varinfo_jet end
2929

3030
"""
31-
determine_suitable_varinfo(model; only_ddpl::Bool=true)
31+
determine_suitable_varinfo(model; only_dppl::Bool=true)
3232
3333
Return a suitable varinfo for the given `model`.
3434
@@ -42,7 +42,7 @@ See also: [`DynamicPPL.Experimental.is_suitable_varinfo`](@ref).
4242
- `model`: The model for which to determine the varinfo.
4343
4444
# Keyword Arguments
45-
- `only_ddpl`: If `true`, only consider error reports within DynamicPPL.jl.
45+
- `only_dppl`: If `true`, only consider error reports within DynamicPPL.jl.
4646
4747
# Examples
4848
@@ -83,10 +83,10 @@ julia> vi isa typeof(DynamicPPL.typed_varinfo(model_with_static_support()))
8383
true
8484
```
8585
"""
86-
function determine_suitable_varinfo(model::DynamicPPL.Model; only_ddpl::Bool=true)
86+
function determine_suitable_varinfo(model::DynamicPPL.Model; only_dppl::Bool=true)
8787
# If JET.jl has been loaded, and thus `determine_varinfo` has been defined, we use that.
8888
return if Base.get_extension(DynamicPPL, :DynamicPPLJETExt) !== nothing
89-
_determine_varinfo_jet(model; only_ddpl)
89+
_determine_varinfo_jet(model; only_dppl)
9090
else
9191
# Warn the user.
9292
@warn "JET.jl is not loaded. Assumes the model is compatible with typed varinfo."

test/accumulators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ using DynamicPPL:
117117
@test at_all64[:LogLikelihood] == ll_f64
118118

119119
@test haskey(AccumulatorTuple(lp_f64), Val(:LogPrior))
120-
@test ~haskey(AccumulatorTuple(lp_f64), Val(:LogLikelihood))
120+
@test !haskey(AccumulatorTuple(lp_f64), Val(:LogLikelihood))
121121
@test length(AccumulatorTuple(lp_f64, ll_f64)) == 2
122122
@test keys(at_all64) == (:LogPrior, :LogLikelihood)
123123
@test collect(at_all64) == [lp_f64, ll_f64]

test/ext/DynamicPPLJETExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
DynamicPPL.NTVarInfo
5757
# Should fail if we're including errors in the model body.
5858
@test DynamicPPL.Experimental.determine_suitable_varinfo(
59-
demo5(); only_ddpl=false
59+
demo5(); only_dppl=false
6060
) isa DynamicPPL.UntypedVarInfo
6161
end
6262

test/varinfo.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ end
7373
r = rand(dist)
7474

7575
@test isempty(vi)
76-
@test ~haskey(vi, vn)
76+
@test !haskey(vi, vn)
7777
@test !(vn in keys(vi))
7878
vi = push!!(vi, vn, r, dist)
79-
@test ~isempty(vi)
79+
@test !isempty(vi)
8080
@test haskey(vi, vn)
8181
@test vn in keys(vi)
8282

@@ -97,7 +97,7 @@ end
9797
vi = empty!!(vi)
9898
@test isempty(vi)
9999
vi = push!!(vi, vn, r, dist)
100-
@test ~isempty(vi)
100+
@test !isempty(vi)
101101
end
102102

103103
test_base(VarInfo())

test/varnamedvector.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,14 @@ end
621621
vnv = DynamicPPL.VarNamedVector()
622622
vnv = setindex!!(vnv, 1.0, vn)
623623
vnv = setindex!!(vnv, 2, @varname(b))
624-
@test ~DynamicPPL.is_tightly_typed(vnv)
624+
@test !DynamicPPL.is_tightly_typed(vnv)
625625
test_tightenability(vnv)
626626
@inferred DynamicPPL.loosen_types!!(vnv, VarName, Any, Any)
627627
# Likewise when first mixed types are pushed, but then deleted.
628628
vnv = DynamicPPL.VarNamedVector()
629629
vnv = setindex!!(vnv, 1.0, vn)
630630
vnv = setindex!!(vnv, 2, @varname(b))
631-
@test ~DynamicPPL.is_tightly_typed(vnv)
631+
@test !DynamicPPL.is_tightly_typed(vnv)
632632
vnv = delete!!(vnv, vn)
633633
@test DynamicPPL.is_tightly_typed(vnv)
634634
test_tightenability(vnv)
@@ -646,17 +646,17 @@ end
646646
t = eltype(vnv.transforms)
647647
# Loosen key type.
648648
vnv = @inferred DynamicPPL.loosen_types!!(vnv, VarName, e, t)
649-
@test ~DynamicPPL.is_tightly_typed(vnv)
649+
@test !DynamicPPL.is_tightly_typed(vnv)
650650
vnv = DynamicPPL.tighten_types!!(vnv)
651651
@test DynamicPPL.is_tightly_typed(vnv)
652652
# Loosen element type
653653
vnv = @inferred DynamicPPL.loosen_types!!(vnv, k, Real, t)
654-
@test ~DynamicPPL.is_tightly_typed(vnv)
654+
@test !DynamicPPL.is_tightly_typed(vnv)
655655
vnv = DynamicPPL.tighten_types!!(vnv)
656656
@test DynamicPPL.is_tightly_typed(vnv)
657657
# Loosen transformation type
658658
vnv = @inferred DynamicPPL.loosen_types!!(vnv, k, e, Function)
659-
@test ~DynamicPPL.is_tightly_typed(vnv)
659+
@test !DynamicPPL.is_tightly_typed(vnv)
660660
vnv = DynamicPPL.tighten_types!!(vnv)
661661
@test DynamicPPL.is_tightly_typed(vnv)
662662
# Loosening to the same types as currently should do nothing.

0 commit comments

Comments
 (0)