Fixed #1153 Track Random Seed#1154
Conversation
|
Review these changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1154 |
|
Currently, However, internally, the |
|
With our new setup for tracking the random seed, at the start of each unit test file, you'll see: So, to reproduce all of the tests, you simply need to go into the This should make reproducing failed tests locally a lot easier! And then revert the Note that all of this is still using the old "legacy numpy random number generator" and so all of our tests (that require a specific seed) are unchanged. |
|
@NimaSarajpoor It is ready to be reviewed at your earliest convenience |
I will look into this PR within the next few days. |
NimaSarajpoor
left a comment
There was a problem hiding this comment.
@seanlaw
You made a couple of attempts before and you finally did it! I left a few comments for your consideration.
|
|
||
| # Note that an initial SEED = 0 is disallowed | ||
| # in order to account for unit testing | ||
| SEED = np.random.randint(1, 4_294_967_295, dtype=np.uint32) |
There was a problem hiding this comment.
| SEED = np.random.randint(1, 4_294_967_295, dtype=np.uint32) | |
| SEED = np.random.randint(1, 4_294_967_296, dtype=np.uint32) |
Next line shows np.random.RandomState(seed=SEED). The numpy's doc provides the following statement regarding the value of seed:
Values can be any integer between 0 and 2**32 - 1 inclusive.
Since the value of high in np.random.randint is excluded (see doc), the param high should be set to 2**32 == 4_294_967_296
| with rng.fix_seed(0): | ||
| state = rng.RNG.get_state() | ||
| seed = state[1][0] | ||
| assert seed != init_seed |
There was a problem hiding this comment.
Isn't it better to do assert seed == 0 instead?
What if seed=1 and init_seed = 5? The current assertion does not fail. BUT, I believe it should fail because seed is expected to be zero here because of passing 0 to rng.fix_seed.
| ------- | ||
| None | ||
| """ | ||
| state = RNG.get_state() |
There was a problem hiding this comment.
To be consistent with the context manager fix_state:
| state = RNG.get_state() | |
| curr_state = RNG.get_state() |
| None | ||
| """ | ||
| state = RNG.get_state() | ||
| RNG.seed(seed) |
There was a problem hiding this comment.
IIUC, the RNG state will be set to a fixed state in this context manager (similar to what fix_state does), and that state is associated with the seed. Is that correct?
There was a problem hiding this comment.
When you have a seed, it might be easier to remember that one can use fix_seed to fix the seed (and state). Is that why you did not refactor fix_seed and fix_state?
| This is typically used when you want to generate a specific random sequence once. | ||
| To repeat the same random sequence, use `fix_state` instead. If you are picking | ||
| a random seed directly before calling `fix_seed` then you probably want to use | ||
| `fix_state` instead! |
There was a problem hiding this comment.
Can you please elaborate the last sentence?
If you are picking a random seed directly before calling
fix_seedthen you probably want to usefix_stateinstead!
Fixed #1153 and #707
Also see #1112
Pull Request Checklist
Below is a simple checklist but please do not hesitate to ask for assistance!
black(i.e.,python -m pip install blackorconda install -c conda-forge black)flake8(i.e.,python -m pip install flake8orconda install -c conda-forge flake8)pytest-cov(i.e.,python -m pip install pytest-covorconda install -c conda-forge pytest-cov)black --exclude=".*\.ipynb" --extend-exclude=".venv" --diff ./in the root stumpy directoryflake8 --extend-exclude=.venv ./in the root stumpy directory./setup.sh dev && ./test.shin the root stumpy directory