Skip to content

Commit ea35bb7

Browse files
authored
Fix a Gibbs bug with models where linking changes variable dimension (#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
1 parent 8bf98e1 commit ea35bb7

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Diff for: Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Turing"
22
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
3-
version = "0.36.1"
3+
version = "0.36.2"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -63,7 +63,7 @@ Distributions = "0.23.3, 0.24, 0.25"
6363
DistributionsAD = "0.6"
6464
DocStringExtensions = "0.8, 0.9"
6565
DynamicHMC = "3.4"
66-
DynamicPPL = "0.33, 0.34"
66+
DynamicPPL = "0.34.1"
6767
EllipticalSliceSampling = "0.5, 1, 2"
6868
ForwardDiff = "0.10.3"
6969
Libtask = "0.8.8"

Diff for: test/mcmc/gibbs.jl

+20
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,26 @@ end
759759
check_numerical(chain, [:m1, :m2], [-0.2, 0.6]; atol=0.1)
760760
end
761761
end
762+
763+
# Test a model that where the sampler needs to link a variable, which consequently
764+
# changes dimension. This used to error because the initial value `VarInfo`,
765+
# obtained from just `VarInfo(model)`, had a value of dimension 2 for `w`, and the one
766+
# coming out of the initial step of the component sampler had a dimension of 1, since
767+
# the latter was linked. `merge` of the varinfos couldn't handle that before DPPL
768+
# 0.34.1.
769+
@testset "linking changes dimension" begin
770+
@model function dirichlet_model()
771+
K = 2
772+
w ~ Dirichlet(K, 1.0)
773+
for i in 1:K
774+
0.1 ~ Normal(w[i], 1.0)
775+
end
776+
end
777+
778+
model = dirichlet_model()
779+
sampler = Gibbs(:w => HMC(0.05, 10))
780+
@test (sample(model, sampler, 10); true)
781+
end
762782
end
763783

764784
end

0 commit comments

Comments
 (0)