Skip to content

fix(mmm): allow constant tensors in adstock sample_prior (fixes #1749)#2304

Open
shivamlalakiya wants to merge 4 commits intopymc-labs:mainfrom
shivamlalakiya:fix/constant-params-plot
Open

fix(mmm): allow constant tensors in adstock sample_prior (fixes #1749)#2304
shivamlalakiya wants to merge 4 commits intopymc-labs:mainfrom
shivamlalakiya:fix/constant-params-plot

Conversation

@shivamlalakiya
Copy link
Contributor

@shivamlalakiya shivamlalakiya commented Feb 18, 2026

Description

Fixes #1749

Previously, sample_prior would fail if an adstock transformation (e.g., GeometricAdstock) was initialized with constant tensors instead of PyMC distributions, as pm.sample_prior_predictive requires free random variables.

This PR adds a fallback mechanism: if no free random variables are detected in the model, it evaluates the constant tensors deterministically and returns a valid InferenceData object.

Changes

  • Modified sample_prior in transformers.py to handle ValueError from sample_prior_predictive.
  • Added regression test tests/mmm/test_issue_1749.py to verify constant inputs work.

Related Issue

Checklist


📚 Documentation preview 📚: https://pymc-marketing--2304.org.readthedocs.build/en/2304/

@cursor
Copy link
Contributor

cursor bot commented Feb 18, 2026

PR Summary

Low Risk
Small, localized change to prior-sampling that only affects transformations initialized with constant tensors; main risk is slightly different prior datasets due to newly-added pm.Deterministic nodes.

Overview
Fixes Transformation.sample_prior to work when transformation parameters are provided as constant tensors (and to include them in the returned idata.prior). It now registers non-distribution priors as pm.Deterministic variables before calling pm.sample_prior_predictive, covering both all-constant and mixed constant/distribution cases.

Adds regression tests for issue #1749 verifying sample_prior succeeds and returns expected constant values for GeometricAdstock (alpha) and for generic transformations, including with coordinate dimensions.

Written by Cursor Bugbot for commit c940cf4. This will update automatically on new commits. Configure here.

@github-actions github-actions bot added MMM tests enhancement New feature or request good second issue Bit more involved but still doable for newcomers plots labels Feb 18, 2026
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@ricardoV94
Copy link
Contributor

There's not really any prior being sampled...

@shivamlalakiya
Copy link
Contributor Author

@ricardoV94 You're right — no actual sampling is happening here. The goal was to unblock the plot curve workflow from #1749 which needs an InferenceData to proceed. Would you prefer a different approach? For example, wrapping constants in pm.DiracDelta, emitting a warnings.warn to be explicit, or something else entirely? Happy to rework it based on your guidance.

@ricardoV94
Copy link
Contributor

I was being just pedantic. It makes sense to support plot_curve, it's just that there's no prior to be sampled from so sample_prior was a bit iffy. But being pragmatic this is probably fine

@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.31%. Comparing base (941bf5f) to head (c940cf4).
⚠️ Report is 46 commits behind head on main.

Files with missing lines Patch % Lines
pymc_marketing/mmm/components/base.py 0.00% 7 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (941bf5f) and HEAD (c940cf4). Click for more details.

HEAD has 24 uploads less than BASE
Flag BASE (941bf5f) HEAD (c940cf4)
28 4
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2304       +/-   ##
===========================================
- Coverage   93.05%   23.31%   -69.74%     
===========================================
  Files          78       78               
  Lines       12230    12235        +5     
===========================================
- Hits        11381     2853     -8528     
- Misses        849     9382     +8533     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good second issue Bit more involved but still doable for newcomers MMM plots tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plot curve workflow with constant parameters

3 participants