Skip to content

Commit aaeb00a

Browse files
committed
Automatically grab job number and default to 0
1 parent b4e992a commit aaeb00a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/utilities/MonteCarlo/Controller.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,6 @@ 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-
212200
def setDispMagnitudeFile(self, magnitudes):
213201
"""
214202
Save .txt with the magnitude of each dispersion in % or sigma away from mean
@@ -724,7 +712,7 @@ class SimulationParameters():
724712
def __init__(self, creationFunction, executionFunction, configureFunction,
725713
retentionPolicies, dispersions, shouldDisperseSeeds,
726714
shouldArchiveParameters, filename, icfilename, index=None, verbose=False, modifications={},
727-
showProgressBar=False, job_number=1):
715+
showProgressBar=False):
728716
self.index = index
729717
self.creationFunction = creationFunction
730718
self.executionFunction = executionFunction
@@ -740,7 +728,19 @@ def __init__(self, creationFunction, executionFunction, configureFunction,
740728
self.dispersionMag = {}
741729
self.saveDispMag = False
742730
self.showProgressBar = showProgressBar
743-
self.job_number = job_number
731+
732+
self.job_number = self.getJobNumber()
733+
734+
@staticmethod
735+
def getJobNumber():
736+
"""
737+
Get the job number of the simulation
738+
Utilized in AWS Batch runs to modify the seed used in dispersion.
739+
740+
:return: Job Array Index, or 0 if not running in AWS Batch.
741+
"""
742+
job_number = os.environ.get('AWS_BATCH_JOB_ARRAY_INDEX', 0)
743+
return job_number
744744

745745

746746
class SimulationExecutor:

0 commit comments

Comments
 (0)