-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
DOC: refactor BitGenerator docs to allow comparison and reccomendations #13675
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
Conversation
.. _`PCG author's page`: http://www.pcg-random.org/ | ||
.. _`xorshift, xoroshiro and xoshiro authors' page`: http://xoroshiro.di.unimi.it/ | ||
.. _`Random123`: https://www.deshawresearch.com/resources_random123.html | ||
|
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.
Moved this information to bit_generators/index.rst and included the top section of that back in here verbatim via an .. include::
directive
.. rubric:: Footnotes | ||
|
||
.. [1] More is better. As always with benchmarks, these are rough guides, your | ||
experience may vary. Win32 is relative to linux64, ``dSFMT`` |
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 table, which is difficult to format in RST, needs to be filled in (or revamped or removed). The numbers in the speed column are made up. Should we include timings at all here, should they be relative to a single baseline or per-OS?
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.
I would do speed relative to MT19937, which is the current release default.
There are a number of separate issues here. Github does not support threaded discussions, so if the answer is not simple and definitive it should become a separate issue/PR. It is very difficult to follow an issue with tens of comments and use of email to respond:
More? |
MT algorithms fail statistical quality tests. |
:class:`~.xoshiro512.Xoshiro512` where the `~.xoshiro512.Xoshiro512.jumped` | ||
method is used to advance the state. For very large scale applications -- | ||
requiring 1,000+ independent streams, :class:`~pcg64.PCG64` or | ||
:class:`~.philox.Philox` are the best choices. |
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.
Should we mention here that MT algorithms fail statistical quality tests? What would be a good phrasing?
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 block is out of date given the recent discussions and should be updated. Ultimately it will depend on what generators are included.
@bashtage ping, don't know if you saw this PR |
@rkern could you suggest a wording that would be appropriate for this summary, or a link for more information? Is this wikipedia page accurate? |
That list of advantages and disadvantages is not terribly applicable to us, and inexplicably puts passing "most, but not all, of the TestU01 tests" in the "advantages" category. It's very hard not to pass most of TestU01; the fact that there are smaller, faster PRNGs that do pass all of TestU01, that has to count as a disadvantage in my mind. The original TestU01 paper from 2007 has the details about the failures that On the same note, this is also why I lean against |
It would probably be best to replace the Philox implementation which is formally called |
Hmm. If we supply more than one built-in bit_generator, it would be good to be able to at least give users some idea what the tradeoffs are or some other criteria for preferring one over the other, even as a set of external links. The table now renders like this. What can we add to the last column to describe them? |
As for recommendations, I don't think that this is necessary (and perhaps not good) aside from choosing the default bit generator. Most people will stick with the default, so this is the important recommendation that matters. If a user decides to use another generator for some reason, then it seems reasonable to assume they are makign an informed decision. |
Then why include them in NumPy, they should be in an external add-on package? |
@mattip One could consider "why" bit generators are supplied. One is obvious
|
f90779f
to
5f631ef
Compare
5f631ef
to
cfa232b
Compare
I incorporated the latest comments into the refactored page and updated the table with the performance data. Any thoughts? |
Should probably cut the top tables to have the same entries as the bottom. The top seems a bit wide to me. In between two tables `RandomState(MT19937())` should probably be ``RandomState(MT19937())`` |
Is it? Which packages? The first package that comes up for me when googling "dSFMT" is |
That list reads weird to me. Those were @bashtage's reasons for incorporating each one. That's not necessarily good advice to help a user select which one to use, should they want to stray from the default. I'd help with wording, but I still maintain that we should only include the default (my preference still being |
Julia. I was under the impression that MATLAB moved to it, but I think I was mistaken and it was only added in R2015a. |
While I'm happy if PCG it is the chosen one, IMO I also think there is a case for hiding As for the others, I stand by my reasons given above. Over time I've become more enamored with the Random123 (ThreeFry/Philox) family of generators for their simplicity in high-dimensional problems, despite having mediocre performance. This family also provides the best answer to any questions about random seeding of a default RNG. I also like the hardware-accelerated versions of aesctr which are like these two but faster (not that I'd recommend these here, at least right now, despite the relatively widespread availability fo AES hardware accelaration instructions (x86, AMD64 and armV8). |
FWIW, I guess our point of difference is not so much the specifics about each PRNG algorithm per se; your reasoning for each one is sound for raising those above the universe of all PRNGs. I agree that all of them should be available to users. But to me, the hard work of that was done by your What do you think of providing the single default PRNG (plus legacy, hidden or not; separate issue) in |
The intellectual challenge I have with including a single, modern bit generator is that there isn't a clear best generator right now. There are the new, high-performance generators (PCG, Xoshiro, Wyrand), and there are new medium security (Philox, ThreeFry, ChaCha8/12) and high security (AES-Ctr (which is about as fast as PCG/Xoshiro w/ AES-NI and very slow without), Chacha20, and others) generators. These are all making different tradeoffs in different dimensions. For example, the counter-based generators have some desirable characteristics around seeding (keying) that PCG and Xoshiro do not. Both PCG and Xoshiro can be pretty easily broken by simple user interventions (advance a large round number, or multiply by 57 or respectively). The CBRNGs also have trivial advance functions, and so all support the range of alternative uses. AFAIK good CBRNGs do not have these issues. While I feel strongly that making a default choice for Finally, I think there is a case for integrating with the wider Python/random number ecosystem. Some modern generators that are not PCG are in wide use. To me, keeping some of these are first class citizens closes the distance between projects and makes it easier to move between different computational models. Not sure if you have seen VecRNG from Cern, but they are considering a similar generation strategy to SeedSequence. |
@bashtage I think we have different starting points in deciding what should be in NumPy. The way I see things is that NumPy provides a framework and basic functionality rather than a platform for experimenting with the advantages or downsides of different RNGs. I didn't always think that way, that is why there are a variety of 1D interval zero solvers in SciPy. At the time I wrote them I figured "Hey, I've played with these, let's get them all out there for others to play with", but in retrospect, only two, maybe even one, was actually needed, the rest were just baggage. I do think there is a place for a variety of RNGs, but in external packages. Indeed, I expect Intel among others to create such packages, both for speed optimizations and to provide different underlying algorithms. Leaving that work to downstream developers will decrease the maintenance burden on NumPy and encourage the natural evolution of algorithms free from the hassle of dealing with NumPy and its PR and decision processes. |
@charris I am not suggesting that NumPy should contain a wide gamut of bit generators. There are many that are clearly inappropriate for NumPy (e.g. one that used RDRAND or AES-NI). There are others that are simply dominated and so have no added value. If minimalism is the desired goal, then the only generator that has to be included is What seems stranger is to make a choice about including modern generator where it doesn't seem to have such a clear rationale for one over another. They are close enough that reasonable people with slightly different preferences over features (performance, independence) would end up at different choices. So what I am suggesting (or advocating for I suppose) is that this minimal set of distinct generators is included. |
We're talking about 6-7 generators here (assuming Xoshiro512 gets cut, with PCG32 to be decided on). If two get kept in
tl;dr SciPy isn't really an option. So I think it's either a standalone package, or in NumPy. I have no clear preference there. For me, the main deciding factor there is maintainer interest/availability. @bashtage has done most of the hard work, with a lot of support from @rkern. We will need their domain expertise. So if there's more energy for maintaining it inside NumPy, then I think that's fine. Another consideration: |
Yes, I think
I think this wording was based on a false recollection that
I think only one of these needs to be here. I think I would also dispute the "very popular in machine learning". I'm pretty sure neither (or both collectively) are more popular than That said, having a counter-based medium-strength-crypto PRNG might be justification enough all by itself; I'm just wobbly on the stated "popular in machine learning" justification.
Similarly, I'm not particularly moved by this. There's a case to be made for inter-language operation (GPU/CPU inter-operation is a kind of subset of this use case), but that would probably be best supported in the packages providing the inter-language communication. It's not like we can actually replicate the results in Julia just by using I am sympathetic to perhaps having a representative of a counter-based PRNG like
Actually, I think this is the one that gets at why I've been pushing to have just one recommended PRNG in numpy. Possibly irrationally (I'll leave it to others to judge), I just don't want The sting of finding that
I just want to be clear, these two are not the same category of things. Whereas multiplying by If we want one other modern "fast", non-counter PRNG besides |
Thanks for this. I will separate the proposal to remove each of |
I think this PR can be closed, we are going in the direction of including a minimal set of BitGenerators so in any case it would need reworking for the final set. |
Superseded by #13849, so closing. |
In order to ground the discussion in #13635, I refactored the BitGenerator documents to try to compare and contrast the alternatives. There is information missing, help needed to correct my misunderstandings and fill in missing information.