feat: add a 'seed' option for reproducible outputs #4532
+105
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Explanation: Why and how do your changes improve the library?
For example:
Before this PR, the points were never in the same position at each run. A
seedoption is added to get exactly the same result every time, e.g. withmanim -pql --seed 42 main.py *.It also works with multiple scenes. For example here, the 5 points of the second scene will be the same as the first 5 points of the first scene.
Links to added or changed documentation pages
https://manimce--4532.org.readthedocs.build/en/4532/guides/configuration.html
Further Information and Comments
There is some drawbacks:
Will break if something else than
randomornumpy.randomis used for randomness (e.g.secretsortorch.random).To avoid any change for the user, it simply modifies the global random state at each scene initialization. A pseudo-code is:
So if scenes are created in a different order, or if anything that uses random numbers is created between the the init and the render, results will be different.
The only way for the user to avoid any drawback is to get a local random state for each scene
or same with
rng = random.Random(config.seed)for therandommodule.In this case, the only thing that this PR brings is the
seedconfig option, nothing else.Reviewer Checklist