spirit-code / spirit

Atomistic Spin Simulation Framework
http://spirit-code.github.io
MIT License
117 stars 52 forks source link

Random seed used in stochastic LLG simulations #588

Closed joovon closed 3 years ago

joovon commented 3 years ago

Dear all,

I've been exploring some finite temperature simulations using the LLG/Depondt solver with the Python API (v2.0.1 Release version).

It appears that the value of the llg_seed parameter in the config file is either not read or accounted for, as two separate runs with different values of this seed (but identical initial states) results in identical dynamics.

Is there a way to verify which seed is used to generate the random fields in the stochastic LLG?

GPMueller commented 3 years ago

I'm afraid that is in fact a bug. The RNG is initialised as part of the parameter-struct initialisation https://github.com/spirit-code/spirit/blob/8e51bcdd78ee05d433d000c7e389fe1e6c3716bc/core/include/data/Parameters_Method_LLG.hpp#L20-L23

Therefore the config, which is read in after that initialisation, has no effect (as the RNG is not re-initialised): https://github.com/spirit-code/spirit/blob/14ed7782bd23f4828bf23ab8136ae31a21037bb3/core/src/io/Configparser.cpp#L700

A random seed is created if none was given in the config file, but the RNG is not initialised using it: https://github.com/spirit-code/spirit/blob/14ed7782bd23f4828bf23ab8136ae31a21037bb3/core/src/io/Configparser.cpp#L664-L666

I will try to quickly fix this, it should not require many changes.

GPMueller commented 3 years ago

Should be fixed with 2189dce26c41df147cadeba4d5aba1efc326b0e7.

@joovon are you able to build the develop version of Spirit? After cloning the repo and checking out the develop branch, you can install the corresponding Python package with

cd core/python
pip install -e . --user

If not, we can create a bugfix release for you.


PS: thanks for noticing and reporting this bug! You should now get the correct seed in the log, something like

...
2021-02-19 22:46:36  [ PARAM ] [IO  ] [--] [--]  Parameters LLG:
                                                     seed              = 123456
...
joovon commented 3 years ago

@GPMueller Yep, got it built and initial tests indicate that it's working as expected, i.e., the chosen seeds are reported in the log and the resulting stochastic dynamics changes between seeds. Thanks for fixing this so quickly!