-
Notifications
You must be signed in to change notification settings - Fork 49
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
Derivatives are different from one run to the next #403
Comments
Hi Antoine, I wouldn't say that this is a bug, simply an artifact of using a multithreaded code. The discrepancy is due to OpenMP and goes away when you only allow simsopt to use one thread. Specifically, the critical region here is the problem. The critical region doesn't guarantee that the threads all write to |
You are right, setting I think it would be worth fixing, as it is currently impossible to get twice the same result, which is obvisouly an issue for reproducibility. As an example, consider the First run gives
While running a second time gives
Note that the aspect ratio, mean iota, QS error, magnetic well and squared flux are different in both runs. In addition, first run required 132 iterations to converge, while the second one took only 122. If you increase the weight on the coils, Any suggestions on how to fix that? Something like this? https://stackoverflow.com/questions/27199255/openmp-ordering-critical-sections |
There are a couple of ways of remedying this.
might work and fits the bill. I'd also like to see how much things slow down now that threads must wait and write in the same order.
|
Thank you @andrewgiuliani, what you proposed fixed the issue. When evaluating twice the same derivative, they match up to machine precision. However, when running the
Interestingly, running rith There is thus somewhere else in simsopt an issue with the OpenMP parallelization. I would be interested to know if anyone has a suggestion to where to look! |
Hi!
I realized that getting twice the same derivatives is not guaranteed in some cases. For example, running
for some
surf
that is aSurfaceRZFourier
instance, I do not get zero as expected, for example it would returnsNow this difference is very negligible; however, when running the single stage example,
examples/3_Advanced/single_stage_optimization.py
, these errors accumulate, and after 100 iterations the optimum found can differ by 10^-3 in the degrees of freedom from one run to the other, which is an issue.To be clear - when running twice the same script, with the same initial guess, I obtain different optima.
Is this a known problem? Does anyone know how to have reproducible runs?
The text was updated successfully, but these errors were encountered: