mirror of
https://github.com/status-im/das-research.git
synced 2025-02-23 11:58:14 +00:00
Adding XML dump of results
This commit is contained in:
parent
fc7339dc91
commit
66824aedc6
@ -33,6 +33,7 @@ class Configuration:
|
|||||||
|
|
||||||
self.numberRuns = int(config.get("Advanced", "numberRuns"))
|
self.numberRuns = int(config.get("Advanced", "numberRuns"))
|
||||||
self.deterministic = config.get("Advanced", "deterministic")
|
self.deterministic = config.get("Advanced", "deterministic")
|
||||||
|
self.dumpXML = config.get("Advanced", "dumpXML")
|
||||||
|
|
||||||
if self.nvStop < (self.blockSizeStart*4):
|
if self.nvStop < (self.blockSizeStart*4):
|
||||||
print("ERROR: The number of validators cannot be lower than the block size * 4")
|
print("ERROR: The number of validators cannot be lower than the block size * 4")
|
||||||
|
@ -1,17 +1,50 @@
|
|||||||
#!/bin/python3
|
#!/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
from xml.dom import minidom
|
||||||
|
from dicttoxml import dicttoxml
|
||||||
|
|
||||||
class Result:
|
class Result:
|
||||||
|
|
||||||
config = []
|
shape = []
|
||||||
missingVector = []
|
missingVector = []
|
||||||
blockAvailable = -1
|
blockAvailable = -1
|
||||||
|
tta = -1
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, shape):
|
||||||
self.config = config
|
self.shape = shape
|
||||||
self.blockAvailable = -1
|
self.blockAvailable = -1
|
||||||
|
self.tta = -1
|
||||||
self.missingVector = []
|
self.missingVector = []
|
||||||
|
|
||||||
|
def populate(self, shape, missingVector):
|
||||||
def addMissing(self, missingVector):
|
self.shape = shape
|
||||||
self.missingVector = missingVector
|
self.missingVector = missingVector
|
||||||
|
missingSamples = missingVector[-1]
|
||||||
|
if missingSamples == 0:
|
||||||
|
self.blockAvailable = 1
|
||||||
|
self.tta = len(missingVector)
|
||||||
|
else:
|
||||||
|
self.blockAvailable = 0
|
||||||
|
self.tta = -1
|
||||||
|
|
||||||
|
def dump(self, execID):
|
||||||
|
if not os.path.exists("results"):
|
||||||
|
os.makedirs("results")
|
||||||
|
if not os.path.exists("results/"+execID):
|
||||||
|
os.makedirs("results/"+execID)
|
||||||
|
resd1 = self.shape.__dict__
|
||||||
|
resd2 = self.__dict__.copy()
|
||||||
|
resd2.pop("shape")
|
||||||
|
resd1.update(resd2)
|
||||||
|
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"
|
||||||
|
with open(filePath, "w") as f:
|
||||||
|
f.write(xmlPretty)
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
#!/bin/python3
|
#!/bin/python3
|
||||||
|
|
||||||
class Shape:
|
class Shape:
|
||||||
|
run = 0
|
||||||
numberValidators = 0
|
numberValidators = 0
|
||||||
failureRate = 0
|
|
||||||
blockSize = 0
|
blockSize = 0
|
||||||
|
failureRate = 0
|
||||||
netDegree = 0
|
netDegree = 0
|
||||||
chi = 0
|
chi = 0
|
||||||
|
|
||||||
def __init__(self, blockSize, numberValidators, failureRate, chi, netDegree):
|
def __init__(self, blockSize, numberValidators, failureRate, chi, netDegree, run):
|
||||||
|
self.run = run
|
||||||
self.numberValidators = numberValidators
|
self.numberValidators = numberValidators
|
||||||
self.failureRate = failureRate
|
|
||||||
self.blockSize = blockSize
|
self.blockSize = blockSize
|
||||||
|
self.failureRate = failureRate
|
||||||
self.netDegree = netDegree
|
self.netDegree = netDegree
|
||||||
self.chi = chi
|
self.chi = chi
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ class Simulator:
|
|||||||
|
|
||||||
def resetShape(self, shape):
|
def resetShape(self, shape):
|
||||||
self.shape = shape
|
self.shape = shape
|
||||||
|
self.result = Result(self.shape)
|
||||||
for val in self.validators:
|
for val in self.validators:
|
||||||
val.shape.failureRate = shape.failureRate
|
val.shape.failureRate = shape.failureRate
|
||||||
val.shape.chi = shape.chi
|
val.shape.chi = shape.chi
|
||||||
@ -117,19 +118,16 @@ class Simulator:
|
|||||||
missingRate = missingSamples*100/expected
|
missingRate = missingSamples*100/expected
|
||||||
self.logger.debug("step %d, missing %d of %d (%0.02f %%)" % (steps, missingSamples, expected, missingRate), extra=self.format)
|
self.logger.debug("step %d, missing %d of %d (%0.02f %%)" % (steps, missingSamples, expected, missingRate), extra=self.format)
|
||||||
if missingSamples == oldMissingSamples:
|
if missingSamples == oldMissingSamples:
|
||||||
|
#self.logger.info("The block cannot be recovered, failure rate %d!" % self.shape.failureRate, extra=self.format)
|
||||||
|
missingVector.append(missingSamples)
|
||||||
break
|
break
|
||||||
elif missingSamples == 0:
|
elif missingSamples == 0:
|
||||||
|
#self.logger.info("The entire block is available at step %d, with failure rate %d !" % (steps, self.shape.failureRate), extra=self.format)
|
||||||
|
missingVector.append(missingSamples)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
steps += 1
|
steps += 1
|
||||||
|
|
||||||
self.result.addMissing(missingVector)
|
self.result.populate(self.shape, missingVector)
|
||||||
if missingSamples == 0:
|
return self.result
|
||||||
self.result.blockAvailable = 1
|
|
||||||
self.logger.debug("The entire block is available at step %d, with failure rate %d !" % (steps, self.shape.failureRate), extra=self.format)
|
|
||||||
return self.result
|
|
||||||
else:
|
|
||||||
self.result.blockAvailable = 0
|
|
||||||
self.logger.debug("The block cannot be recovered, failure rate %d!" % self.shape.failureRate, extra=self.format)
|
|
||||||
return self.result
|
|
||||||
|
|
||||||
|
@ -25,3 +25,4 @@ chiStep = 2
|
|||||||
|
|
||||||
deterministic = 0
|
deterministic = 0
|
||||||
numberRuns = 2
|
numberRuns = 2
|
||||||
|
dumpXML = 1
|
||||||
|
29
study.py
29
study.py
@ -1,6 +1,6 @@
|
|||||||
#! /bin/python3
|
#! /bin/python3
|
||||||
|
|
||||||
import time, sys
|
import time, sys, random, copy
|
||||||
from DAS import *
|
from DAS import *
|
||||||
|
|
||||||
|
|
||||||
@ -10,36 +10,45 @@ def study():
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
config = Configuration(sys.argv[1])
|
config = Configuration(sys.argv[1])
|
||||||
sim = Simulator(config)
|
shape = Shape(0, 0, 0, 0, 0, 0)
|
||||||
|
sim = Simulator(shape)
|
||||||
sim.initLogger()
|
sim.initLogger()
|
||||||
results = []
|
results = []
|
||||||
simCnt = 0
|
simCnt = 0
|
||||||
|
|
||||||
|
now = datetime.now()
|
||||||
|
execID = now.strftime("%Y-%m-%d_%H-%M-%S_")+str(random.randint(100,999))
|
||||||
|
|
||||||
sim.logger.info("Starting simulations:", extra=sim.format)
|
sim.logger.info("Starting simulations:", extra=sim.format)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
for run in range(config.numberRuns):
|
for run in range(config.numberRuns):
|
||||||
for fr in range(config.failureRateStart, config.failureRateStop+1, config.failureRateStep):
|
for nv in range(config.nvStart, config.nvStop+1, config.nvStep):
|
||||||
for chi in range(config.chiStart, config.chiStop+1, config.chiStep):
|
for blockSize in range(config.blockSizeStart, config.blockSizeStop+1, config.blockSizeStep):
|
||||||
for blockSize in range(config.blockSizeStart, config.blockSizeStop+1, config.blockSizeStep):
|
for fr in range(config.failureRateStart, config.failureRateStop+1, config.failureRateStep):
|
||||||
for nv in range(config.nvStart, config.nvStop+1, config.nvStep):
|
for netDegree in range(config.netDegreeStart, config.netDegreeStop, config.netDegreeStep):
|
||||||
for netDegree in range(config.netDegreeStart, config.netDegreeStop, config.netDegreeStep):
|
for chi in range(config.chiStart, config.chiStop+1, config.chiStep):
|
||||||
|
|
||||||
if not config.deterministic:
|
if not config.deterministic:
|
||||||
random.seed(datetime.now())
|
random.seed(datetime.now())
|
||||||
|
|
||||||
shape = Shape(blockSize, nv, fr, chi, netDegree)
|
shape = Shape(blockSize, nv, fr, chi, netDegree, run)
|
||||||
sim.resetShape(shape)
|
sim.resetShape(shape)
|
||||||
sim.initValidators()
|
sim.initValidators()
|
||||||
sim.initNetwork()
|
sim.initNetwork()
|
||||||
result = sim.run()
|
result = sim.run()
|
||||||
sim.logger.info("Run %d, FR: %d %%, Chi: %d, BlockSize: %d, Nb.Val: %d, netDegree: %d ... Block Available: %d" % (run, fr, chi, blockSize, nv, netDegree, result.blockAvailable), extra=sim.format)
|
sim.logger.info("Shape: %s ... Block Available: %d" % (str(sim.shape.__dict__), result.blockAvailable), extra=sim.format)
|
||||||
results.append(result)
|
results.append(copy.deepcopy(result))
|
||||||
simCnt += 1
|
simCnt += 1
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
sim.logger.info("A total of %d simulations ran in %d seconds" % (simCnt, end-start), extra=sim.format)
|
sim.logger.info("A total of %d simulations ran in %d seconds" % (simCnt, end-start), extra=sim.format)
|
||||||
|
|
||||||
|
if config.dumpXML:
|
||||||
|
for res in results:
|
||||||
|
res.dump(execID)
|
||||||
|
sim.logger.info("Results dumped into results/%s/" % (execID), extra=sim.format)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
study()
|
study()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user