Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse fixtures in slow MMM tests #515

Merged
merged 3 commits into from
Feb 9, 2024
Merged

Reuse fixtures in slow MMM tests #515

merged 3 commits into from
Feb 9, 2024

Conversation

wd60622
Copy link
Contributor

@wd60622 wd60622 commented Feb 6, 2024

Description

Modify the scope of the fixture from class to module in order to reuse on the out of sample tests

Related Issue

Checklist

Modules affected

  • MMM
  • CLV

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

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

@@ -106,15 +106,15 @@ def mmm_with_fourier_features() -> DelayedSaturatedMMM:
)


@pytest.fixture(scope="class")
@pytest.fixture(scope="module")
def mmm_fitted(
mmm: DelayedSaturatedMMM, toy_X: pd.DataFrame, toy_y: pd.Series
) -> DelayedSaturatedMMM:
mmm.fit(X=toy_X, y=toy_y, target_accept=0.8, draws=3, chains=2)
Copy link
Contributor

@ricardoV94 ricardoV94 Feb 6, 2024

Choose a reason for hiding this comment

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

Instead of this nearly useless fit here and in the fixture below, you can take draws from a prior predictive with narrow priors that correspond to a reasonable posterior and store those as if they were the posterior. We do this in almost all CLV tests.

There should be one test that actually calls fit (from real priors) and asserts it is converging to something correct. That could be marked with @pytest.mark.slow so it is skipped by default locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that sounds good
What converging stats do you have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

I dunno. We can simulate data with known parameters and check the posterior converges to those with some relative tolerance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. I will add that in

Some of the tests still call fit with draws=100
Is that an issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

Depends on whether that is relevant for the test or not

@wd60622
Copy link
Contributor Author

wd60622 commented Feb 6, 2024

Tests seem to be a lot faster! So step in the right direction 😄
Thanks for pointing out @ricardoV94

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (167482f) 91.34% compared to head (1a028ed) 91.36%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #515      +/-   ##
==========================================
+ Coverage   91.34%   91.36%   +0.02%     
==========================================
  Files          21       21              
  Lines        2067     2073       +6     
==========================================
+ Hits         1888     1894       +6     
  Misses        179      179              

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

@wd60622
Copy link
Contributor Author

wd60622 commented Feb 6, 2024

some other tests that depend on the fit... Will have to change a bit more than expected
Will work through them sometime soon

@ricardoV94
Copy link
Contributor

So let's merge the easy wins with the scope and optimize in a separate PR?

@wd60622
Copy link
Contributor Author

wd60622 commented Feb 7, 2024

Going back one commit for the easy win solution. Will create an issue for follow up

@ricardoV94 ricardoV94 changed the title change scope to module Reuse fixtures in slow MMM tests Feb 7, 2024
@juanitorduz juanitorduz merged commit a224cfe into pymc-labs:main Feb 9, 2024
13 checks passed
@juanitorduz
Copy link
Collaborator

Thanks @wd60622 !

@wd60622 wd60622 deleted the speed-up-out-of-sample-tests branch February 9, 2024 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_new_data_sample_posterior_predictive_method takes 50 minutes (70%) of CI time
3 participants