vendredi 17 juin 2016

How can I transfer a fixed_seed from main.py module to others modules?

I have been working in a model which has many process using the random number generator. I the first time I use to call "import random" in each every module where is necessary to use random generator numbers. I used this like "random.Random.seed(1)" and as the ideia it will be enough to run two different times the model and get the same results. Because was generated the "fixed_seed" in the "parameters" module.

The problem wwas there are many call process where I need to call the "parameters" module, and it's re-create the "fixed_seed". In fact, each simulation month is get the same seed for random numbers generator.

So I tried to transfer this "fixed_seed" creation from paramters to main module. But, I couldn't use the sys or argparse libraries to transfer the "fixed_seed".

My example:

############################################
# in the main model
############################################
import argparse
import random

# creating the fixed seed random generator 
fixed_seed = random.Random(0)

# transfering the fixed_seed to other modules
parser = argparse.ArgumentParser()
parsed_args = parser.parse_args(fixed_seed)

###############################################
# importing the fixed_seed in the other module
###############################################
import argparse

parser = argparse.ArgumentParser()
fixed_seed = parser.parse_args()




Aucun commentaire:

Enregistrer un commentaire