-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add some minimal tests for deprecated @submodel
- Loading branch information
1 parent
cda42f0
commit a987195
Showing
3 changed files
with
59 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@testset "deprecated" begin | ||
@testset "@submodel" begin | ||
@testset "is deprecated" begin | ||
@model inner() = x ~ Normal() | ||
@model outer() = @submodel x = inner() | ||
@test_logs( | ||
( | ||
:warn, | ||
"`@submodel model` and `@submodel prefix=... model` are deprecated; see `to_submodel` for the up-to-date syntax.", | ||
), | ||
outer()() | ||
) | ||
|
||
@model outer_with_prefix() = @submodel prefix = "sub" x = inner() | ||
@test_logs( | ||
( | ||
:warn, | ||
"`@submodel model` and `@submodel prefix=... model` are deprecated; see `to_submodel` for the up-to-date syntax.", | ||
), | ||
outer_with_prefix()() | ||
) | ||
end | ||
|
||
@testset "prefixing still works correctly" begin | ||
@model inner() = x ~ Normal() | ||
@model function outer() | ||
a = @submodel inner() | ||
b = @submodel prefix = "sub" inner() | ||
return a, b | ||
end | ||
@test outer()() isa Tuple{Float64,Float64} | ||
vi = VarInfo(outer()) | ||
@test @varname(x) in keys(vi) | ||
@test @varname(var"sub.x") in keys(vi) | ||
end | ||
|
||
@testset "logp is still accumulated properly" begin | ||
@model inner_assume() = x ~ Normal() | ||
@model inner_observe(x, y) = y ~ Normal(x) | ||
@model function outer(b) | ||
a = @submodel inner_assume() | ||
@submodel inner_observe(a, b) | ||
end | ||
y_val = 1.0 | ||
model = outer(y_val) | ||
@test model() == y_val | ||
|
||
x_val = 1.5 | ||
vi = VarInfo(outer(b)) | ||
vn_x = @varname(x) | ||
DynamicPPL.setindex!!(vi, x_val, vn_x) | ||
@test logprior(model, vi) ≈ logpdf(Normal(), x_val) | ||
@test loglikelihood(model, vi) ≈ logpdf(Normal(x_val), y_val) | ||
@test logjoint(model, vi) ≈ logpdf(Normal(), x_val) + logpdf(Normal(x_val), y_val) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters