-
Notifications
You must be signed in to change notification settings - Fork 35
Remove 3-argument {_,}evaluate!!
; clean up submodel code
#960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f0ed7f3
7f94016
c79fe47
691e01d
bfa48b3
aaf0bc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,7 +258,7 @@ julia> # However, it's not possible to condition `inner` directly. | |
conditioned_model_fail = model | (inner = 1.0, ); | ||
|
||
julia> conditioned_model_fail() | ||
ERROR: ArgumentError: `~` with a model on the right-hand side of an observe statement is not supported | ||
ERROR: ArgumentError: `x ~ to_submodel(...)` is not supported when `x` is observed | ||
[...] | ||
``` | ||
""" | ||
|
@@ -864,12 +864,6 @@ If multiple threads are available, the varinfo provided will be wrapped in a | |
|
||
Returns a tuple of the model's return value, plus the updated `varinfo` | ||
(unwrapped if necessary). | ||
|
||
evaluate!!(model::Model, varinfo, context) | ||
|
||
When an extra context stack is provided, the model's context is inserted into | ||
that context stack. See `combine_model_and_external_contexts`. This method is | ||
deprecated. | ||
""" | ||
function AbstractPPL.evaluate!!(model::Model, varinfo::AbstractVarInfo) | ||
return if use_threadsafe_eval(model.context, varinfo) | ||
|
@@ -878,17 +872,6 @@ function AbstractPPL.evaluate!!(model::Model, varinfo::AbstractVarInfo) | |
evaluate_threadunsafe!!(model, varinfo) | ||
end | ||
end | ||
function AbstractPPL.evaluate!!( | ||
model::Model, varinfo::AbstractVarInfo, context::AbstractContext | ||
) | ||
Base.depwarn( | ||
"The `context` argument to evaluate!!(model, varinfo, context) is deprecated.", | ||
:dynamicppl_evaluate_context, | ||
) | ||
new_ctx = combine_model_and_external_contexts(model.context, context) | ||
model = contextualize(model, new_ctx) | ||
return evaluate!!(model, varinfo) | ||
end | ||
Comment on lines
-881
to
-891
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't this deprecation added just a few weeks ago? Or am I mixing this with something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above; but I don't know, I might be open to leaving a helpful error message in (i.e., maybe it shouldn't continue behaving as it does, but it should throw an error message that guides people towards the right answer)? I do know that upstream packages use evaluate!! even though it is internal, pretty sure I've seen it in Pigeons.jl for example, and Turing itself obviously uses evaluate!! quite a lot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A manually crafted, more informative error message sounds good to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added an error hint in julia> using DynamicPPL, Distributions
julia> @model f() = x ~ Normal()
f (generic function with 2 methods)
julia> m = f(); v = VarInfo(m); c = DefaultContext()
DefaultContext()
julia> DynamicPPL.evaluate!!(m, v, c)
ERROR: MethodError: no method matching evaluate!!(::Model{…}, ::VarInfo{…}, ::DefaultContext)
The function `evaluate!!` exists, but no method is defined for this combination of argument types.
The method `evaluate!!(model, varinfo, new_ctx)` has been removed. Instead, you should store the `new_ctx` in the `model.context` field using `new_model = contextualize(model, new_ctx)`, and then call `evaluate!!(new_model, varinfo)` on the new model. (Note that, if the model already contained a non-default context, you will need to wrap the existing context.)
Closest candidates are:
evaluate!!(::Model, ::AbstractVarInfo)
@ DynamicPPL ~/ppl/dppl/src/model.jl:868
Stacktrace:
[1] top-level scope
@ REPL[10]:1
Some type information was truncated. Use `show(err)` to see complete types. |
||
|
||
""" | ||
evaluate_threadunsafe!!(model, varinfo) | ||
|
@@ -932,54 +915,14 @@ Evaluate the `model` with the given `varinfo`. | |
|
||
This function does not wrap the varinfo in a `ThreadSafeVarInfo`. It also does not | ||
reset the log probability of the `varinfo` before running. | ||
|
||
_evaluate!!(model::Model, varinfo, context) | ||
|
||
If an additional `context` is provided, the model's context is combined with | ||
that context before evaluation. | ||
""" | ||
function _evaluate!!(model::Model, varinfo::AbstractVarInfo) | ||
args, kwargs = make_evaluate_args_and_kwargs(model, varinfo) | ||
return model.f(args...; kwargs...) | ||
end | ||
function _evaluate!!(model::Model, varinfo::AbstractVarInfo, context::AbstractContext) | ||
# TODO(penelopeysm): We don't really need this, but it's a useful | ||
# convenience method. We could remove it after we get rid of the | ||
# evaluate_threadsafe!! stuff (in favour of making users call evaluate!! | ||
# with a TSVI themselves). | ||
new_ctx = combine_model_and_external_contexts(model.context, context) | ||
model = contextualize(model, new_ctx) | ||
return _evaluate!!(model, varinfo) | ||
end | ||
|
||
is_splat_symbol(s::Symbol) = startswith(string(s), "#splat#") | ||
|
||
""" | ||
combine_model_and_external_contexts(model_context, external_context) | ||
|
||
Combine a context from a model and an external context into a single context. | ||
|
||
The resulting context stack has the following structure: | ||
|
||
`external_context` -> `childcontext(external_context)` -> ... -> | ||
`model_context` -> `childcontext(model_context)` -> ... -> | ||
`leafcontext(external_context)` | ||
|
||
The reason for this is that we want to give `external_context` precedence over | ||
`model_context`, while also preserving the leaf context of `external_context`. | ||
We can do this by | ||
|
||
1. Set the leaf context of `model_context` to `leafcontext(external_context)`. | ||
2. Set leaf context of `external_context` to the context resulting from (1). | ||
""" | ||
function combine_model_and_external_contexts( | ||
model_context::AbstractContext, external_context::AbstractContext | ||
) | ||
return setleafcontext( | ||
external_context, setleafcontext(model_context, leafcontext(external_context)) | ||
) | ||
end | ||
|
||
""" | ||
make_evaluate_args_and_kwargs(model, varinfo) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.