Skip to content

Commit 7ddec2c

Browse files
committed
removed now-redudant filtering methods since we use JET's own filters
1 parent 33e5b98 commit 7ddec2c

File tree

3 files changed

+10
-44
lines changed

3 files changed

+10
-44
lines changed

ext/DynamicPPLJETExt.jl

+4-38
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,19 @@ module DynamicPPLJETExt
33
using DynamicPPL: DynamicPPL
44
using JET: JET
55

6-
"""
7-
is_tilde_instance(x)
8-
9-
Return `true` if `x` is a method instance of a tilde function, otherwise `false`.
10-
"""
11-
is_tilde_instance(x) = false
12-
is_tilde_instance(frame::JET.VirtualFrame) = is_tilde_instance(frame.linfo)
13-
function is_tilde_instance(mi::Core.MethodInstance)
14-
types = mi.specTypes
15-
# This can occur, for example, if `specTypes` is `UnionAll` due to an error.
16-
return if hasproperty(types, :parameters)
17-
is_tilde_instance(types.parameters[1])
18-
else
19-
false
20-
end
21-
end
22-
is_tilde_instance(::Type{typeof(DynamicPPL.tilde_assume!!)}) = true
23-
is_tilde_instance(::Type{typeof(DynamicPPL.tilde_observe!!)}) = true
24-
is_tilde_instance(::Type{typeof(DynamicPPL.dot_tilde_assume!!)}) = true
25-
is_tilde_instance(::Type{typeof(DynamicPPL.dot_tilde_observe!!)}) = true
26-
27-
"""
28-
report_has_error_in_tilde(report)
29-
30-
Return `true` if the given error `report` contains a tilde function in its frames, otherwise `false`.
31-
32-
This is used to filter out reports that occur outside of the tilde pipeline, in an attempt to avoid
33-
warning the user about DynamicPPL doing something wrong when it is in fact an issue with the user's code.
34-
"""
35-
function report_has_error_in_tilde(report)
36-
frames = report.vst
37-
return any(is_tilde_instance, frames)
38-
end
39-
406
function DynamicPPL.is_suitable_varinfo(
417
model::DynamicPPL.Model,
428
context::DynamicPPL.AbstractContext,
439
varinfo::DynamicPPL.AbstractVarInfo;
44-
only_tilde::Bool=true,
10+
only_ddpl::Bool=true,
4511
)
4612
# Let's make sure that both evaluation and sampling doesn't result in type errors.
4713
f, argtypes = DynamicPPL.DebugUtils.gen_evaluator_call_with_types(
4814
model, varinfo, context
4915
)
5016
# If specified, we only check errors originating somewhere in the DynamicPPL.jl.
5117
# This way we don't just fall back to untyped if the user's code is the issue.
52-
result = if only_tilde
18+
result = if only_ddpl
5319
JET.report_call(f, argtypes; target_modules=(JET.AnyFrameModule(DynamicPPL),))
5420
else
5521
JET.report_call(f, argtypes)
@@ -58,14 +24,14 @@ function DynamicPPL.is_suitable_varinfo(
5824
end
5925

6026
function DynamicPPL._determine_varinfo_jet(
61-
model::DynamicPPL.Model, context::DynamicPPL.AbstractContext; only_tilde::Bool=true
27+
model::DynamicPPL.Model, context::DynamicPPL.AbstractContext; only_ddpl::Bool=true
6228
)
6329
# First we try with the typed varinfo.
6430
varinfo = DynamicPPL.typed_varinfo(model, context)
6531
issuccess = true
6632

6733
# Let's make sure that both evaluation and sampling doesn't result in type errors.
68-
issuccess, result = DynamicPPL.is_suitable_varinfo(model, context, varinfo; only_tilde)
34+
issuccess, result = DynamicPPL.is_suitable_varinfo(model, context, varinfo; only_ddpl)
6935

7036
if !issuccess
7137
# Useful information for debugging.

src/model_utils.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Check if the `model` supports evaluation using the provided `context` and `varin
222222
- `varinfo`: The varinfo to verify the support for.
223223
224224
# Keyword Arguments
225-
- `only_tilde`: If `true`, only consider error reports occuring in the tilde pipeline. Default: `true`.
225+
- `only_ddpl`: If `true`, only consider error reports occuring in the tilde pipeline. Default: `true`.
226226
227227
# Returns
228228
- `issuccess`: `true` if the model supports the varinfo, otherwise `false`.
@@ -234,7 +234,7 @@ function is_suitable_varinfo end
234234
function _determine_varinfo_jet end
235235

236236
"""
237-
determine_suitable_varinfo(model[, context]; verbose::Bool=false, only_tilde::Bool=true)
237+
determine_suitable_varinfo(model[, context]; verbose::Bool=false, only_ddpl::Bool=true)
238238
239239
Return a suitable varinfo for the given `model`.
240240
@@ -249,14 +249,14 @@ See also: [`DynamicPPL.is_suitable_varinfo`](@ref).
249249
- `context`: The context to use for the model evaluation. Default: `SamplingContext()`.
250250
251251
# Keyword Arguments
252-
- `only_tilde`: If `true`, only consider error reports occuring in the tilde pipeline. Default: `true`.
252+
- `only_ddpl`: If `true`, only consider error reports within DynamicPPL.jl.
253253
"""
254254
function determine_suitable_varinfo(
255-
model::Model, context::AbstractContext=SamplingContext(); only_tilde::Bool=true
255+
model::Model, context::AbstractContext=SamplingContext(); only_ddpl::Bool=true
256256
)
257257
# If JET.jl has been loaded, and thus `determine_varinfo` has been defined, we use that.
258258
return if Base.get_extension(DynamicPPL, :DynamicPPLJETExt) !== nothing
259-
_determine_varinfo_jet(model, context; only_tilde)
259+
_determine_varinfo_jet(model, context; only_ddpl)
260260
else
261261
# Warn the user.
262262
@warn "JET.jl is not loaded. Assumes the model is compatible with typed varinfo."

test/ext/DynamicPPLJETExt.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
# Should pass if we're only checking the tilde statements.
5151
@test DynamicPPL.determine_suitable_varinfo(demo5()) isa DynamicPPL.TypedVarInfo
5252
# Should fail if we're including errors in the model body.
53-
@test DynamicPPL.determine_suitable_varinfo(demo5(); only_tilde=false) isa
53+
@test DynamicPPL.determine_suitable_varinfo(demo5(); only_ddpl=false) isa
5454
DynamicPPL.UntypedVarInfo
5555
end
5656

0 commit comments

Comments
 (0)