Skip to content

Use a local Numpy random generator.#1030

Merged
amcadmus merged 3 commits into
deepmodeling:develfrom
shishaochen:local-random
Aug 25, 2021
Merged

Use a local Numpy random generator.#1030
amcadmus merged 3 commits into
deepmodeling:develfrom
shishaochen:local-random

Conversation

@shishaochen

@shishaochen shishaochen commented Aug 25, 2021

Copy link
Copy Markdown
Collaborator

Using np.random.seed(number) sets what NumPy calls the global random seed — affecting all uses to the np.random.* module. Some imported packages or other scripts could reset the global random seed to another random seed with np.random.seed(another_number), leading to undesirable changes to your output and your results not being reproducible.

For back compatibility, we switch to numpy.random.RandomState instead of numpy.random.default_rng.

  • Before:
>>> import numpy as np
>>> np.random.seed(3)
>>> np.random.random()
0.5507979025745755
  • After:
>>> import numpy as np
>>> rs = np.random.RandomState()
>>> rs.seed(3)
>>> rs.random_sample()
0.5507979025745755

@codecov-commenter

codecov-commenter commented Aug 25, 2021

Copy link
Copy Markdown

Codecov Report

Merging #1030 (5358778) into devel (fd1f371) will increase coverage by 0.03%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##            devel    #1030      +/-   ##
==========================================
+ Coverage   75.01%   75.05%   +0.03%     
==========================================
  Files          86       87       +1     
  Lines        6924     6938      +14     
==========================================
+ Hits         5194     5207      +13     
- Misses       1730     1731       +1     
Impacted Files Coverage Δ
deepmd/entrypoints/test.py 11.53% <50.00%> (+0.42%) ⬆️
deepmd/utils/data_system.py 71.35% <66.66%> (+0.07%) ⬆️
deepmd/utils/random.py 90.90% <90.90%> (ø)
deepmd/entrypoints/train.py 87.19% <100.00%> (ø)
deepmd/utils/data.py 90.35% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd1f371...5358778. Read the comment docs.

@amcadmus amcadmus merged commit 8048e77 into deepmodeling:devel Aug 25, 2021
gzq942560379 pushed a commit to HPC-AI-Team/deepmd-kit that referenced this pull request Sep 2, 2021
* Use a local Numpy random generator.

* Fix import error.

* Replace random generator in test_gen_stat_data.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants