Adding multidimensional simulator and results module to gather data for visualization.

This commit is contained in:
leobago 2023-01-16 22:43:52 +01:00
parent e8e82d7460
commit bf1a5a60e4
5 changed files with 94 additions and 37 deletions

View File

@ -2,29 +2,49 @@
class Configuration:
blockSize = 0
failureRateStep = 0
maxTries = 0
numberValidators = 0
chi = 0
failureRate = 0
deterministic = 0
blockSize = 0
numberValidators = 0
failureRate = 0
failureRateStart = 0
failureRateStop = 0
failureRateStep = 0
chio = 0
chiStart = 0
chiStop = 0
chiStep = 0
run =0
runStart = 0
runStop = 0
runStep = 0
def __init__(self, deterministic, blockSize, numberValidators,\
failureRateStart, failureRateStop, failureRateStep,\
chiStart, chiStop, chiStep,\
runStart, runStop, runStep):
def __init__(self, blockSize, failureRateStep, maxTries, numberValidators, chi, failureRate, deterministic):
if numberValidators < (blockSize*4):
print("ERROR: The number of validators cannot be lower than the block size * 4")
exit(1)
if chi < 1:
if chiStart < 1:
print("Chi has to be greater than 0")
exit(1)
if chi > blockSize:
if chiStop > blockSize:
print("Chi has to be smaller than %d" % blockSize)
exit(1)
self.blockSize = blockSize
self.failureRateStep = failureRateStep
self.maxTries = maxTries
self.numberValidators = numberValidators
self.chi = chi
self.failureRate = failureRate
self.deterministic = deterministic
self.blockSize = blockSize
self.numberValidators = numberValidators
self.failureRateStart = failureRateStart
self.failureRateStop = failureRateStop
self.failureRateStep = failureRateStep
self.failureRate = failureRateStart
self.chiStart = chiStart
self.chiStop = chiStop
self.chiStep = chiStep
self.chi = chiStart
self.runStart = runStart
self.runStop = runStop
self.runStep = runStep
self.run = runStart

17
DAS/results.py Normal file
View File

@ -0,0 +1,17 @@
#!/bin/python3
class Result:
config = []
missingVector = []
blockAvailable = -1
def __init__(self, config):
self.config = config
self.blockAvailable = -1
self.missingVector = []
def addMissing(self, missingVector):
self.missingVector = missingVector

View File

