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

Using r123 in molecular dynamics #9

Open
xzhh opened this issue Mar 31, 2023 · 4 comments
Open

Using r123 in molecular dynamics #9

xzhh opened this issue Mar 31, 2023 · 4 comments
Assignees

Comments

@xzhh
Copy link

xzhh commented Mar 31, 2023

Hello,

We are software developers for MD simulation (https://github.com/espressopp/espressopp @junghans) and we have implemented r123 into a pair-based DPD thermostat.

zrng = u01<double>(crng.v[0]) - 0.5;
#ifdef RANDOM123_EXIST
   r0 = zrng;
#else
   r0 = ((*boost_rng)() - 0.5);
#endif
double noise = pref2 * omega * r0;

In this case, we need to prepare a random number with a uniform distribution (-1/2 ~ 1/2) in calculating random force for every pair(i,j) at time t. And the counter - crng.v[0] is unique with the given {t, i, j} so that the reproducibility of data is possible when the MD restarts. Recently, we found an issue that using r123 in DPD leads to a shift-up of temperature during an NVT simulation (the system is the simplest LJ fluid). The temperature is actually NOT out of control and the shift is always around +2% ~ +3% above the target temperature (but very obvious to see after running averaging the data). Comparing with the verified boostRNG, the random numbers created by r123 do not look any strange, yielding the exact uni-distribution. Then we are unsure whether the counter-based rng introduces unexpected auto-correlation under some condition or whether there's something we missed to take into accounts in implementing r123.

Thank you for reading this and that would be nice if any ideas.

Best,
Zhen-Hao Xu, Uni-Mainz (DE)

@markmoraes
Copy link

I won't be able to respond for another week, but some quick questions:

  • which Random123 rng is this using?
  • can you show a bit more code that generates the crng.v[0] (your comment suggests it's the counter, but it's been used as a random number here, is it also being used for the output of one of the rngs? )
  • some experiments worth trying:
    • switch the RNG up (e.g. if you're using ThreeFry4x64, try using ThreeFry2x64 or Philox2x64 or vice-versa.
    • Ensure you're using one of the 64 family of generators, since you want the output to be double
    • since this may be an issue with u01 rather than the rng, would u01fixedpt work for your case instead?

@markmoraes markmoraes self-assigned this Apr 2, 2023
@xzhh
Copy link
Author

xzhh commented Apr 3, 2023

Many thanks to your quick reply!

  1. The crng is defined by
crng = threefry2x64(counter, key);

See line 215 in https://github.com/xzhh/espressopp/blob/master/src/integrator/DPDThermostat.cpp

  1. I also tested with u01fixedpt but found nothing improved. Here I also attach T(t) from our test simulations and you can see the difference using between boostrng and crng. (https://seafile.rlp.net/f/6d48ec8f2ca14e319482/)

*Edit: I also used Philox2x64 with std::uniform_real_distribution but no any changes.
Z.H.

@bergdorf
Copy link

bergdorf commented Apr 6, 2023

Hi Zhen-Hao, I probably won't be able to help in a material way, but I did want to try to understand the setup a bit better:
I see here that you're setting up a counter by mapping each unique pair (i, j) to an ordinal, where i, j are the .id() of the particles. I was trying to understand the expression in L212; I plugged in intStep=0, i=0, j=0, but that yielded a negative counter value. Are these id()s using zero or one-based indexing?

Thanks!

@xzhh
Copy link
Author

xzhh commented Apr 6, 2023

Hello Michael @bergdorf

Assuming there forms a triangular matrix for pair[i,j] (j>i>0)
counter.v[0] is actually given by c = intStep*n_mat+idx(i,j). n_mat is the total number of non-zero elements of this matrix; idx(i,j) is the array position in the matrix. We do that for saving space of counters before rerolling init_seed.

Regards,
Z.H.

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