Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: interaction between random seed and readparfile #643

Open
Rick-Methot-NOAA opened this issue Nov 12, 2024 · 4 comments
Open

[Bug]: interaction between random seed and readparfile #643

Rick-Methot-NOAA opened this issue Nov 12, 2024 · 4 comments
Assignees

Comments

@Rick-Methot-NOAA
Copy link
Collaborator

Describe the bug

During a jitter analysis (Marta Cousido) observed the following behaviour. When setting the seed in the starter file and using the "Initial Parameter Values=0" option, the seed seems to work correctly as I ran three models with the same seed and all three gave identical estimates.However, when I switch to "Initial Parameter Values=1" and set the seed in the starter file, the seed does not seem to work consistently. I ran three models with the same seed, but each gave different results. Is there any explanation for this behaviour?

To Reproduce

Rick will create a test example

Expected behavior

random seed to work as expected

Screenshots

No response

Which OS are you seeing the problem on?

No response

Which version of SS3 are you seeing the problem on?

No response

Additional Context

No response

@iantaylor-NOAA
Copy link
Contributor

I tried jittering without reading from the .par file and got different results each time.

It looks like the optional user-input random seed is used in the creation of bootstrap data files here: https://github.com/nmfs-ost/ss3-source-code/blob/main/SS_write_ssnew.tpl#L22-L25 but not in the calculation of jittered initial values here: https://github.com/nmfs-ost/ss3-source-code/blob/main/SS_objfunc.tpl#L1488.

If we were to use the user-controlled random seed for the jittered parameters then you would need to change the seed in the starter file each time your ran a new jitter. That's possible but might require some change in workflow. It might be tricky to use random seeds in the r4ss::jitter() function which now has parallelization, so I think the easier solution would just be to add an error if the user inputs a random seed. The benefit would be more reproducibility in the jittering process. Alternatively we could just document the fact that the seed only impacts the bootstrap data files, not the jitters.

@MartaCousido, can you tell us more about the use case you have and how important setting the seed in the jitters would be?

@MartaCousido
Copy link

MartaCousido commented Nov 15, 2024 via email

@iantaylor-NOAA
Copy link
Contributor

Thanks for the additional details @MartaCousido.
Your findings support my conclusion that the jitters is SS3 are using the start time, not the random seed. But changing the code to make use of the random seed could impact how users typically run jitters.

@okenk and I thought about the possibility of simultaneous start times and matching seeds when jittering and thought that the "likelihood of the cores using the exact same seed is infinitesimal" https://r4ss.github.io/r4ss/reference/jitter.html#details.
However, I now see that the C++ time() function used to set the seeds for the jitters only provides the time in seconds, so simultaneous start times could easily occur: https://en.cppreference.com/w/c/chrono/time.
One alternative solution might be to use a more precise clock using something like https://en.cppreference.com/w/cpp/chrono/high_resolution_clock.
Additionally the r4ss::jitter() function (if you're using it) could build in some kind of random delay to the starting time to avoid simultaneous starts.

@MartaCousido
Copy link

MartaCousido commented Nov 19, 2024 via email

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

No branches or pull requests

3 participants