Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Added `evaluate!!(model, context, vi)` to evaluate with an explicit leaf context

## Breaking changes

`keys`, `haskey`, `length`, `values`, `isempty` and `is_transformed(vi)` on a `VarInfo` without a `VectorValueAccumulator` now throw an `ArgumentError` instead of reporting no variables. Record values with `VarInfo(VectorValueAccumulator(), DynamicPPL.default_accumulators()...)` in place of `VarInfo()`.

`marginalize` and the `DynamicPPLMarginalLogDensitiesExt` extension are removed in DynamicPPL 0.43. Users requiring the existing Turing/MLD integration can remain on DynamicPPL 0.42.x with a compatible Turing release—for example, Turing 0.49.0—and MarginalLogDensities 0.4.3–0.4.x. See the [0.42 marginalisation documentation](https://turinglang.org/DynamicPPL.jl/v0.42/api/#Marginalisation).

On newer DynamicPPL versions, MLD’s generic API requires a manually constructed log-density adapter; no drop-in model-level replacement is currently available. Migration of the integration into MLD is proposed in [MLD #47](https://github.com/ElOceanografo/MarginalLogDensities.jl/pull/47).
Expand Down
7 changes: 7 additions & 0 deletions src/abstract_varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ end
keys(vi::AbstractVarInfo)

Return an iterator over all `vns` in `vi`.

Throw an `ArgumentError` if `vi` has no `VectorValueAccumulator`.
""" Base.keys

"""
Expand Down Expand Up @@ -528,6 +530,8 @@ This is useful when using a sampling algorithm that assumes an empty `vi`, e.g.
isempty(vi::AbstractVarInfo)

Return true if `vi` is empty and false otherwise.

Throw an `ArgumentError` if `vi` has no `VectorValueAccumulator`.
""" Base.isempty

"""
Expand Down Expand Up @@ -564,6 +568,8 @@ Subset a `varinfo` to only contain the variables `vns`.
The ordering of variables in the return value will be the same as in `varinfo`.

# Examples

```jldoctest varinfo-subset
julia> using DynamicPPL, Distributions

julia> @model function demo()
Expand Down Expand Up @@ -675,6 +681,7 @@ Return `true` if all variables in `vi` have a transform of `DynamicLink`, and fa
otherwise.

If `vns` is provided, then only check if this/these varname(s) are transformed.
Throw an `ArgumentError` if `vi` has no `VectorValueAccumulator`, unless `vns` is empty.

!!! warning
Not all implementations of `AbstractVarInfo` support transforming only a subset of
Expand Down
10 changes: 5 additions & 5 deletions src/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ get_vector_values(vi::AbstractVarInfo) = getacc(vi, Val(VECTORVAL_ACCNAME)).valu
get_values(vi::AbstractVarInfo) = get_vector_values(vi)

function Base.keys(vi::Union{VarInfo,ThreadSafeVarInfo})
return hasacc(vi, Val(VECTORVAL_ACCNAME)) ? keys(get_vector_values(vi)) : ()
return keys(get_vector_values(vi))
end
function Base.haskey(vi::Union{VarInfo,ThreadSafeVarInfo}, vn::VarName)
return hasacc(vi, Val(VECTORVAL_ACCNAME)) && haskey(get_vector_values(vi), vn)
return haskey(get_vector_values(vi), vn)
end
function Base.length(vi::Union{VarInfo,ThreadSafeVarInfo})
return hasacc(vi, Val(VECTORVAL_ACCNAME)) ? length(get_vector_values(vi)) : 0
return length(get_vector_values(vi))
end
function Base.values(vi::Union{VarInfo,ThreadSafeVarInfo})
return hasacc(vi, Val(VECTORVAL_ACCNAME)) ? values(get_vector_values(vi)) : ()
return values(get_vector_values(vi))
end
function Base.isempty(vi::Union{VarInfo,ThreadSafeVarInfo})
return !hasacc(vi, Val(VECTORVAL_ACCNAME)) || isempty(get_vector_values(vi))
return isempty(get_vector_values(vi))
end
Base.empty(vi::VarInfo) = resetaccs!!(copy(vi))
BangBang.empty!!(vi::VarInfo) = resetaccs!!(vi)
Expand Down
11 changes: 6 additions & 5 deletions test/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ end

@testset "no recorded values" begin
for vi in (VarInfo(), DynamicPPL.ThreadSafeVarInfo(VarInfo()))
@test @inferred isempty(vi)
@test isempty(@inferred keys(vi))
@test isempty(@inferred values(vi))
@test !(@inferred haskey(vi, @varname(x)))
@test (@inferred length(vi)) == 0
@test_throws ArgumentError isempty(vi)
@test_throws ArgumentError keys(vi)
@test_throws ArgumentError values(vi)
@test_throws ArgumentError haskey(vi, @varname(x))
@test_throws ArgumentError length(vi)
@test_throws ArgumentError is_transformed(vi)
@test_throws ArgumentError get_vector_values(vi)
@test_throws ArgumentError internal_values_as_vector(vi)
@test_throws ArgumentError vi[:]
Expand Down
Loading