@ -4,6 +4,7 @@ import networkx as nx
import logging
from datetime import datetime
from DAS.tools import *
from DAS.results import *
from DAS.observer import *
from DAS.validator import *
@ -13,6 +14,7 @@ class Simulator:
logLevel = logging.INFO
validators = []
glob = []
result = []
config = []
logger = []
format = {}
@ -20,6 +22,7 @@ class Simulator:
def __init__(self, config):
self.config = config
self.format = {"entity": "Simulator"}
self.result = Result(self.config)
def initValidators(self):
if not self.config.deterministic:
@ -48,7 +51,7 @@ class Simulator:
for id in range(self.config.blockSize):
G = nx.random_regular_graph(d, len(rowChannels[id]))
if not nx.is_connected(G):
self.logger.error("graph not connected for row %d !" % id, extra=self.format)
self.logger.error("Graph not connected for row %d !" % id, extra=self.format)
for u, v in G.edges:
val1=rowChannels[id][u]
val2=rowChannels[id][v]
@ -56,7 +59,7 @@ class Simulator:
val2.rowNeighbors[id].append(val1)
G = nx.random_regular_graph(d, len(columnChannels[id]))
if not nx.is_connected(G):
self.logger.error("graph not connected for column %d !" % id, extra=self.format)
self.logger.error("Graph not connected for column %d !" % id, extra=self.format)
for u, v in G.edges:
val1=columnChannels[id][u]
val2=columnChannels[id][v]
@ -73,15 +76,25 @@ class Simulator:
self.logger = logger
def resetFailureRate(self, failureRate):
self.failureRate = failureRate
self.config.failureRate = failureRate
for val in self.validators:
val.config.failureRate = failureRate
def resetChi(self, chi):
self.config.chi = chi
for val in self.validators:
val.config.chi = chi
def run(self):
self.glob.checkRowsColumns(self.validators)
self.validators[self.proposerID].broadcastBlock()
arrived, expected = self.glob.checkStatus(self.validators)
missingSamples = expected - arrived
missingVector = []
steps = 0
while(missingSamples > 0):
missingVector.append(missingSamples)
oldMissingSamples = missingSamples
for i in range(1,self.config.numberValidators):
self.validators[i].receiveRowsColumns()
@ -96,7 +109,7 @@ class Simulator:
arrived, expected = self.glob.checkStatus(self.validators)
missingSamples = expected - arrived
missingRate = missingSamples*100/expected
self.logger.info("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:
break
elif missingSamples == 0:
@ -104,10 +117,13 @@ class Simulator:
else:
steps += 1
self.result.addMissing(missingVector)
if missingSamples == 0:
self.logger.debug("The entire block is available at step %d, with failure rate %d !" % (steps, self.failureRate), extra=self.format)
return 0
self.result.blockAvailable = 1
self.logger.debug("The entire block is available at step %d, with failure rate %d !" % (steps, self.config.failureRate), extra=self.format)
return self.result
else:
self.logger.debug("The block cannot be recovered, failure rate %d!" % self.failureRate, extra=self.format)
return 1
self.result.blockAvailable = 0
self.logger.debug("The block cannot be recovered, failure rate %d!" % self.config.failureRate, extra=self.format)
return self.result

View File

@ -70,7 +70,7 @@ class Validator:
self.block.data[i] = 0
nbFailures = self.block.data.count(0)
measuredFailureRate = nbFailures * 100 / (self.config.blockSize * self.config.blockSize)
self.logger.info("Number of failures: %d (%0.02f %%)", nbFailures, measuredFailureRate, extra=self.format)
self.logger.debug("Number of failures: %d (%0.02f %%)", nbFailures, measuredFailureRate, extra=self.format)
#broadcasted.print()
for id in range(self.config.blockSize):
self.sendColumn(id)

View File

@ -5,30 +5,34 @@ from DAS import *
def study():
config = Configuration(64, 20, 10, 256, 8, 0, 0)
config = Configuration(0, 64, 256, 0, 100, 20, 8, 16, 4, 0, 10, 1)
sim = Simulator(config)
sim.initLogger()
frRange = []
results = []
resultRange = []
simCnt = 0
sim.logger.info("Starting simulations:", extra=sim.format)
start = time.time()
for fr in range(0, 100, config.failureRateStep):
if fr % 10 == 0:
sim.logger.info("Failure rate %d %% ..." % fr, extra=sim.format)
for fr in range(config.failureRateStart, config.failureRateStop+1, config.failureRateStep):
sim.resetFailureRate(fr)
result = 0
for i in range(config.maxTries):
for chi in range(config.chiStart, config.chiStop+1, config.chiStep):
sim.resetChi(chi)
blockAvailable = 0
for run in range(config.runStart, config.runStop, config.runStep):
sim.logger.info("FR: %d %%, Chi: %d %%, Run: %d ..." % (fr, chi, run), extra=sim.format)
sim.initValidators()
sim.initNetwork()
result += sim.run()
result = sim.run()
blockAvailable += result.blockAvailable
results.append(result)
simCnt += 1
frRange.append(fr)
resultRange.append((config.maxTries-result)*100/config.maxTries)
resultRange.append((blockAvailable)*100/config.runStop)
end = time.time()
sim.logger.info("A total of %d simulations ran in %d seconds" % (simCnt, end-start), extra=sim.format)
for i in range(len(frRange)):
sim.logger.info("For failure rate of %d we got %d %% success rate in DAS!" % (frRange[i], resultRange[i]), extra=sim.format)
#for i in range(len(frRange)):
# sim.logger.info("For failure rate of %d we got %d %% success rate in DAS!" % (frRange[i], resultRange[i]), extra=sim.format)
study()