Skip to content

Commit 8496968

Browse files
committed
added a bunch of docs for introduced and existing methods
Added docs for `determine_suitable_varinfo` and existing methods that should be documented, e.g. `untyped_varinfo`, `typed_varinfo`, and `default_varinfo`
1 parent fa155a4 commit 8496968

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

docs/src/api.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ AbstractVarInfo
243243

244244
But exactly how a [`AbstractVarInfo`](@ref) stores this information can vary.
245245

246+
For constructing the "default" typed and untyped varinfo types used in DynamicPPL (see [the section on varinfo design](./internals/varinfo) for more on this), we have the following two methods:
247+
248+
```@docs
249+
DynamicPPL.untyped_varinfo
250+
DynamicPPL.typed_varinfo
251+
```
252+
246253
#### `VarInfo`
247254

248255
```@docs
@@ -403,6 +410,19 @@ DynamicPPL.loadstate
403410
DynamicPPL.initialsampler
404411
```
405412

413+
Finally, to specify which varinfo type a [`Sampler`](@ref) should use for a given [`Model`](@ref), this is specified by [`DynamicPPL.default_varinfo`](@ref) and can thus be overloaded for each `model`-`sampler` combination. This can be useful in cases where one has explicit knowledge that one type of varinfo will be more performant for the given `model` and `sampler`.
414+
415+
```@docs
416+
DynamicPPL.default_varinfo
417+
```
418+
419+
There is also the _experimental_ [`DynamicPPL.Experimental.determine_suitable_varinfo`](@ref), which uses static checking via [JET.jl](https://github.com/aviatesk/JET.jl) to determine whether one should use [`DynamicPPL.typed_varinfo`](@ref) or [`DynamicPPL.untyped_varinfo`](@ref), depending on which supports the model:
420+
421+
```@docs
422+
DynamicPPL.Experimental.determine_suitable_varinfo
423+
DynamicPPL.Experimental.is_suitable_varinfo
424+
```
425+
406426
### [Model-Internal Functions](@id model_internal)
407427

408428
```@docs

src/sampler.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ function AbstractMCMC.step(
6767
return vi, nothing
6868
end
6969

70+
"""
71+
default_varinfo(rng, model, sampler[, context])
72+
73+
Return a default varinfo object for the given `model` and `sampler`.
74+
75+
# Arguments
76+
- `rng::Random.AbstractRNG`: Random number generator.
77+
- `model::Model`: Model for which we want to create a varinfo object.
78+
- `sampler::AbstractSampler`: Sampler which will make use of the varinfo object.
79+
- `context::AbstractContext`: Context in which the model is evaluated.
80+
81+
# Returns
82+
- `AbstractVarInfo`: Default varinfo object for the given `model` and `sampler`.
83+
"""
7084
function default_varinfo(rng::Random.AbstractRNG, model::Model, sampler::AbstractSampler)
7185
return default_varinfo(rng, model, sampler, DefaultContext())
7286
end

src/varinfo.jl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,7 @@ function has_varnamedvector(vi::VarInfo)
163163
(vi isa TypedVarInfo && any(Base.Fix2(isa, VarNamedVector), values(vi.metadata)))
164164
end
165165

166-
"""
167-
untyped_varinfo([rng, ]model[, sampler, context])
168-
169-
Return an untyped `VarInfo` instance for the model `model`.
170-
"""
166+
# TODO: We should just remove this function in favour of passing `SamplingContext` directly.
171167
function untyped_varinfo(
172168
rng::Random.AbstractRNG,
173169
model::Model,
@@ -182,6 +178,19 @@ function untyped_varinfo(
182178
)
183179
return untyped_varinfo(Random.default_rng(), model, args...)
184180
end
181+
182+
"""
183+
untyped_varinfo([rng, ]model[, context, metadata])
184+
185+
Return an untyped varinfo object for the given `model` and `context`.
186+
187+
# Arguments
188+
- `rng::Random.AbstractRNG`: The random number generator to use. Default: `Random.default_rng()`.
189+
- `model::Model`: The model for which to create the varinfo object.
190+
- `context::AbstractContext`: The context in which to evaluate the model. Default: `DefaultContext()`.
191+
- `metadata::Union{Metadata,VarNamedVector}`: The metadata to use for the varinfo object.
192+
Default: `Metadata()`.
193+
"""
185194
function untyped_varinfo(
186195
model::Model,
187196
context::AbstractContext,
@@ -194,9 +203,14 @@ function untyped_varinfo(
194203
end
195204

196205
"""
197-
typed_varinfo([rng, ]model[, sampler, context])
206+
typed_varinfo([rng, ]model[, context, metadata])
207+
208+
Return a typed varinfo object for the given `model`, `sampler` and `context`.
209+
210+
This simply calls [`DynamicPPL.untyped_varinfo`](@ref) and converts the resulting
211+
varinfo object to a typed varinfo object.
198212
199-
Return a typed `VarInfo` instance for the model `model`.
213+
See also: [`DynamicPPL.untyped_varinfo`](@ref)
200214
"""
201215
typed_varinfo(args...) = TypedVarInfo(untyped_varinfo(args...))
202216

0 commit comments

Comments
 (0)