Skip to content

Access to external nuts samplers via sample #6422

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

Merged
merged 4 commits into from
Feb 15, 2023
Merged

Access to external nuts samplers via sample #6422

merged 4 commits into from
Feb 15, 2023

Conversation

twiecki
Copy link
Member

@twiecki twiecki commented Jan 1, 2023

TODO:

  • Tests
  • Figure out circular dependency on nutpie test...

Major

  • All arguments except draws in sample are now keyword-only.

Enhancements

  • Access to external nuts samplers via sample

@codecov
Copy link

codecov bot commented Jan 1, 2023

Codecov Report

Merging #6422 (f489848) into main (301b28a) will decrease coverage by 0.01%.
The diff coverage is 91.80%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6422      +/-   ##
==========================================
- Coverage   94.74%   94.74%   -0.01%     
==========================================
  Files         146      147       +1     
  Lines       27807    27861      +54     
==========================================
+ Hits        26346    26397      +51     
- Misses       1461     1464       +3     
Impacted Files Coverage Δ
pymc/tests/distributions/test_mixture.py 99.35% <ø> (ø)
pymc/sampling/mcmc.py 92.28% <82.14%> (-0.75%) ⬇️
pymc/sampling/jax.py 98.26% <100.00%> (+<0.01%) ⬆️
pymc/tests/sampling/test_jax.py 100.00% <100.00%> (ø)
pymc/tests/sampling/test_mcmc_external.py 100.00% <100.00%> (ø)
pymc/model.py 90.13% <0.00%> (+0.27%) ⬆️

@ferrine
Copy link
Member

ferrine commented Jan 1, 2023

So far nutpie doesn’t provide precompiled Python wheels. So users that pip install pymc are unable to use this sampler. pymc-devs/nutpie#22

@ricardoV94
Copy link
Member

ricardoV94 commented Jan 1, 2023

So far nutpie doesn’t provide precompiled Python wheels. So users that pip install pymc are unable to use this sampler. pymc-devs/nutpie#22

That's okay, we're not making it the default here. There's a try except import with an informative message

@fonnesbeck
Copy link
Member

nutpie can currently only be installed via maturin, correct?

@twiecki
Copy link
Member Author

twiecki commented Jan 2, 2023

nutpie can currently only be installed via maturin, correct?

It's also available via conda-forge.

@twiecki
Copy link
Member Author

twiecki commented Jan 3, 2023

[pymc/sampling/mcmc.py]
pymc/sampling/mcmc.py:253: error: Argument "chains" to "sample_numpyro_nuts" has incompatible type "Optional[int]"; expected "int"
pymc/sampling/mcmc.py:255: error: Argument "random_seed" to "sample_numpyro_nuts" has incompatible type "Union[Union[int, Sequence[int], ndarray[Any, Any], None], RandomState, Generator, None]"; expected "Union[int, Sequence[int], ndarray[Any, Any], None]"
pymc/sampling/mcmc.py:266: error: Argument "chains" to "sample_blackjax_nuts" has incompatible type "Optional[int]"; expected "int"
pymc/sampling/mcmc.py:268: error: Argument "random_seed" to "sample_blackjax_nuts" has incompatible type "Union[Union[int, Sequence[int], ndarray[Any, Any], None], RandomState, Generator, None]"; expected "Union[int, Sequence[int], ndarray[Any, Any], None]"

Is this important? Not very familiar with types.

@twiecki twiecki changed the title Add fast_nuts option to sample() that tries different compiled samplers. Add compiled nuts samplers to sample() Jan 24, 2023
@ricardoV94 ricardoV94 changed the title Add compiled nuts samplers to sample() Add access to external nuts samplers via sample Jan 26, 2023
@ricardoV94 ricardoV94 marked this pull request as draft January 26, 2023 12:36
@ricardoV94 ricardoV94 changed the title Add access to external nuts samplers via sample Access to external nuts samplers via sample Jan 26, 2023
@ricardoV94 ricardoV94 force-pushed the fast_nuts branch 3 times, most recently from f2dfcaa to 5b5b9c9 Compare February 2, 2023 17:56
@ricardoV94 ricardoV94 marked this pull request as ready for review February 2, 2023 18:28
@ricardoV94
Copy link
Member

Hmm a specific version of pymc is being installed by nutpie... so the test doesn't make much sense...

@ricardoV94 ricardoV94 requested review from cluhmann, michaelosthege and aseyboldt and removed request for cluhmann February 2, 2023 18:31
@twiecki
Copy link
Member Author

twiecki commented Feb 13, 2023

@ricardoV94 Any progress? What's the status? Should someone else take over?

@ricardoV94
Copy link
Member

The problem is I don't know how to test nutpie, because nutpie has a direct dependency in pymc/pytensor (at least the conda package). I'll see if it can be pip installed instead. But it may not make sense to test at all given the circular dependency

@twiecki
Copy link
Member Author

twiecki commented Feb 13, 2023

OK, lets just not test it then, or only if it's istalled.

@ricardoV94 ricardoV94 force-pushed the fast_nuts branch 2 times, most recently from f88fadb to 27bc414 Compare February 13, 2023 16:59
@twiecki
Copy link
Member Author

twiecki commented Feb 13, 2023

Tests pass! Last comment but LGTM otherwise.

@ricardoV94
Copy link
Member

Tests already passed before, they were failing for unrelated reasons :)

Still didn't remove the test dependency on nutpie

@@ -503,7 +613,7 @@ def sample(
)

sample_args = {
"draws": draws,
"draws": draws + tune, # FIXME: Why is tune added to draws?
Copy link
Member

Choose a reason for hiding this comment

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

probably a relic of old signatures

Copy link
Member

Choose a reason for hiding this comment

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

I will open an issue after this PR to investigate it

@michaelraczycki
Copy link
Contributor

Have you tried using dependency injection? Because if yes, other way would be to use unittest.mock, I've used it in the past but that will depend on how complex the test is.

@ricardoV94
Copy link
Member

ricardoV94 commented Feb 14, 2023

Maybe the dependency is not too bad. It first installs nutpie and then the local pymc, so I guess if PyMC depends on a newer PyTensor it will replace it by that? We can merge and see what happens when we next bump the PyTensor dependency.

@ricardoV94 ricardoV94 added the major Include in major changes release notes section label Feb 15, 2023
Reorder arguments more logically [citation needed]
@twiecki
Copy link
Member Author

twiecki commented Feb 15, 2023

This looks great! merge?

@ricardoV94
Copy link
Member

This looks great! merge?

Never hurts to see what happens next :D

@twiecki twiecki merged commit c2ce47f into main Feb 15, 2023
@twiecki twiecki deleted the fast_nuts branch February 15, 2023 20:25
@twiecki
Copy link
Member Author

twiecki commented Feb 15, 2023

Let's do a minor release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancements major Include in major changes release notes section
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants