TuringLang / TuringLang/DynamicPPL.jl
(speculative) turn `model.f` parameters into ConditionContext
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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