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

Move sampling code to a submodule #6268

Merged
merged 2 commits into from
Nov 7, 2022

Conversation

michaelosthege
Copy link
Member

@michaelosthege michaelosthege commented Nov 5, 2022

What is this PR about?
In #6257 we already wanted to do this, but had no good way to keep the from pymc import sampling_jax imports working.

Today I found a simple solution for this, so this PR moves all *sampling*.py files into a sampling submodule.

I also moved the tests accordingly.

⚠ The commits must not be squashed, otherwise the git history of jax.py would get messed-up. ⚠

You can check the diff commit-by-commit to see that I didn't actually change +721-680 lines...

Checklist

Major / Breaking Changes

  • None

Bugfixes / New features

  • None

Docs / Maintenance

  • All sampling related modules were moved into a new pymc.sampling submodule to facilitate further refactoring.

@michaelosthege michaelosthege added this to the v4.4.0 milestone Nov 5, 2022
@michaelosthege michaelosthege self-assigned this Nov 5, 2022
@michaelosthege michaelosthege force-pushed the sampling-submodule branch 2 times, most recently from 4baf3cf to 84fac13 Compare November 5, 2022 12:36
@codecov
Copy link

codecov bot commented Nov 5, 2022

Codecov Report

Merging #6268 (f18e61c) into main (9c313cb) will increase coverage by 0.19%.
The diff coverage is 97.21%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6268      +/-   ##
==========================================
+ Coverage   94.19%   94.38%   +0.19%     
==========================================
  Files         102      108       +6     
  Lines       21480    23829    +2349     
==========================================
+ Hits        20233    22491    +2258     
- Misses       1247     1338      +91     
Impacted Files Coverage Δ
pymc/sampling/forward.py 95.55% <ø> (ø)
pymc/sampling/parallel.py 87.32% <ø> (ø)
pymc/tests/sampling/test_mcmc.py 98.75% <94.11%> (ø)
pymc/sampling/jax.py 97.19% <97.19%> (ø)
pymc/sampling/mcmc.py 90.03% <100.00%> (ø)
pymc/sampling_jax.py 100.00% <100.00%> (+2.81%) ⬆️
pymc/smc/kernels.py 97.37% <100.00%> (ø)
pymc/smc/sampling.py 83.22% <100.00%> (ø)
pymc/tests/distributions/test_mixture.py 99.35% <100.00%> (ø)
pymc/tests/distributions/test_multivariate.py 99.44% <100.00%> (ø)
... and 10 more

@michaelosthege michaelosthege force-pushed the sampling-submodule branch 2 times, most recently from 837bbfc to 14bf341 Compare November 5, 2022 13:59
@michaelosthege michaelosthege marked this pull request as ready for review November 5, 2022 13:59
Copy link
Member

@Armavica Armavica left a comment

Choose a reason for hiding this comment

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

I only have two comments:

  • There needs to be an empty __init__.py file inside tests/sampling
  • There are a few places, mainly in the tests, where you import from pm.sampling.mcmc or pm.sampling.forward instead of just pm.sampling. This is not needed for the few items that are mentioned in __all__ of these two submodules, because they are reimported in pm.sampling. But it works this way too, I didn't know if you actually wanted to be more precise, and I don't have a strong opinion on this question.

@michaelosthege
Copy link
Member Author

thanks, @Armavica ! I'll add the init file.
For the import routes that I went with the exact ones because it makes refactoring a little easier.
IMO we should try to eventually arrive at a point where each submodule has an __all__-advertised public API and only those functions are used by other components. Once we get there I agree that we should import from the init files.

@ricardoV94 want to add something too before I make the "apply review feedback commit"?

This is a follow-up to pymc-devs#6257 where we split the `sampling.py` into two files.
This is a separate commit to make sure that git tracks the rename
of the old `sampling_jax.py` to `sampling/jax.py` correctly.
@ricardoV94
Copy link
Member

ricardoV94 commented Nov 7, 2022

@ricardoV94 want to add something too before I make the "apply review feedback commit"?

LGTM, do you want a review already or still need to merge the suggestion?

@michaelosthege
Copy link
Member Author

LGTM, do you want a review already or still need to merge the suggestion?

I already added the __init__.py file, this is ready to review. You can even merge if you like it ;)

@ricardoV94 ricardoV94 merged commit 781d974 into pymc-devs:main Nov 7, 2022
@michaelosthege michaelosthege deleted the sampling-submodule branch November 7, 2022 16:39
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.

3 participants