Skip to content

returned(::Model, ::Any) #1123

@penelopeysm

Description

@penelopeysm

DynamicPPL.jl/src/model.jl

Lines 1134 to 1146 in 08fffa2

function returned(model::Model, parameters::Union{NamedTuple,AbstractDict{<:VarName}})
vi = DynamicPPL.setaccs!!(VarInfo(), ())
# Note: we can't use `fix(model, parameters)` because
# https://github.com/TuringLang/DynamicPPL.jl/issues/1097
# Use `nothing` as the fallback to ensure that any missing parameters cause an error
ctx = InitContext(Random.default_rng(), InitFromParams(parameters, nothing))
new_model = setleafcontext(model, ctx)
# We can't use new_model() because that overwrites it with an InitContext of its own.
return first(evaluate!!(new_model, vi))
end
Base.@deprecate returned(model::Model, values, keys) returned(
model, NamedTuple{keys}(values)
)

#1096 implemented returned(::Model, ::AbstractDict). But, since we probably want to extend InitFromParams to accept multiple different inputs, we should actually generalise this to returned(::Model, x) for any x that InitFromParams supports.

For example, since TuringLang/Turing.jl#2710 implements InitFromParams(::ModeResult), doing this would automatically fix TuringLang/Turing.jl#2607.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions