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 issue with pickling Deterministic #4120

Merged
merged 6 commits into from
Sep 20, 2020

Conversation

Spaak
Copy link
Member

@Spaak Spaak commented Sep 20, 2020

This should fix #4112 in a more specific way than #4117. Work in progress, but filing now already to share the relevant str test. The fix itself should be done later today.

@Spaak Spaak changed the title [WIP] Fix issue with pickling Deterministic Fix issue with pickling Deterministic Sep 20, 2020
@Spaak
Copy link
Member Author

Spaak commented Sep 20, 2020

@AlexAndorra @canyon289 @MarcoGorelli @aloctavodia @ahartikainen

With e9bc36c, this PR should fix #4112 while keeping all new str functionality intact (#4076), and hopefully rendering #4117 obsolete. I cherry-picked the new pickling tests by @canyon289 and added them here, too.

@codecov
Copy link

codecov bot commented Sep 20, 2020

Codecov Report

Merging #4120 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4120   +/-   ##
=======================================
  Coverage   88.75%   88.75%           
=======================================
  Files          89       89           
  Lines       14040    14041    +1     
=======================================
+ Hits        12461    12462    +1     
  Misses       1579     1579           
Impacted Files Coverage Δ
pymc3/model.py 89.33% <100.00%> (+0.01%) ⬆️

new_type = type(old_type.__name__ + '_pymc3_Deterministic', (old_type,),
{'__str__': functools.partial(_repr_deterministic_rv, var, formatting='plain')})
var.__class__ = new_type
var.__class__ = DeterministicWrapper # adds str and latex functionality
Copy link
Contributor

@MarcoGorelli MarcoGorelli Sep 20, 2020

Choose a reason for hiding this comment

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

Is it possible for var to be a numpy array here*, in which case, would assigning its .__class__ attribute to a subclass of tt.TensorVariable cause problems? (I'm new to PyMC3 so sorry for the basic question :) )

*the definition of floatX would suggest it

Copy link
Member Author

Choose a reason for hiding this comment

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

This will indeed cause errors if var is not a TensorVariable. I think a deterministic will always be a TensorVariable, at least it is in all the test scripts and demos. It's a good question, though; I'm not sure there is any formal specification requiring that it has to be. (But I cannot really see how a numpy-typed deterministic makes sense, given that all model factors are TensorVariables anyway (and all results of e.g. numpy * tensorvariable etc. are also of type TensorVariable))

@canyon289
Copy link
Member

This looks great to me. Thank you so much for the fast follow up

@canyon289 canyon289 merged commit 66f078c into pymc-devs:master Sep 20, 2020
@Spaak Spaak deleted the fix_pickle_issue branch September 21, 2020 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pickling error
3 participants