Skip to content

Commit 89bc0ea

Browse files
committed
Fix JETExt properly
1 parent 70bb2c4 commit 89bc0ea

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

ext/DynamicPPLJETExt.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ using JET: JET
66
function DynamicPPL.Experimental.is_suitable_varinfo(
77
model::DynamicPPL.Model, varinfo::DynamicPPL.AbstractVarInfo; only_ddpl::Bool=true
88
)
9-
# Let's make sure that both evaluation and sampling doesn't result in type errors.
109
f, argtypes = DynamicPPL.DebugUtils.gen_evaluator_call_with_types(model, varinfo)
1110
# If specified, we only check errors originating somewhere in the DynamicPPL.jl.
1211
# This way we don't just fall back to untyped if the user's code is the issue.

test/ext/DynamicPPLJETExt.jl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,33 +67,37 @@
6767

6868
@testset "demo models" begin
6969
@testset "$(model.f)" for model in DynamicPPL.TestUtils.DEMO_MODELS
70-
sampling_model = contextualize(model, SamplingContext(model.context))
7170
# Use debug logging below.
7271
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)
8372
# For our demo models, they should all result in typed.
8473
is_typed = varinfo isa DynamicPPL.NTVarInfo
8574
@test is_typed
86-
# If the test failed, check why it didn't infer a typed varinfo
75+
# If the test failed, check what the type stability problem was for
76+
# the typed varinfo. This is mostly useful for debugging from test
77+
# logs.
8778
if !is_typed
79+
@info "Model `$(model.f)` is not type stable with typed varinfo."
8880
typed_vi = DynamicPPL.typed_varinfo(model)
89-
f_eval, argtypes_eval = DynamicPPL.DebugUtils.gen_evaluator_call_with_types(
90-
model, typed_vi
81+
82+
@info "Evaluating with DefaultContext:"
83+
model = DynamicPPL.contextualize(
84+
model,
85+
DynamicPPL.setleafcontext(model.context, DynamicPPL.DefaultContext()),
86+
)
87+
f, argtypes = DynamicPPL.DebugUtils.gen_evaluator_call_with_types(
88+
model, varinfo
89+
)
90+
JET.test_call(f, argtypes)
91+
92+
@info "Initialising with InitContext:"
93+
model = DynamicPPL.contextualize(
94+
model,
95+
DynamicPPL.setleafcontext(model.context, DynamicPPL.InitContext()),
9196
)
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
97+
f, argtypes = DynamicPPL.DebugUtils.gen_evaluator_call_with_types(
98+
model, varinfo
9599
)
96-
JET.test_call(f_sample, argtypes_sample)
100+
JET.test_call(f, argtypes)
97101
end
98102
end
99103
end

0 commit comments

Comments
 (0)