Skip to content

fix and condition _still_ don't use the same VarNames as tilde pipeline (specifically InitFromParams) #1097

@penelopeysm

Description

@penelopeysm

This is a resurfacing of #702:

julia> using DynamicPPL, Distributions, LinearAlgebra

julia> @model function f()
           x ~ MvNormal(zeros(2), I)
           return x
       end
f (generic function with 2 methods)

julia> first(DynamicPPL.init!!(f(), VarInfo(), InitFromParams(Dict(@varname(x[1]) => 1.0, @varname(x[2]) => 2.0))))
2-element Vector{Float64}:
 1.0
 2.0

julia> fix(f(), Dict(@varname(x[1]) => 1.0, @varname(x[2]) => 2.0))()
2-element Vector{Float64}:
 0.24589494968073047
 1.0916208950180246

I think that the current behaviour is quite dangerous because it silently fails rather than erroring. In particular, the main failure mode would be attempting to use a Dict obtained from MCMCChains.

The reason for this difference in behaviour is because hasfixed only uses hasvalue(context.values, vn), instead of using hasvalue(context.values, vn, dist). This is a fairly easy fix, we just need to pass dist down through the call stack of isfixed, etc.

Because hasvalue(vals, vn, dist) simply calls hasvalue(vals, vn) as the very first check, I don't believe this shouldn't result in any (significant) loss of performance for the existing case where the whole vector x is provided. But it'd probably be good to benchmark in case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions