-
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
pickle setstate: setattr __dict__ only if not empty #2972
Conversation
Sweet! At high-level, motivation not immediately obvious for me - was it speed, or correctness, and can you mention publicly visible stakeholder (Google) or proj name ( |
And for given motivation, is it possible to give precise numbers (or rough) in terms of performance gain (if it was speed / memory)? |
Performance isn't the main concerns, but Yes, this is for DeepMinds open_spiel: https://github.com/deepmind/open_spiel Thanks for looking Eric, I'll go ahead working on the unit test and will add the motivation to the description. |
61007e9
to
a4bd790
Compare
Hi @EricCousineau-TRI and @elkhrt, this PR is complete now. Could you please review? |
The one CI failure is just our most common flake (see #2995). |
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.
Thanks Ralf - this is great.
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.
Looks good, thank you for providing context (and soz for delay!)
Requesting more concrete testing, with nits on consistent styling w/ existing and usage of more explicitly conditionals in lieu of try/catch
. (Feel free to punt on nits!)
For the overview, I can see two possible "debugging" issue:
(1) you accidentally assign a non-existent attribute but py::dynamic_attr()
allows it (thus "ouch", you gotta trace that out)
(2) is that you cannot unpickle a C++ derived class, motivating py::dynamic_attr()
, forcing you to run into (1).
Is it possible for you to rewrite the overview / commit stmt to expliclty focus on (2)?
(then (1) becomes an obvious side effect?)
Lemme know if you have any Q's or would like push back on this!
61e2ba7
to
cc0cefe
Compare
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.
Thanks Eric! I updated the code and the PR description starting from your suggestion.
cc0cefe
to
ad96e32
Compare
Apparently the Centos 8 build broke for external reasons on 6/3. Trying again (PR Close-Reopen) to see if it fixed itself. |
ddcab22
to
2cbf77a
Compare
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.
Looks great! However, I think you possibly uncovered a new bug 😿
I don't think we need to block this PR on it, but we should at least leave paper trail (issue+TODO) for it!
… of py::dynamic_attr() unnecessarily.
ef433dc
to
f6c1df8
Compare
Closing-Reopening to trigger CI. |
Description
The motivation for this PR is to not force the use of
py::dynamic_attr()
unnecessarily. Concrete use case:https://github.com/deepmind/open_spiel/blob/643dfd2a5ef023e796e20d06758800ec34a1204b/open_spiel/python/pybind11/pyspiel.cc#L309
py::dynamic_attr()
comes with the disadvantage that it enables adding arbitrary attributes, which opens the door to accidents that tend to be subtle and time-consuming to debug (example situation below). The cost for avoiding this disadvantage is minuscule: just one additionalif
with 2 simple conditions in pybind11/detail/init.h.The newly added unit tests reflect a typical situation in which this PR helps: a wrapped C++ virtual base class with a trampoline, combined with the use of base class pointers to C++ derived classes.
Example situation:
py::dynamic_attr()
.py::dynamic_attr()
.py::dynamic_attr()
the code runs and produces nonsensical results. It takes you N hours to trace that out.Suggested changelog entry: