Skip to content

Commit a9aa065

Browse files
committed
Add job_number to Controller simulationParameters
1 parent 4193636 commit a9aa065

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/utilities/MonteCarlo/Controller.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ def setVerbose(self, verbose):
197197
"""
198198
self.simParams.verbose = verbose
199199

200+
201+
def setJobNumber(self, job_number):
202+
"""
203+
Set the job number of the simulation.
204+
Used in AWS work to modify the seed used in dispersion.
205+
Should be set to $AWS_BATCH_JOB_ARRAY_INDEX
206+
207+
:param job_number:
208+
:return:
209+
"""
210+
self.simParams.job_number = job_number
211+
200212
def setDispMagnitudeFile(self, magnitudes):
201213
"""
202214
Save .txt with the magnitude of each dispersion in % or sigma away from mean
@@ -712,7 +724,7 @@ class SimulationParameters():
712724
def __init__(self, creationFunction, executionFunction, configureFunction,
713725
retentionPolicies, dispersions, shouldDisperseSeeds,
714726
shouldArchiveParameters, filename, icfilename, index=None, verbose=False, modifications={},
715-
showProgressBar=False):
727+
showProgressBar=False, job_number=1):
716728
self.index = index
717729
self.creationFunction = creationFunction
718730
self.executionFunction = executionFunction
@@ -728,7 +740,7 @@ def __init__(self, creationFunction, executionFunction, configureFunction,
728740
self.dispersionMag = {}
729741
self.saveDispMag = False
730742
self.showProgressBar = showProgressBar
731-
743+
self.job_number = job_number
732744

733745

734746
class SimulationExecutor:
@@ -764,9 +776,11 @@ def __call__(cls, params):
764776
try:
765777
signal.signal(signal.SIGINT, signal.SIG_IGN) # On ctrl-c ignore the signal... let the parent deal with it.
766778

767-
# must make new random seed on each new thread.
768-
np.random.seed(simParams.index * 10)
769-
random.seed(simParams.index * 10)
779+
780+
# must make new random seed on each new thread and job number
781+
dispersion_seed = (simParams.job_number << 32) + (simParams.index * 10)
782+
np.random.seed(dispersion_seed)
783+
random.seed(dispersion_seed)
770784

771785
# create the users sim by calling their supplied creationFunction
772786
simInstance = simParams.creationFunction()

0 commit comments

Comments
 (0)