Adding and logging random seed in the shape for each simulation

This commit is contained in:
Leonardo Bautista-Gomez 2023-03-15 13:18:02 +01:00
parent 833ae76097
commit 0a92ef7071
4 changed files with 14 additions and 14 deletions

View File

@ -39,11 +39,6 @@ class Result:
resXml = dicttoxml(resd1)
xmlstr = minidom.parseString(resXml)
xmlPretty = xmlstr.toprettyxml()
filePath = "results/"+execID+"/nbv-"+str(self.shape.numberValidators)+\
"-bs-"+str(self.shape.blockSize)+\
"-nd-"+str(self.shape.netDegree)+\
"-fr-"+str(self.shape.failureRate)+\
"-chi-"+str(self.shape.chi)+\
"-r-"+str(self.shape.run)+".xml"
filePath = "results/"+execID+"/"+str(self.shape)+".xml"
with open(filePath, "w") as f:
f.write(xmlPretty)

View File

@ -11,6 +11,7 @@ class Shape:
self.failureRate = failureRate
self.netDegree = netDegree
self.chi = chi
self.randomSeed = ""
def __repr__(self):
"""Returns a printable representation of the shape"""
@ -21,6 +22,9 @@ class Shape:
shastr += "-chi-"+str(self.chi)
shastr += "-nd-"+str(self.netDegree)
shastr += "-r-"+str(self.run)
return repr(shastr)
return shastr
def setSeed(self, seed):
"""Adds the random seed to the shape"""
self.randomSeed = seed

View File

@ -35,11 +35,15 @@ blockSizes = range(32,65,16)
# Per-topic mesh neighborhood size
netDegrees = range(6, 9, 2)
# number of rows and columns a validator is interested in
# Number of rows and columns a validator is interested in
chis = range(4, 9, 2)
# Set to True if you want your run to be deterministic, False if not
deterministic = False
# If your run is deterministic you can decide the random seed. This is ignore otherwise.
randomSeed = "DAS"
def nextShape():
for run in runs:
for fr in failureRates:

View File

@ -14,7 +14,8 @@ from DAS import *
def runOnce(sim, config, shape):
if config.deterministic:
random.seed(repr(shape))
shape.setSeed(config.randomSeed+"-"+str(shape))
random.seed(shape.randomSeed)
sim.initLogger()
sim.resetShape(shape)
@ -49,10 +50,7 @@ def study():
sim.logger.info("Starting simulations:", extra=sim.format)
start = time.time()
results = Parallel(config.numJobs)(delayed(runOnce)(sim, config, shape) for shape in config.nextShape())
end = time.time()
sim.logger.info("A total of %d simulations ran in %d seconds" % (len(results), end-start), extra=sim.format)
@ -61,8 +59,7 @@ def study():
res.dump(execID)
sim.logger.info("Results dumped into results/%s/" % (execID), extra=sim.format)
visualization = 1
if visualization:
if config.visualization:
vis = Visualizer(execID)
vis.plotHeatmaps()