-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
CustomDist
and Simulator
no longer require class_name
when creating a dist
#6668
CustomDist
and Simulator
no longer require class_name
when creating a dist
#6668
Conversation
* Also remove the experimental warning when using CustomSymbolicDists
CustomDist
and Simulator
no longer require class_name when creating a dist
CustomDist
and Simulator
no longer require class_name when creating a dist
CustomDist
and Simulator
no longer require class_name
when creating a dist
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6668 +/- ##
=======================================
Coverage 91.97% 91.97%
=======================================
Files 94 94
Lines 15942 15944 +2
=======================================
+ Hits 14662 14664 +2
Misses 1280 1280
|
@ricardoV94, is this linked to an open issue? Or is the change just to simplify the API? Anyway, I will need to read up on what is happening under the hood to understand what the problematic API was, how this is an improvement, and why |
No related issue. The goal is to simplify the API. I introduced the classnames because I thought they were necessary as we are creating new types dynamically. But I realized it's not needed so this PR removes the restriction that a user has to pass class_name. This reminds me I have to update the docstrings. |
For more context, I think I borrowed this constraint from Simulator design. We started implementing it prior to the switch to cloudpickle and I think we were having troubles implementing the dynamic class in a way that was serializable, and one of the things I tried (without remembering now if it even mattered in the end) was to request a unique |
So I've dug a bit into >>> import dis
>>> dis.disco(cloudpickle.loads(cloudpickle.dumps(a)).__class__.__init__.__code__)
3 0 LOAD_FAST 1 (a)
2 LOAD_FAST 0 (self)
4 STORE_ATTR 0 (a)
6 LOAD_CONST 0 (None)
8 RETURN_VALUE
>>> dis.disco(cloudpickle.loads(cloudpickle.dumps(b)).__class__.__init__.__code__)
9 0 LOAD_FAST 1 (b)
2 LOAD_FAST 0 (self)
4 STORE_ATTR 0 (b)
6 LOAD_CONST 0 (None)
8 RETURN_VALUE The class name is indeed the same for >>> import pickle
>>> pickle.loads(pickle.dumps(a))
PicklingError Traceback (most recent call last)
Cell In[26], line 1
----> 1 pickle.loads(pickle.dumps(a))
PicklingError: Can't pickle <class '__main__.A'>: it's not the same object as __main__.A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me
return _CustomSymbolicDist( | ||
name, | ||
*dist_params, | ||
class_name=name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, was old behavior to use the RV name as the class name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were doing "CustomDist_{class_name}", so yes, if a user created one in a model context it was
CustomDIst_mu` for example. Pretty meh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you have a concern in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No concern, just checking my understanding
Thanks for the review 🙏 @lucianopaz |
Apparently cloudpickle is happy with classes with the same name, so we don't need to request them from users...
📚 Documentation preview 📚: https://pymc--6668.org.readthedocs.build/en/6668/