Repository navigation
BUG: Ensure seed sequences are restored through pickling - #26260
Conversation
|
The biggest concern I have with this approach is the requirement that the seed sequence uses the 3-argument version of |
f039e85 to
3ca64f5
Compare
|
Should probably have a test using a file pickle generated from 1.26.x. |
seberg
left a comment
There was a problem hiding this comment.
(submodules are in a bad state unfortunately, although maybe you fixed it by the time I comment :))
Thanks! Preserving unpicking of old files is easy enough, yeah. If we also care about unpickling of new ones on old versions, we would need to try my solution, I think.
Breaking loading 2.0 files in 1.x should be OK, though. I am a bit unsure of backporting into a bug-fix 1.26.x. But maybe just as well.
| # Unpickle the seed sequence | ||
| ss_ctor, ss_ctor_args, ss_state = seed_seq_info | ||
| seed_seq = ss_ctor(*ss_ctor_args) | ||
| seed_seq.__setstate__(ss_state) |
There was a problem hiding this comment.
Should remove this here, for simplification. Which you can do if you just use self._seed_seq in the __reduce__ below (rather than seed_seq.__reduce__()).
There was a problem hiding this comment.
I simplified this by removing the unnecessary call to reduce
seberg
left a comment
There was a problem hiding this comment.
Thanks for having a look! LGTM, modulo the print and the tests seem good.
As I said, not sure I would like to backport this beyond 2.0, but I think backport into 2.0 would be good.
I'll leave it a bit in case someone has a comment, but basically, I think it is good modulo the print and rebasing away the submodule changes.
|
I do plan on one more release of 1.26 if the release still builds. But this bug has been around since 1.17, so maybe not so important to fix. |
seberg
left a comment
There was a problem hiding this comment.
Looks good for backporting to 2.0, want to wait a bit in case someone wants to make a comment or you agree that trying to simplify a bit more is worthwhile.
But, I am happy if we put it in as is, I think it is a bug fix and also an improvement, plus we got new tets.
| # Pickling support: | ||
| def __getstate__(self): | ||
| return self.bit_generator.state | ||
| return self.bit_generator.__getstate__() |
There was a problem hiding this comment.
Should be good, so don't think we need to iterate more (it is nicer than before!). But thought I would comment that I would think we can just return the bit_generator here (which then gets pickled), so that Generator need not know that the bit generator even has a getstate/state.
There was a problem hiding this comment.
I've removed this, simplified a bit more, and made sure it work with legacy pickles (<2 and <1.22, which had different __reduce__ implementations).
I think it is ready now (subject to green). Only question remaining is whether to go ahead and return type(self) instead of self.__class__.___name__?
e1d0cb2 to
f9cb51d
Compare
|
When ready to merge, I should also probably squash some or all of the commits. |
550b8b8 to
3aba7a1
Compare
|
Grrr mypy strict typing... |
b005ffa to
3a02920
Compare
Explicity store and restore seed sequence closes numpy#26234
Make more use of set and getstate to avoid changes in the pickling functions
Add test for legacy pickles Include pickles for tests
bc2d926 to
81531b6
Compare
81531b6 to
0289bec
Compare
5aa2747 to
fc57d77
Compare
Explicitly return bit generator rather than ctor
fc57d77 to
6cd6520
Compare
|
@seberg I think this has gone as far as possible. |
|
Thanks @bashtage looks good to me, let's put this in. It was certainly a longer journey than anticipate :), but the added tests look nice. |
Explicity store and restore seed sequence closes numpy#26234 --- * BUG: Ensure seed sequences are restored through pickling Explicity store and restore seed sequence closes numpy#26234 * CLN: Simplify refactor Make more use of set and getstate to avoid changes in the pickling functions * BUG: Correct behavior for legacy pickles Add test for legacy pickles Include pickles for tests * MAINT: Correct types for pickle related functions * REF: Switch from string to type * REF: Swtich to returning bit generators Explicitly return bit generator rather than ctor
BUG: Ensure seed sequences are restored through pickling (#26260)
Explicity store and restore seed sequence
closes #26234