DOC: Use a consistent random seed in examples.#7382
DOC: Use a consistent random seed in examples.#7382QuLogic wants to merge 1 commit intomatplotlib:v2.xfrom
Conversation
This ensures that repeated builds of the documentation produce the same images, which improves consistency.
| # Initialize random number generator for consistent plots. | ||
| import random | ||
| random.seed(20021210) | ||
| del random |
There was a problem hiding this comment.
what's the point of importing random, then deleting random, then using np.random?
There was a problem hiding this comment.
I don't know for certain whether any of our examples use random, but I don't think np.random shares seed with it. I delete it because our documentation already mysteriously depends on np and plt existing and I don't want anyone else to start depending on random, too.
There was a problem hiding this comment.
That doesn't do anything. It fixes the seed for the stdlib random generator, but not numpy's.
There was a problem hiding this comment.
Right, which is why there's a line just underneath setting numpy's seed.
There was a problem hiding this comment.
so once #7385 is merged, you can get rid of these three lines.
|
If we want to have to have reproducible examples, fixing the random seed should be done in the examples, not in our documentation building system. (That is also unlikely to work with sphinx-gallery). |
|
I'm not sure I agree about putting it in the examples themselves. IMO, the seed isn't for the benefit of those using them, so much as our ability to use them to smoke out changes. You'd be adding more lines of boilerplate for no educational benefit. |
|
I'm not aiming for reproducible examples, but for reproducible documentation. It means if you change some small documentation thing, only that thing will change. In a way, I think it's more "fun" (or let's say, interesting) to have the examples be truly random, and it detracts from them by setting a seed. |
|
Couldn't a quick git grep tell us if the examples use random? And then change those over to np.random just to keep this cleaner. |
|
There's only one example importing standard library's |
|
I like the idea of reproducible plots in our docs. I'm not sure what the significance of @NelleV mentioned that this won't affect sphinx-gallery when we switch to that, but perhaps it'd be worth adding the |
|
On the other hand - there are only 17 files that use of those, |
|
Why are you only looking at |
|
I could have sworn it was >100, but I must have forgotten to exclude the seeded ones. There are 80 examples without seeds: plus the 6 in |
|
Oh, and 20021210 was the first date I could pull out of the changelog, but I have no real tie to it. |
I used |
|
I still think this could be a good |
|
I can volunteer to make the examples reproducible. |
|
Closing for #7386. |
This ensures that repeated builds of the documentation produce the same images, which improves consistency.
There are about 100 examples that use randomness without setting a seed, so this seems the more prudent (and lazier) solution.