|
30 | 30 | DynamicPPL.UntypedVarInfo |
31 | 31 |
|
32 | 32 | # Evaluation works (and it would even do so in practice), but sampling |
33 | | - # fill fail due to storing `Cauchy{Float64}` in `Vector{Normal{Float64}}`. |
| 33 | + # will fail due to storing `Cauchy{Float64}` in `Vector{Normal{Float64}}`. |
34 | 34 | @model function demo4() |
35 | 35 | x ~ Bernoulli() |
36 | 36 | if x |
|
40 | 40 | end |
41 | 41 | end |
42 | 42 | @test DynamicPPL.Experimental.determine_suitable_varinfo(demo4()) isa |
43 | | - DynamicPPL.NTVarInfo |
44 | | - init_model = DynamicPPL.contextualize( |
45 | | - demo4(), DynamicPPL.InitContext(DynamicPPL.InitFromPrior()) |
46 | | - ) |
47 | | - @test DynamicPPL.Experimental.determine_suitable_varinfo(init_model) isa |
48 | 43 | DynamicPPL.UntypedVarInfo |
49 | 44 |
|
50 | 45 | # In this model, the type error occurs in the user code rather than in DynamicPPL. |
|
67 | 62 |
|
68 | 63 | @testset "demo models" begin |
69 | 64 | @testset "$(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS |
70 | | - sampling_model = contextualize(model, SamplingContext(model.context)) |
71 | 65 | # Use debug logging below. |
72 | 66 | varinfo = DynamicPPL.Experimental.determine_suitable_varinfo(model) |
73 | | - # Check that the inferred varinfo is indeed suitable for evaluation and sampling |
74 | | - f_eval, argtypes_eval = DynamicPPL.DebugUtils.gen_evaluator_call_with_types( |
75 | | - model, varinfo |
76 | | - ) |
77 | | - JET.test_call(f_eval, argtypes_eval) |
78 | | - |
79 | | - f_sample, argtypes_sample = DynamicPPL.DebugUtils.gen_evaluator_call_with_types( |
80 | | - sampling_model, varinfo |
81 | | - ) |
82 | | - JET.test_call(f_sample, argtypes_sample) |
83 | 67 | # For our demo models, they should all result in typed. |
84 | 68 | is_typed = varinfo isa DynamicPPL.NTVarInfo |
85 | 69 | @test is_typed |
86 | | - # If the test failed, check why it didn't infer a typed varinfo |
| 70 | + # If the test failed, check what the type stability problem was for |
| 71 | + # the typed varinfo. This is mostly useful for debugging from test |
| 72 | + # logs. |
87 | 73 | if !is_typed |
| 74 | + @info "Model `$(model.f)` is not type stable with typed varinfo." |
88 | 75 | typed_vi = DynamicPPL.typed_varinfo(model) |
89 | | - f_eval, argtypes_eval = DynamicPPL.DebugUtils.gen_evaluator_call_with_types( |
90 | | - model, typed_vi |
| 76 | + |
| 77 | + @info "Evaluating with DefaultContext:" |
| 78 | + model = DynamicPPL.contextualize( |
| 79 | + model, |
| 80 | + DynamicPPL.setleafcontext(model.context, DynamicPPL.DefaultContext()), |
| 81 | + ) |
| 82 | + f, argtypes = DynamicPPL.DebugUtils.gen_evaluator_call_with_types( |
| 83 | + model, varinfo |
| 84 | + ) |
| 85 | + JET.test_call(f, argtypes) |
| 86 | + |
| 87 | + @info "Initialising with InitContext:" |
| 88 | + model = DynamicPPL.contextualize( |
| 89 | + model, |
| 90 | + DynamicPPL.setleafcontext(model.context, DynamicPPL.InitContext()), |
91 | 91 | ) |
92 | | - JET.test_call(f_eval, argtypes_eval) |
93 | | - f_sample, argtypes_sample = DynamicPPL.DebugUtils.gen_evaluator_call_with_types( |
94 | | - sampling_model, typed_vi |
| 92 | + f, argtypes = DynamicPPL.DebugUtils.gen_evaluator_call_with_types( |
| 93 | + model, varinfo |
95 | 94 | ) |
96 | | - JET.test_call(f_sample, argtypes_sample) |
| 95 | + JET.test_call(f, argtypes) |
97 | 96 | end |
98 | 97 | end |
99 | 98 | end |
|
0 commit comments