condition and decondition alternative
#279
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements an alternative to #278.
The way this approach works as follows:
ConditionContextspecifies which variables are condition and their values.Modelnow also has aConditionContextinstead ofmissings: by default it holdsmodel.argsand so a variable is consideredmissingif it's inmodel.argsbut not in theConditionContext. Why do we need bothmodel.argsandConditionContext(model.context)?missing, i.e.decondition(model, :x)which results inmodel.contextbut now withoutx, we don't know the shape ofxanymore. Hence we need to keepargsaround to understand what the user wants.model.contextwraps whatever context we provide evaluation of the model, i.e. in_evaluate. This in turn means that we're still allowed to do something likemodel(vi, ConditionContext(x = 1.0)), resulting inConditionContext(model.context, ConditionContext(x = 1.0))being used inside of the model.model.conditioned_argsinstead of aConditionContext, but then we'd have to add more logic to the compiler to maybe extract variables if they're not conditioned on and not inmodel.argsrather than deferring this totilde_assume!and others.The drawback of this vs. #278 is that it's definitively going to a breaking change + we probably want the
ContextualModelfrom #278 in the future anyways for other operations, e.g.do, etc. Hence I'm personally in favour of #278 and then maybe we can think about taking the approach in this PR at a later stage.Example