Skip to content

Commit 0100d6d

Browse files
committed
fix docs
1 parent 0213736 commit 0100d6d

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

docs/src/api.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,21 @@ DynamicPPL.varname_and_value_leaves
438438

439439
### Evaluation Contexts
440440

441-
Internally, both sampling and evaluation of log densities are performed with [`AbstractPPL.evaluate!!`](@ref).
441+
Internally, model evaluation is performed with [`AbstractPPL.evaluate!!`](@ref).
442442

443443
```@docs
444444
AbstractPPL.evaluate!!
445445
```
446446

447-
The behaviour of a model execution can be changed with evaluation contexts that are passed as additional argument to the model function.
447+
This method mutates the `varinfo` used for execution.
448+
By default, it does not perform any actual sampling: it only evaluates the model using the values of the variables that are already in the `varinfo`.
449+
To perform sampling, you can either wrap `model.context` in a `SamplingContext`, or use this convenience method:
450+
451+
```@docs
452+
DynamicPPL.sample!!
453+
```
454+
455+
The behaviour of a model execution can be changed with evaluation contexts, which are a field of the model.
448456
Contexts are subtypes of `AbstractPPL.AbstractContext`.
449457

450458
```@docs

src/model.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -794,22 +794,23 @@ julia> # Now `a.x` will be sampled.
794794
fixed(model::Model) = fixed(model.context)
795795

796796
"""
797-
(model::Model)([rng[, varinfo]])
797+
(model::Model)([rng, varinfo])
798798
799-
Sample from the `model` using the `sampler` with random number generator `rng`
800-
and the `context`, and store the sample and log joint probability in `varinfo`.
799+
Sample from the prior of the `model` with random number generator `rng`.
801800
802801
Returns the model's return value.
803802
804-
If no arguments are provided, uses the default random number generator and
805-
samples from the prior.
803+
Note that calling this with an existing `varinfo` object will mutate it.
806804
"""
805+
(model::Model)() = model(Random.default_rng(), VarInfo())
806+
function (model::Model)(varinfo::AbstractVarInfo)
807+
return model(Random.default_rng(), varinfo)
808+
end
809+
# ^ Weird Documenter.jl bug means that we have to write the two above separately
810+
# as it can only detect the `function`-less syntax.
807811
function (model::Model)(rng::Random.AbstractRNG, varinfo::AbstractVarInfo=VarInfo())
808812
return first(sample!!(rng, model, varinfo))
809813
end
810-
function (model::Model)(varinfo::AbstractVarInfo=VarInfo())
811-
return model(Random.default_rng(), varinfo)
812-
end
813814

814815
"""
815816
use_threadsafe_eval(context::AbstractContext, varinfo::AbstractVarInfo)
@@ -853,10 +854,10 @@ end
853854
854855
Evaluate the `model` with the given `varinfo`. If an extra context stack is
855856
provided, the model's context is inserted into that context stack. See
856-
[`combine_model_and_external_contexts`](@ref).
857+
`combine_model_and_external_contexts`.
857858
858859
If multiple threads are available, the varinfo provided will be wrapped in a
859-
[`DynamicPPL.ThreadSafeVarInfo`](@ref) before evaluation.
860+
`ThreadSafeVarInfo` before evaluation.
860861
861862
Returns a tuple of the model's return value, plus the updated `varinfo`
862863
(unwrapped if necessary).
@@ -871,6 +872,10 @@ end
871872
function AbstractPPL.evaluate!!(
872873
model::Model, varinfo::AbstractVarInfo, context::AbstractContext
873874
)
875+
Base.depwarn(
876+
"The `context` argument to evaluate!!(model, varinfo, context) is deprecated.",
877+
:dynamicppl_evaluate_context,
878+
)
874879
new_ctx = combine_model_and_external_contexts(model.context, context)
875880
model = contextualize(model, new_ctx)
876881
return evaluate!!(model, varinfo)

0 commit comments

Comments
 (0)