Skip to content

Releases: TuringLang/DynamicPPL.jl

v0.36.2

09 May 18:29
cdeb657
Compare
Choose a tag to compare

DynamicPPL v0.36.2

Diff since v0.36.1

Improved docstrings for AD testing utilities.

Merged pull requests:

v0.36.1

28 Apr 14:49
e75fd1e
Compare
Choose a tag to compare

DynamicPPL v0.36.1

Diff since v0.36.0

Fixed a missing method for tilde_assume.

Merged pull requests:

  • CompatHelper: add new compat entry for AbstractPPL at version 0.11 for package docs, (keep existing compat) (#902) (@github-actions[bot])
  • CompatHelper: add new compat entry for DynamicPPL at version 0.36 for package docs, (keep existing compat) (#903) (@github-actions[bot])

Closed issues:

  • Conditioning on submodel variables (#857)

v0.36.0

24 Apr 17:04
23834de
Compare
Choose a tag to compare

DynamicPPL v0.36.0

Diff since v0.35.9

Breaking changes

Submodels: conditioning

Variables in a submodel can now be conditioned and fixed in a correct way.
See #857 for a full illustration, but essentially it means you can now do this:

@model function inner()
    x ~ Normal()
    return y ~ Normal()
end
@model function outer()
    return a ~ to_submodel(inner() | (x=1.0,))
end

and the a.x variable will be correctly conditioned.
(Previously, you would have to condition inner() with the variable a.x, meaning that you would need to know what prefix to use before you had actually prefixed it.)

Submodel prefixing

The way in which VarNames in submodels are prefixed has been changed.
This is best explained through an example.
Consider this model and submodel:

using DynamicPPL, Distributions
@model inner() = x ~ Normal()
@model outer() = a ~ to_submodel(inner())

In previous versions, the inner variable x would be saved as a.x.
However, this was represented as a single symbol Symbol("a.x"):

julia> dump(keys(VarInfo(outer()))[1])
VarName{Symbol("a.x"), typeof(identity)}
  optic: identity (function of type typeof(identity))

Now, the inner variable is stored as a field x on the VarName a:

julia> dump(keys(VarInfo(outer()))[1])
VarName{:a, Accessors.PropertyLens{:x}}
  optic: Accessors.PropertyLens{:x} (@o _.x)

In practice, this means that if you are trying to condition a variable in the submodel, you now need to use

outer() | (@varname(a.x) => 1.0,)

instead of either of these (which would have worked previously)

outer() | (@varname(var"a.x") => 1.0,)
outer() | (a.x=1.0,)

In a similar way, if the variable on the left-hand side of your tilde statement is not just a single identifier, any fields or indices it accesses are now properly respected.
Consider the following setup:

using DynamicPPL, Distributions
@model inner() = x ~ Normal()
@model function outer()
    a = Vector{Float64}(undef, 1)
    a[1] ~ to_submodel(inner())
    return a
end

In this case, the variable sampled is actually the x field of the first element of a:

julia> only(keys(VarInfo(outer()))) == @varname(a[1].x)
true

Before this version, it used to be a single variable called var"a[1].x".

Note that if you are sampling from a model with submodels, this doesn't affect the way you interact with the MCMCChains.Chains object, because VarNames are converted into Symbols when stored in the chain.
(This behaviour will likely be changed in the future, in that Chains should be indexable by VarNames and not just Symbols, but that has not been implemented yet.)

AD testing utilities

DynamicPPL.TestUtils.AD.run_ad now links the VarInfo by default.
To disable this, pass the linked=false keyword argument.
If the calculated value or gradient is incorrect, it also throws a DynamicPPL.TestUtils.AD.ADIncorrectException rather than a test failure.
This exception contains the actual and expected gradient so you can inspect it if needed; see the documentation for more information.
From a practical perspective, this means that if you need to add this to a test suite, you need to use @test run_ad(...) isa Any rather than just run_ad(...).

SimpleVarInfo linking / invlinking

Linking a linked SimpleVarInfo, or invlinking an unlinked SimpleVarInfo, now displays a warning instead of an error.

VarInfo constructors

VarInfo(vi::VarInfo, values) has been removed. You can replace this directly with unflatten(vi, values) instead.

The metadata argument to VarInfo([rng, ]model[, sampler, context, metadata]) has been removed.
If you were not using this argument (most likely), then there is no change needed.
If you were using the metadata argument to specify a blank VarNamedVector, then you should replace calls to VarInfo with DynamicPPL.typed_vector_varinfo instead (see 'Other changes' below).

The UntypedVarInfo constructor and type is no longer exported.
If you needed to construct one, you should now use DynamicPPL.untyped_varinfo instead.

The TypedVarInfo constructor and type is no longer exported.
The type has been replaced with DynamicPPL.NTVarInfo.
The constructor has been replaced with DynamicPPL.typed_varinfo.

Note that the exact kind of VarInfo returned by VarInfo(rng, model, ...) is an implementation detail.
Previously, it was guaranteed that this would always be a VarInfo whose metadata was a NamedTuple containing Metadata structs.
Going forward, this is no longer the case, and you should only assume that the returned object obeys the AbstractVarInfo interface.

Other changes

While these are technically breaking, they are only internal changes and do not affect the public API.
The following four functions have been added and/or reworked to make it easier to construct VarInfos with different types of metadata:

  1. DynamicPPL.untyped_varinfo([rng, ]model[, sampler, context])
  2. DynamicPPL.typed_varinfo([rng, ]model[, sampler, context])
  3. DynamicPPL.untyped_vector_varinfo([rng, ]model[, sampler, context])
  4. DynamicPPL.typed_vector_varinfo([rng, ]model[, sampler, context])

The reason for this change is that there were several flavours of VarInfo.
Some, like typed_varinfo, were easy to construct because we had convenience methods for them; however, the others were more difficult.
This change makes it easier to access different VarInfo types, and also makes it more explicit which one you are constructing.

Merged pull requests:

v0.35.9

23 Apr 01:46
cb4ea95
Compare
Choose a tag to compare

DynamicPPL v0.35.9

Diff since v0.35.8

Fixed the isnan check introduced in 0.35.7 for distributions which returned NamedTuple.

Merged pull requests:

  • Link varinfo by default in AD testing utilities; make test suite run on linked varinfos (#890) (@penelopeysm)
  • Fix isnan for NamedTuple distributions (#897) (@penelopeysm)

Closed issues:

  • Pretty printing show also for TypedVarInfo (#243)
  • Add Enzyme to AD tests (#739)
  • isnan check on NamedTuples with nested vectors fails (#898)

v0.35.8

14 Apr 15:21
60ee68e
Compare
Choose a tag to compare

DynamicPPL v0.35.8

Diff since v0.35.7

Added the DynamicPPL.TestUtils.AD.run_ad function to test the correctness and/or benchmark the performance of an automatic differentiation backend on DynamicPPL models.
Please see the docstring for more information.

v0.35.7

11 Apr 13:54
c7bdc3f
Compare
Choose a tag to compare

DynamicPPL v0.35.7

Diff since v0.35.6

check_model_and_trace now errors if any NaN's are encountered when evaluating the model.

Merged pull requests:

Closed issues:

  • Avoid unnecessary computation with generated_quantities (#884)

v0.35.6

28 Mar 11:53
eed80e5
Compare
Choose a tag to compare

DynamicPPL v0.35.6

Diff since v0.35.5

Fixed the implementation of .~, such that running a model with it no longer requires DynamicPPL itself to be loaded.

Merged pull requests:

  • simplify benchmarking commit ref (#855) (@yebai)
  • CompatHelper: bump compat for ForwardDiff to 1 for package docs, (keep existing compat) (#865) (@github-actions[bot])
  • CompatHelper: bump compat for ForwardDiff to 1 for package test, (keep existing compat) (#866) (@github-actions[bot])

Closed issues:

  • Make Sampler a field of DefaultContext (renamed to SamplingContext) (#80)
  • Restrict values_as_in_model to specific varnames? (#845)

v0.35.5

22 Mar 15:55
0810e14
Compare
Choose a tag to compare

DynamicPPL v0.35.5

Diff since v0.35.4

Several internal methods have been removed:

  • DynamicPPL.getall(vi::AbstractVarInfo) has been removed. You can directly replace this with getindex_internal(vi, Colon()).
  • DynamicPPL.setall!(vi::AbstractVarInfo, values) has been removed. Rewrite the calling function to not assume mutation and use unflatten(vi, values) instead.
  • DynamicPPL.replace_values(md::Metadata, values) and DynamicPPL.replace_values(nt::NamedTuple, values) (where the nt is a NamedTuple of Metadatas) have been removed. Use DynamicPPL.unflatten_metadata as a direct replacement.
  • DynamicPPL.set_values!!(vi::AbstractVarInfo, values) has been renamed to DynamicPPL.set_initial_values(vi::AbstractVarInfo, values); it also no longer mutates the varinfo argument.

The exported method VarInfo(vi::VarInfo, values) has been deprecated, and will be removed in the next minor version. You can replace this directly with unflatten(vi, values) instead.

v0.35.4

19 Mar 22:28
e4fa7f2
Compare
Choose a tag to compare

DynamicPPL v0.35.4

Diff since v0.35.3

Fixed a type instability in an implementation of with_logabsdet_jacobian, which resulted in the log-jacobian returned being an Int in some cases and a Float in others.
This resolves an Enzyme.jl error on a number of models.
More generally, this version also changes the type of various log probabilities to be more consistent with one another.
Although we aren't fully there yet, our eventual aim is that log probabilities will generally default to Float64 on 64-bit systems, and Float32 on 32-bit systems.
If you run into any issues with these types, please get in touch.

Merged pull requests:

v0.35.3

18 Mar 16:22
48aca59
Compare
Choose a tag to compare

DynamicPPL v0.35.3

Diff since v0.35.2

model | (@varname(x) => 1.0, @varname(y) => 2.0) now works. Previously, this would throw a MethodError if the tuple had more than one element.