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

fix: deep copy nuts_sampler_kwarg to prevent .pop side effects #7652

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

inclinedadarsh
Copy link

@inclinedadarsh inclinedadarsh commented Jan 20, 2025

Description

Deep copy the nuts_sampler_kwargs to prevent the function (.pop method) mutating the original passed dictonary.

Related Issue

Checklist

Type of change

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

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

Copy link

welcome bot commented Jan 20, 2025

Thank You Banner]
💖 Thanks for opening this pull request! 💖 The PyMC community really appreciates your time and effort to contribute to the project. Please make sure you have read our Contributing Guidelines and filled in our pull request template to the best of your ability.

@github-actions github-actions bot added the bug label Jan 20, 2025
pymc/sampling/mcmc.py Outdated Show resolved Hide resolved
@ricardoV94
Copy link
Member

ricardoV94 commented Jan 20, 2025

The kwargs.pop in sample is fine, because it comes from **kwargs, it doesn't need any copy.

The only one that needs is the nuts_sample_kwargs, and only in the nutpie branch before we start popping it.
Just add the nuts_sampler_kwargs = nuts_sampler_kwargs.copy() line here:

compile_kwargs = {}

@inclinedadarsh
Copy link
Author

Thank you for correcting me, @ricardoV94; it means a lot to me.
I now understand why we just need the copy in the nutpie branch.

Thank you!

@ricardoV94
Copy link
Member

Thanks @inclinedadarsh

Once the tests pass we can merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of dict.pop in pm.sample leads to side effects
2 participants