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

Fixing the Random Number Generator Bug from pickled objects #8

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jeremyleung521
Copy link

When loading a model from a XXX.synd pickle object (like trpcage.synd), a previously-initialized random number generator (RNG) is used, so any trajectory generated from the loaded pickle are deterministic. You can test it by running the sample code below multiple times; the resulting output is exactly the same. Un-commenting line 7, which will create a new RNG each time, will fix that.

This branch contains all the necessary fixes for sufficiently randomized runs. These include the following changes:

  1. By default, the random number generator is reinitialized with a new entropy-derived seed when a model is loaded. I added a randomize argument to load_model() to suppress randomization, which could be useful when reproducibility is needed.
  2. When running with the WESTPA propagator, the seed is reinitialized every iteration. New options like randomize and rng_seed can be added to the west.cfg to suppress randomization for testing.
  3. Generated trajectories will be pulled from independent streams, instead of from the same random sequence. While the output will still be deterministic, this is contingent on the seed. The new seeds from 1) and 2) should produce sufficient randomness between iterations.

Test Script (need to manually run this multiple times):

import numpy as np
from synd.core import load_model

model = load_model('synd_model/ntl9_folding.synd')

# Uncomment the following lines to create a new generator every time.
#model.rng = np.random.default_rng()
print(model.rng.random())

discrete_trajectory = model.generate_trajectory(
    initial_states=np.array([121]),
    # 1 step is 10 ps
    n_steps=10
)

print(f'discrete: {discrete_trajectory}')

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.

1 participant