TuringLang / TuringLang/DynamicPPL.jl

(speculative) turn `model.f` parameters into ConditionContext

Open
#958 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Julia
Stars
286
Forks
41
Avg merge
1d 11h
Merged PRs (30d)
34

Description

Right now we have two ways of conditioning, one through model arguments and one through contexts. However, it's unclear what happens if someone tries to do it both ways.

@model function f(a=1.0)
    a ~ Normal()
    return a
end

m = f()
cm = m | (; a=2.0)

cm() # returns 1.0, i.e. conditioning is ignored, but this behaviour is undefined

The cheapest fix would be to warn or error when somebody tries to condition on a model argument. (We can do this because the argument names, and values, are stored in the Model object.)

A different fix would be to somehow unify the two ways together, so that for example when one declares f(2.0) it's really turned into f without an argument, but with a ConditionContext.

I actually think this would be good. I used to have some concerns about ConditionContext, but that was all fixed since we simplified .~ (#804), and now I think it's much better than the old argument-passing. But I don't immediately know from a technical standpoint how to do this. (I think we would have to do some macro magic to generate a new method for f without arguments, then forward the f-with-arguments method to the f-without-arguments method.) In this case, as long as we prevent conditioning twice on the same variable we would avoid the undefined behaviour..

@yebai points out that having static parameter declaration a la of would solve this, though of course we are unsure when that will be ready.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the @model macro, the Model object’s stored argument names and values, and ConditionContext handling; compare them with the behavior of .~ described in #804. Define whether model arguments should be unified with or rejected alongside conditioning, then verify the example no longer has undefined behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.