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

Same code produces different results in VScode vs terminal #220

Open
fabrizioleone opened this issue Jul 20, 2023 · 10 comments
Open

Same code produces different results in VScode vs terminal #220

fabrizioleone opened this issue Jul 20, 2023 · 10 comments

Comments

@fabrizioleone
Copy link

Hi,

Thanks for this great package.

I am using bboptimize to find the minimum of a non-linear function. My approach is very simple

res = bboptimize(x -> my_obj_fun(x, args); SearchRange = [(0.0, 2.0), (0.0, 2.0)], Method = :adaptive_de_rand_1_bin)

This code produces different results if I run it on VScode or if I call Julia in batch mode from the terminal of my computer. Since everything else is identical (package version, seeds, and objective function) I wonder if bboptimize searches differently depending on how it is called.

Is this a known issue? Is there any way to make sure bboptimize gives the same results in both cases?

Thank you.

@robertfeldt
Copy link
Owner

Try to set the same random seed on both platforms otherwise the results might differ between runs since these algorithms are stochastic.

@fabrizioleone
Copy link
Author

fabrizioleone commented Aug 15, 2023 via email

@robertfeldt
Copy link
Owner

Hmm, then I don't understand it. If you're on the same machine, same Julia version, and everything else is the same there shouldn't be a difference. Are you sure VSCode is invoking the same Julia binary as when you run from the terminal? Maybe include a call to versioninfo()right before the call to bboptimize? What do you mean "searches differently depending on how it is called"? There is no difference in the code, you mean "from where" it is called, right?

@JobJob
Copy link

JobJob commented Dec 20, 2023

Maybe init_rng!(params) should be called in bbsetup? Populations get initialized there (which use the PRNG), i.e. seems it should be called before optimizer = optimizer_func(problem, params) here

@robertfeldt
Copy link
Owner

@JobJob but why would we need to do this within BlackBoxOptim when the user can do it themselves if they need a particular RNG "behavior"? Please clarify, maybe I'm missing something.

@JobJob
Copy link

JobJob commented Dec 20, 2023

Just if you wanted the same seed to produce the same result, for reproducibility. This is what I assumed would happen if I called bbsetup(f; ..., RandomizeRngSeed=false, RngSeed=42) that I'd get the same result every time, but I don't because of the setup that happens (initial population creation) before the RNG is seeded in init_rng!

@JobJob
Copy link

JobJob commented Dec 20, 2023

I guess my thinking is: what's the point of providing a RngSeed if it doesn't lead to reproducible results?

@robertfeldt
Copy link
Owner

Yes, for sure, you have a point. I'm considering skipping the fiddling with the RNG inside of the package though. Hmm, let me revisit the design around this, not sure why we introduced that in the first place... ;)

@JobJob
Copy link

JobJob commented Dec 21, 2023 via email

@robertfeldt
Copy link
Owner

Ok, now changed on master:

f3b8a2b

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