Skip to content

Commit 9ec1556

Browse files
committed
forgot to add the experimenta.jl file in previous commit
1 parent e07ecdb commit 9ec1556

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/experimental.jl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module Experimental
2+
3+
using DynamicPPL: DynamicPPL
4+
5+
"""
6+
is_suitable_varinfo(model::Model, context::AbstractContext, varinfo::AbstractVarInfo; kwargs...)
7+
8+
Check if the `model` supports evaluation using the provided `context` and `varinfo`.
9+
10+
!!! warning
11+
Loading JET.jl is required before calling this function.
12+
13+
# Arguments
14+
- `model`: The model to to verify the support for.
15+
- `context`: The context to use for the model evaluation.
16+
- `varinfo`: The varinfo to verify the support for.
17+
18+
# Keyword Arguments
19+
- `only_ddpl`: If `true`, only consider error reports occuring in the tilde pipeline. Default: `true`.
20+
21+
# Returns
22+
- `issuccess`: `true` if the model supports the varinfo, otherwise `false`.
23+
- `report`: The result of `report_call` from JET.jl.
24+
"""
25+
function is_suitable_varinfo end
26+
27+
# Internal hook for JET.jl to overload.
28+
function _determine_varinfo_jet end
29+
30+
"""
31+
determine_suitable_varinfo(model[, context]; verbose::Bool=false, only_ddpl::Bool=true)
32+
33+
Return a suitable varinfo for the given `model`.
34+
35+
See also: [`DynamicPPL.is_suitable_varinfo`](@ref).
36+
37+
!!! warning
38+
For full functionality, this requires JET.jl to be loaded.
39+
If JET.jl is not loaded, this function will assume the model is compatible with typed varinfo.
40+
41+
# Arguments
42+
- `model`: The model for which to determine the varinfo.
43+
- `context`: The context to use for the model evaluation. Default: `SamplingContext()`.
44+
45+
# Keyword Arguments
46+
- `only_ddpl`: If `true`, only consider error reports within DynamicPPL.jl.
47+
"""
48+
function determine_suitable_varinfo(
49+
model::DynamicPPL.Model,
50+
context::DynamicPPL.AbstractContext=DynamicPPL.SamplingContext();
51+
only_ddpl::Bool=true,
52+
)
53+
# If JET.jl has been loaded, and thus `determine_varinfo` has been defined, we use that.
54+
return if Base.get_extension(DynamicPPL, :DynamicPPLJETExt) !== nothing
55+
_determine_varinfo_jet(model, context; only_ddpl)
56+
else
57+
# Warn the user.
58+
@warn "JET.jl is not loaded. Assumes the model is compatible with typed varinfo."
59+
# Otherwise, we use the, possibly incorrect, default typed varinfo (to stay backwards compat).
60+
DynamicPPL.typed_varinfo(model, context)
61+
end
62+
end
63+
64+
end

0 commit comments

Comments
 (0)