Skip to content

Commit ef5a0d1

Browse files
committed
Merge branch 'main' into breaking
2 parents c2ae953 + 411a341 commit ef5a0d1

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

HISTORY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Release 0.38.3
2+
3+
`getparams(::Model, ::AbstractVarInfo)` now returns an empty `Float64[]` if the VarInfo contains no parameters.
4+
5+
# Release 0.38.2
6+
7+
Bump compat for `MCMCChains` to `7`.
8+
By default, summary statistics and quantiles for chains are no longer printed; to access these you should use `describe(chain)`.
9+
110
# Release 0.38.1
211

312
The method `Bijectors.bijector(::DynamicPPL.Model)` was moved to DynamicPPL.jl.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ForwardDiff = "0.10.3"
6868
Libtask = "0.8.8"
6969
LinearAlgebra = "1"
7070
LogDensityProblems = "2"
71-
MCMCChains = "5, 6"
71+
MCMCChains = "5, 6, 7"
7272
NamedArrays = "0.9, 0.10"
7373
Optim = "1"
7474
Optimization = "3, 4"

src/mcmc/Inference.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ function getparams(model::DynamicPPL.Model, vi::DynamicPPL.VarInfo)
358358
# Materialize the iterators and concatenate.
359359
return mapreduce(collect, vcat, iters)
360360
end
361+
function getparams(::DynamicPPL.Model, ::DynamicPPL.VarInfo{NamedTuple{(),Tuple{}}})
362+
return float(Real)[]
363+
end
361364

362365
function _params_to_array(model::DynamicPPL.Model, ts::Vector)
363366
names_set = OrderedSet{VarName}()

src/mcmc/mh.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ end
246246
]
247247
return expr
248248
end
249+
_val_tuple(::VarInfo, ::Tuple{}) = ()
249250

250251
@generated function _dist_tuple(
251252
props::NamedTuple{propnames}, vi::VarInfo, vns::NamedTuple{names}
@@ -267,6 +268,7 @@ end
267268
]
268269
return expr
269270
end
271+
_dist_tuple(::@NamedTuple{}, ::VarInfo, ::Tuple{}) = ()
270272

271273
# Utility functions to link
272274
should_link(varinfo, sampler, proposal) = false

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ HypothesisTests = "0.11"
5959
LinearAlgebra = "1"
6060
LogDensityProblems = "2"
6161
LogDensityProblemsAD = "1.4"
62-
MCMCChains = "5, 6"
62+
MCMCChains = "5, 6, 7"
6363
Mooncake = "0.4.95"
6464
NamedArrays = "0.9.4, 0.10"
6565
Optim = "1"

test/mcmc/Inference.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,39 @@ using Turing
631631
StableRNG(seed), demo_incorrect_missing([missing]), NUTS(), 10; check_model=true
632632
)
633633
end
634+
635+
@testset "getparams" begin
636+
@model function e(x=1.0)
637+
return x ~ Normal()
638+
end
639+
evi = Turing.VarInfo(e())
640+
@test isempty(Turing.Inference.getparams(e(), evi))
641+
642+
@model function f()
643+
return x ~ Normal()
644+
end
645+
fvi = Turing.VarInfo(f())
646+
@test only(Turing.Inference.getparams(f(), fvi)) == (@varname(x), fvi[@varname(x)])
647+
648+
@model function g()
649+
x ~ Normal()
650+
return y ~ Poisson()
651+
end
652+
gvi = Turing.VarInfo(g())
653+
gparams = Turing.Inference.getparams(g(), gvi)
654+
@test gparams[1] == (@varname(x), gvi[@varname(x)])
655+
@test gparams[2] == (@varname(y), gvi[@varname(y)])
656+
@test length(gparams) == 2
657+
end
658+
659+
@testset "empty model" begin
660+
@model function e(x=1.0)
661+
return x ~ Normal()
662+
end
663+
# Can't test with HMC/NUTS because some AD backends error; see
664+
# https://github.com/JuliaDiff/DifferentiationInterface.jl/issues/802
665+
@test sample(e(), IS(), 100) isa MCMCChains.Chains
666+
end
634667
end
635668

636669
end

0 commit comments

Comments
 (0)