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

Examples should use numpyro only if installed #1398

Open
ricardoV94 opened this issue Jan 18, 2025 · 2 comments
Open

Examples should use numpyro only if installed #1398

ricardoV94 opened this issue Jan 18, 2025 · 2 comments
Labels
docs Improvements or additions to documentation good first issue Good for newcomers . Doesn't require extensive knowledge of the repo and package

Comments

@ricardoV94
Copy link
Contributor

ricardoV94 commented Jan 18, 2025

When you install pymc-marketing numpyro is not a requirement, but in several examples it's used.

I suggest having a pymc_marketing._numpyro_if_available variable (name up to discussion) that is "numpyro" if it's installed and "pymc" if not. Then the examples where we may want numpyro would have nuts_sample=_numpyro_if_available, and work.

In #1357 I actually changed one of the NBs to have a try/except but that clutters NBs a bit too much?

@wd60622
Copy link
Contributor

wd60622 commented Jan 18, 2025

Not a fan on the hidden name and that it is only for numpyro

What about a small class which checks the imports:

# pymc_marketing/utils.py
class InstalledSamplers(BaseModel): 
    nutpie: bool
    numpyro: bool 
    blackjax: bool

    @classmethod 
    def check(cls) -> InstalledSamplers: 
       # Check for all the requirements
    

installed_samplers = InstalledSamplers.check()

Then in notebook:

from pymc_marketing.utils import installed_samplers


model.fit(..., sampler="numpyro" if installed_samplers.numpyro else "pymc")

If user does inspect that object, it would have a nice repr

InstalledSamplers(nutpie=True, numpyro=False, blackjax=True)

@wd60622 wd60622 added docs Improvements or additions to documentation and removed Needs Triage labels Jan 18, 2025
@ricardoV94
Copy link
Contributor Author

Sounds good

@wd60622 wd60622 added the good first issue Good for newcomers . Doesn't require extensive knowledge of the repo and package label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation good first issue Good for newcomers . Doesn't require extensive knowledge of the repo and package
Projects
None yet
Development

No branches or pull requests

2 participants