1- using JET: JET
2-
31@testset " DynamicPPLJETExt.jl" begin
42 @testset " determine_varinfo" begin
53 @model function demo1 ()
@@ -11,7 +9,7 @@ using JET: JET
119 end
1210 end
1311 model = demo1 ()
14- @test DynamicPPL. determine_varinfo (model) isa DynamicPPL. UntypedVarInfo
12+ @test DynamicPPL. determine_varinfo (model; verbose = true ) isa DynamicPPL. UntypedVarInfo
1513
1614 @model demo2 () = x ~ Normal ()
1715 @test DynamicPPL. determine_varinfo (demo2 ()) isa DynamicPPL. TypedVarInfo
@@ -26,7 +24,7 @@ using JET: JET
2624 z ~ Normal ()
2725 end
2826 end
29- @test DynamicPPL. determine_varinfo (demo3 ()) isa DynamicPPL. UntypedVarInfo
27+ @test DynamicPPL. determine_varinfo (demo3 (); verbose = true ) isa DynamicPPL. UntypedVarInfo
3028
3129 # Evaluation works (and it would even do so in practice), but sampling
3230 # fill fail due to storing `Cauchy{Float64}` in `Vector{Normal{Float64}}`.
@@ -38,24 +36,38 @@ using JET: JET
3836 y ~ Cauchy () # different distibution, but same transformation => should work
3937 end
4038 end
41- @test DynamicPPL. determine_varinfo (demo4 ()) isa DynamicPPL. UntypedVarInfo
39+ @test DynamicPPL. determine_varinfo (demo4 (); verbose= true ) isa DynamicPPL. UntypedVarInfo
40+
41+ # In this model, the type error occurs in the user code rather than in DynamicPPL.
42+ @model function demo5 ()
43+ x ~ Normal ()
44+ xs = Any[]
45+ push! (xs, x)
46+ # `sum(::Vector{Any})` can potentially error unless the dynamic manages to resolve the
47+ # correct `zero` method. As a result, this code will run, but JET will raise this is an issue.
48+ return sum (xs)
49+ end
50+ # Should pass if we're only checking the tilde statements.
51+ @test DynamicPPL. determine_varinfo (demo5 (); verbose= true ) isa DynamicPPL. TypedVarInfo
52+ # Should fail if we're including errors in the model body.
53+ @test DynamicPPL. determine_varinfo (demo5 (); verbose= true , only_tilde= false ) isa DynamicPPL. UntypedVarInfo
4254 end
4355
44- # @testset "demo models" begin
45- # @testset "$(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS
46- # varinfo = DynamicPPL.DynamicPPL.determine_varinfo(model)
47- # # They should all result in typed.
48- # @test varinfo isa DynamicPPL.TypedVarInfo
49- # # But let's also make sure that they're not lying.
50- # f_eval, argtypes_eval = DynamicPPL.DebugUtils.gen_evaluator_call_with_types(
51- # model, varinfo
52- # )
53- # JET.test_call(f_eval, argtypes_eval)
56+ @testset " demo models" begin
57+ @testset " $(model. f) " for model in DynamicPPL. TestUtils. DEMO_MODELS
58+ varinfo = DynamicPPL. DynamicPPL. determine_varinfo (model)
59+ # They should all result in typed.
60+ @test varinfo isa DynamicPPL. TypedVarInfo
61+ # But let's also make sure that they're not lying.
62+ f_eval, argtypes_eval = DynamicPPL. DebugUtils. gen_evaluator_call_with_types (
63+ model, varinfo
64+ )
65+ JET. test_call (f_eval, argtypes_eval)
5466
55- # f_sample, argtypes_sample = DynamicPPL.DebugUtils.gen_evaluator_call_with_types(
56- # model, varinfo, DynamicPPL.SamplingContext()
57- # )
58- # JET.test_call(f_sample, argtypes_sample)
59- # end
60- # end
67+ f_sample, argtypes_sample = DynamicPPL. DebugUtils. gen_evaluator_call_with_types (
68+ model, varinfo, DynamicPPL. SamplingContext ()
69+ )
70+ JET. test_call (f_sample, argtypes_sample)
71+ end
72+ end
6173end
0 commit comments