1+ .. _quality-assurance :
2+
13=================
24Quality Assurance
35=================
46
5- A values below are the maximum output size where a bit generator or sequence of bit generators
6- has passed PractRand _. A -- indicates that configuration is not relevant. Failures are marked
7- with FAIL. Most bit generators were only tested in their default configuration.
7+ Core Testing
8+ ------------
9+
10+ A values in the below are the maximum output size where a bit generator or sequence of
11+ bit generators has passed PractRand _. A -- indicates that configuration is not relevant.
12+ Failures are marked with FAIL. Most bit generators were only tested in their default configuration.
813Non-default configurations are indicated by listing the keyword arguments to the bit generator.
914Two sets of tests were performed. The first tested all configurations using 128GB of data using
1015PractRand's extended set of tests and additional bit folding. The second set of tests used
@@ -16,11 +21,11 @@ initialized with the same 256-bits of entropy taken from random.org.
1621.. include :: test-results.txt
1722
1823Notes
19- -----
24+ ~~~~~
2025¹ Failures at or before 128GB were generated by tests that used the expanded
2126set of tests and extra bt folds (``-te 1 `` and ``-tf 2 ``). Failures at sample
2227sizes above 128GB were produces using the default configuration
23- (``-te 0 `` and ``-tf 0 ``).
28+ (``-te 0 `` and ``-tf 1 ``).
2429
2530² PCG64DXSM and PCG64(variant=dxsm) are identical and so the latter not separately reported.
2631
@@ -32,10 +37,8 @@ is required.
3237
3338⁵ Identical output to the version included in NumPy 1.19.
3439
35- .. _PractRand : http://pracrand.sourceforge.net/
36-
3740Example Configuration
38- ---------------------
41+ ~~~~~~~~~~~~~~~~~~~~~
3942All configurations are constructed using the same template. The code below tests a
4043configuration using 8,196 streams of :class: `~randomgen.aes.AESCounter `. The other
4144configurations simply make changes to either ``JUMPED `` or ``STREAMS ``.
@@ -66,3 +69,83 @@ configurations simply make changes to either ``JUMPED`` or ``STREAMS``.
6669 for child in SEED_SEQ.spawn(STREAMS):
6770 bit_gens.append(rg.AESCounter(child, **BIT_GENERATOR_KWARGS))
6871 output = 64
72+
73+ Additional Experiments
74+ ----------------------
75+ The best practice for using any of the bit generators is to initialize
76+ a single :class: `~numpy.random.SeedSequence ` with a reasonably random seed,
77+ and then to use this seed sequence to initialize all bit generators.
78+ Some additional experiments were used to check that the quality of output
79+ streams is not excessively sensitive to use that deviates from this best practice.
80+
81+ Correlated Seeds
82+ ~~~~~~~~~~~~~~~~
83+ While the recommended practice is to use a :class: `~numpy.random.SeedSequence `,
84+ it is natural to worry about bad seeds. A common sequence of bad seeds are
85+ those which set a single bit to be non-zero: 1, 2, 4, 8, 16, and so on.
86+ By default, bit generators use a :class: `~numpy.random.SeedSequence ` to transform
87+ seed values into an initial state for the bit generator.
88+ :class: `~numpy.random.SeedSequence ` is itself a random number generator that always
89+ escapes low-entropy states -- that is, those with many 0s or 1s -- immediately.
90+ All bit generators were tested with 8 streams using seeds of the form :math: `2 ^i` for
91+ i in 0, 1, ..., 7. Only three bit generators failed this experiment: :class: `~randomgen.dsfmt.DSFMT `,
92+ :class: `~randomgen.mt19937.MT19937 `, and :class: `~randomgen.sfmt.SFMT `. These are all
93+ members of the Mersenne Twister family which commonly fail ``BRank `` tests.
94+
95+ Sequential Seeds
96+ ~~~~~~~~~~~~~~~~
97+ The recommended practice for constructing multiple :class: `~numpy.random.Generator`s
98+ is to use :class:`~numpy.random.SeedSequence `'s :func: `~numpy.random.SeedSequence.spawn `
99+ method.
100+
101+ ::
102+
103+ from numpy.random import default_rng, Generator, SeedSequence
104+ from randomgen import Romu
105+
106+ NUM_STREAMS = 2**15
107+ seed_seq = SeedSequence(5897100938578919857511)
108+ # To use the default bit generator, which is not guaranteed to be stable
109+ generators = [default_rng(child) for child in seed_seq.spawn(NUM_STREAMS)]
110+
111+ # To use a specific bit generator
112+ generators = [Generator(Romu(child)) for child in seed_seq.spawn(NUM_STREAMS)]
113+
114+ It is common to see examples that use sequential seed that resemble:
115+
116+ ::
117+
118+ generators = [default_rng(i) for i in range(NUM_STREAMS)]
119+
120+ This practice was examined with all bit generators using 8,196 streams
121+ seeded using 0, 1, 2, ..., 8,195 by intertwining the output of the
122+ generators. **None ** of the generators failed these tests.
123+
124+ Zero (0) Seeding
125+ ~~~~~~~~~~~~~~~~
126+ Bit generators use a :class: `~numpy.random.SeedSequence ` that always
127+ escapes low-entropy states immediately to transform
128+ seed values into an initial state for the bit generator.
129+ To ensure that this is not an issue, all bit generators were tested using 4, 32 or 8196
130+ streams using 128GB in PractRand _ with expanded tests and extra folding. The table
131+ below reports **only ** the configurations that failed. These were all Mersenne Twister-class
132+ generators and so failure is attributable to the bit generator and not the seeding.
133+ All other generators passed these tests.
134+
135+
136+ +--------------+---------------+----------------+------+
137+ | Streams | 4 | 32 | 8196 |
138+ +==============+===============+================+======+
139+ | DSFMT | FAIL at 64 GB | FAIL at 64 GB | -- |
140+ +--------------+---------------+----------------+------+
141+ | MT19937 | FAIL at 64 GB | FAIL at 64 GB | -- |
142+ +--------------+---------------+----------------+------+
143+ | SFMT | FAIL at 64 GB | FAIL at 64 GB | -- |
144+ +--------------+---------------+----------------+------+
145+
146+ The non-failures at 8196 are due to the relatively short length of each sequence tested since
147+ 128GB shared across 8196 streams only samples :math: `2 ^{37 }/(2 ^{13 }\times2 ^{3 })=2 ^{21 }` values
148+ from each stream since each value is 8-bytes.
149+
150+
151+ .. _PractRand : http://pracrand.sourceforge.net/
0 commit comments