TRIQS / triqs

a Toolbox for Research on Interacting Quantum Systems
https://triqs.github.io
GNU General Public License v3.0
141 stars 72 forks source link

Random sequence generated by the Mersenne Twister of boost is different in version 1.56 and newer #226

Closed krivenko closed 9 years ago

krivenko commented 9 years ago

This issue was discussed in a now-closed ticket #24. Since it has never been solved, it is very likely that someone will come across it again.

For more details see my comment https://github.com/TRIQS/triqs/issues/24#issuecomment-60490735 and hereinafter.

parcollet commented 9 years ago

Hi, I am aware of it, and that is quite bad. What are possible solutions for this ?

krivenko commented 9 years ago

By default (when RandomGeneratorName = ""), triqs::mc_tools::random_generator uses TRIQS' own implementation of mt19937 from MersenneRNG.hpp as its backend. Would it be enough to make sure that mt19937 is never explicitly requested in the tests?

parcollet commented 9 years ago

It also break the statistics test of @tayral ...

parcollet commented 9 years ago

Did you compare the generators, or a distribution ? The distribution have changed, but in my tests the mt19937 gave the same sequence between 1.54 and later... Do you have the example ?

krivenko commented 9 years ago

Did you compare the generators, or a distribution ? The distribution have changed, but in my tests the mt19937 gave the same sequence between 1.54 and later... Do you have the example ?

I had it somewhere... Shall post it here a bit later.

parcollet commented 9 years ago

Ok. It is important to confirm that it is indeed the generator itself which has changed... I agree to rm mt19937 from the tests...

krivenko commented 9 years ago

Hm, indeed, now it looks like the thing that has changed is only normal_distribution. There was a change in the seeding procedure of mt19937 between versions 1.55 and 1.56, but apparently it did not change the pseudo-random sequence. I'm sorry for disinformation.

Anyway, here is my testing program:

#include <iostream>
#include <boost/version.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_01.hpp>
#include <boost/random/normal_distribution.hpp>

int main() {

    std::cout << "Using Boost ";
    std::cout << BOOST_VERSION / 100000 << ".";
    std::cout << (BOOST_VERSION / 100) % 1000 << ".";
    std::cout << BOOST_VERSION % 100 << std::endl;

    int seed = 1567;
    std::cout << "Seed = " << seed << std::endl;
    boost::random::mt19937 gen(seed);

    std::cout << "boost::random::mt19937 (w/o distribution):\t\t";
    for(int n=0; n<5; ++n) std::cout << gen() << ' ';
    std::cout << std::endl;

    boost::random::uniform_01<> uni_dist;
    std::cout << "boost::random::mt19937 (uniform_01):\t\t";
    for(int n=0; n<5; ++n) std::cout << uni_dist(gen) << ' ';
    std::cout << std::endl;

    boost::random::normal_distribution<> norm_dist;
    std::cout << "boost::random::mt19937 (normal_distribution):\t\t";
    for(int n=0; n<5; ++n) std::cout << norm_dist(gen) << ' ';
    std::cout << std::endl;

    return 0;
}

And its output: https://gist.github.com/krivenko/acd03ad4b1c65bc2afd5#file-gistfile1-txt

parcollet commented 9 years ago

Ok, I had the same conclusion. I think the uniform_distribution is stable (it is pretty obvious). So the issue here is just the 2 statistics tests, a minor pb.

tayral commented 9 years ago

in the statistics tests, I replaced all boost calls with std:: calls...

tayral commented 9 years ago

so what do we decide here?

parcollet commented 9 years ago

At this stage, add a version of Igor's test (adapted for google test) to test that boost, std given the same generator and uniform_distrib. Then see if it ok on all machines... cc @mferrero ?

krivenko commented 9 years ago

Should I close this issue now?

parcollet commented 9 years ago

Conclusion :