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.
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.
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
Modelobject.)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 intofwithout 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 forfwithout arguments, then forward thef-with-arguments method to thef-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
ofwould solve this, though of course we are unsure when that will be ready.