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

Require Seed #1211

Merged
merged 49 commits into from Jul 25, 2018
Merged

Require Seed #1211

merged 49 commits into from Jul 25, 2018

Conversation

davidsean
Copy link
Contributor

Fixes #1039

Description of changes:

Requires that the user seeds from the script, displays how to do it as part of the runtime error message

PR Checklist

  • Tests?
    • Interface
    • Core
  • Docs?

@RudolfWeeber
Copy link
Contributor

RudolfWeeber commented Jun 27, 2017 via email

@hmenke
Copy link
Member

hmenke commented Jun 27, 2017

Great! More global variables.

@mkuron
Copy link
Member

mkuron commented Jul 3, 2017

This is broken on Python 3: https://travis-ci.org/espressomd/espresso/jobs/247486394#L1369

@codecov
Copy link

codecov bot commented Oct 18, 2017

Codecov Report

❗ No coverage uploaded for pull request base (python@3e8ab5d). Click here to learn what that means.
The diff coverage is 38%.

Impacted file tree graph

@@           Coverage Diff            @@
##             python   #1211   +/-   ##
========================================
  Coverage          ?     60%           
========================================
  Files             ?     416           
  Lines             ?   28977           
  Branches          ?       0           
========================================
  Hits              ?   17391           
  Misses            ?   11586           
  Partials          ?       0
Impacted Files Coverage Δ
src/core/random.hpp 62% <33%> (ø)
src/core/random.cpp 39% <50%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e8ab5d...a62c7b1. Read the comment docs.

@jonaslandsgesell
Copy link
Member

jonaslandsgesell commented Feb 2, 2018

This PR seems to have a lot of merge conflicts. Identical seeds may result in synchronization even when the system is setup in different start configurations. This is due to stochastic thermostats like the langevin thermostat acting as an attractor and the Lyapunov exponent(s) therefore having a negative sign such that trajectories exponentially converge. The Lyapunov exponent is system dependent.

This attracting behaviour has for example been shown in 1D Lennard-Jones systems and I can reproduce this behaviour with espresso.

The remaining question is whether this synchronization may be present in systems which are of interest for us. In this case it is important to seed with different seeds when using multiple simulations to estimate the variance of observables. With same seeds (but different start configurations
) the estimated variance of the observables are wrongly too small due to the correlation of different runs with same seeds of the PRNG in espresso.

Synchronization has for example also been reported in a 3d alanine peptide system:
http://pubs.acs.org/doi/abs/10.1021/ct800573m

Although synchronization might not always happen I would be careful here and rather use a random seed. I would say to be on the safe side we should look at the alanine peptide example and see wether something like this can happen in our systems. If we decide it s not possible we can keep the fixed seeds and maybe just close this PR?

@kosovan
Copy link
Contributor

kosovan commented Feb 2, 2018

If the user is required to provide a seed, what prevents him from providing a random seed?

@RudolfWeeber
Copy link
Contributor

github and CI seem to be happy. Any specific thing @KaiSzuttor?

@@ -65,7 +65,9 @@

# System setup
#############################################################
system = espressomd.System(box_l=[1.0, 1.0, 1.0])
system = espressomd.Systembox_l=([1.0, 1.0, 1.0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong.

@@ -83,6 +89,12 @@ void init_random_seed(int seed);

inline double d_random() {
using namespace Random;

if (!user_has_seeded && !unseeded_error_thrown) {
unseeded_error_thrown = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a lot of code duplication here for every function that returns random numbers... also there is no need to throw if temperature is 0.0, e.g. the user only wants the damping part of a langevin thermostat

Copy link
Member

@KaiSzuttor KaiSzuttor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidsean please remove code duplication and only throw if temperature != 0.0

@@ -73,7 +74,7 @@ def test_npt(self):
print(avp,compressibility)

self.assertAlmostEqual(2.0, avp, delta=0.02)
self.assertAlmostEqual(0.2, compressibility, delta=0.01)
self.assertAlmostEqual(0.2, compressibility, delta=0.013)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the accepted deviation?

@RudolfWeeber
Copy link
Contributor

RudolfWeeber commented Jul 24, 2018 via email

@KaiSzuttor
Copy link
Member

I broke the drude testcase, no idea how. Thermalized bond and harmonic bond tests pass.

@KaiSzuttor
Copy link
Member

@fweik , ready for review i think


namespace Random {
extern std::mt19937 generator;
extern std::normal_distribution<double> normal_distribution;
extern std::uniform_real_distribution<double> uniform_real_distribution;
extern bool user_has_seeded;
extern bool unseeded_error_thrown;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be global, I think the best solution is to make it a static local variable in check_user_has_seeded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, but how to switch the user_has_seeded variable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only talking about unseeded_error_thrown.

@jonaslandsgesell
Copy link
Member

What was the exact reason for not requiring a user provided seed when initializing a random number generator (and preventing a random number generator to exist without a user provided seed or state)? That would be the correct dependency inversion right? Then we would not need to check for a seed to be present all the time.

@KaiSzuttor
Copy link
Member

good idea, but i think that would be some more work. having our manpower in mind, i think this PR serves our current needs. But you can open an issue.

@KaiSzuttor
Copy link
Member

@fweik

@fweik fweik merged commit 99fef59 into espressomd:python Jul 25, 2018
@mkuron mkuron mentioned this pull request Nov 2, 2018
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

Successfully merging this pull request may close these issues.

None yet

8 participants