pymc-marketing icon indicating copy to clipboard operation
pymc-marketing copied to clipboard

Avoid PyTensor evals whenever possible

Open cluhmann opened this issue 2 years ago • 3 comments

In BaseDelayedSaturatedMMM, the channel_contributions_forward_pass() method calls eval() on the pytensor value to be returned (here). This causes problems if you expect the tensor returned by the various transformation methods to be passed along as-is. For example, if you try to compile a pytensor function that incorporates a call to channel_contributions_forward_pass(), pytensor will complain and break.

Can we avoid calls to eval() whenever possible? Obviously, handing back tensors may be a bit confusing to some users, but having the eval() calls scattered throughout the codebase in unsystematic ways is going to lead to problems.

cluhmann avatar Sep 23 '23 12:09 cluhmann

Thinking about this more, it probably makes sense to make any "internal" functions propagate results as tensors and any "user-facing" functions call eval(). Because the eval() mentioned above is in BaseDelayedSaturatedMMM, it should be considered "internal" and thus not call eval(). Seem fair?

cluhmann avatar Sep 23 '23 12:09 cluhmann

We may also want to change the names of the base class methods so that they are not overridden by the child class methods. The super.channel_contributions_forward_pass() method may be useful even when you have a BaseDelayedSaturatedMMM object (i.e., the contribution forward pass without the target variable transformation). It would be easy enough to rename the base method to _channel_contributions_forward_pass() or something.

cluhmann avatar Sep 25 '23 11:09 cluhmann

This is also relevant to #314

cluhmann avatar Sep 26 '23 03:09 cluhmann