Skip to content

Commit

Permalink
Fix a Gibbs bug with models where linking changes variable dimension (#…
Browse files Browse the repository at this point in the history
…2472)

* Add a test that catches a bug in Gibbs

* Bump patch version to 0.36.1

* Bump DPPL compat to 0.34.1

* Expand comment
  • Loading branch information
mhauru authored Jan 23, 2025
1 parent 8bf98e1 commit ea35bb7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Turing"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.36.1"
version = "0.36.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -63,7 +63,7 @@ Distributions = "0.23.3, 0.24, 0.25"
DistributionsAD = "0.6"
DocStringExtensions = "0.8, 0.9"
DynamicHMC = "3.4"
DynamicPPL = "0.33, 0.34"
DynamicPPL = "0.34.1"
EllipticalSliceSampling = "0.5, 1, 2"
ForwardDiff = "0.10.3"
Libtask = "0.8.8"
Expand Down
20 changes: 20 additions & 0 deletions test/mcmc/gibbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,26 @@ end
check_numerical(chain, [:m1, :m2], [-0.2, 0.6]; atol=0.1)
end
end

# Test a model that where the sampler needs to link a variable, which consequently
# changes dimension. This used to error because the initial value `VarInfo`,
# obtained from just `VarInfo(model)`, had a value of dimension 2 for `w`, and the one
# coming out of the initial step of the component sampler had a dimension of 1, since
# the latter was linked. `merge` of the varinfos couldn't handle that before DPPL
# 0.34.1.
@testset "linking changes dimension" begin
@model function dirichlet_model()
K = 2
w ~ Dirichlet(K, 1.0)
for i in 1:K
0.1 ~ Normal(w[i], 1.0)
end
end

model = dirichlet_model()
sampler = Gibbs(:w => HMC(0.05, 10))
@test (sample(model, sampler, 10); true)
end
end

end

2 comments on commit ea35bb7

@mhauru
Copy link
Member Author

@mhauru mhauru commented on ea35bb7 Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/123568

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.36.2 -m "<description of version>" ea35bb747b64442890cf9446517fec1af9765092
git push origin v0.36.2

Please sign in to comment.