diff --git a/DAS/node.py b/DAS/node.py index 85aaf8a..abc10fe 100644 --- a/DAS/node.py +++ b/DAS/node.py @@ -32,11 +32,13 @@ class Neighbor: class Validator: + i = 0 def __init__(self, rowIDs, columnIDs): self.rowIDs = rowIDs self.columnIDs = columnIDs def initValidator(nbRows, custodyRows, nbCols, custodyCols): + random.seed(10 + Validator.i); Validator.i += 1 rowIDs = set(random.sample(range(nbRows), custodyRows)) columnIDs = set(random.sample(range(nbCols), custodyCols)) return Validator(rowIDs, columnIDs) @@ -48,7 +50,7 @@ class Node: """It returns the node ID.""" return str(self.ID) - def __init__(self, ID, amIproposer, amImalicious, logger, shape, config, + def __init__(self, ID, amIproposer, nodeClass, amImalicious, logger, shape, config, validators, rows = set(), columns = set()): """It initializes the node, and eventual validators, following the simulation configuration in shape and config. @@ -82,7 +84,7 @@ class Node: self.rowIDs = range(shape.nbRows) self.columnIDs = range(shape.nbCols) else: - self.nodeClass = 1 if (self.ID <= shape.numberNodes * shape.class1ratio) else 2 + self.nodeClass = nodeClass self.vpn = len(validators) #TODO: needed by old code, change to fn self.rowIDs = set(rows) @@ -96,13 +98,13 @@ class Node: self.logger.warning("Row custody (*vpn) larger than number of rows!", extra=self.format) self.rowIDs = range(self.shape.nbRows) else: - self.rowIDs = set(random.sample(range(self.shape.nbRows), self.vpn*self.shape.custodyRows)) + self.rowIDs = set(random.sample(range(self.shape.nbRows), max(self.vpn*self.shape.custodyRows, self.shape.minCustodyRows))) if (self.vpn * self.shape.custodyCols) > self.shape.nbCols: self.logger.warning("Column custody (*vpn) larger than number of columns!", extra=self.format) self.columnIDs = range(self.shape.nbCols) else: - self.columnIDs = set(random.sample(range(self.shape.nbCols), self.vpn*self.shape.custodyCols)) + self.columnIDs = set(random.sample(range(self.shape.nbCols), max(self.vpn*self.shape.custodyCols, self.shape.minCustodyCols))) self.rowNeighbors = collections.defaultdict(dict) self.columnNeighbors = collections.defaultdict(dict) @@ -120,10 +122,8 @@ class Node: # 1 Mbps ~= 1e6 mbps * 0.050 s / (560*8) bits ~= 11 segments/timestep if self.amIproposer: self.bwUplink = shape.bwUplinkProd - elif self.nodeClass == 1: - self.bwUplink = shape.bwUplink1 else: - self.bwUplink = shape.bwUplink2 + self.bwUplink = shape.nodeTypes["classes"][self.nodeClass]["def"]['bwUplinks'] self.bwUplink *= 1e3 / 8 * config.stepDuration / config.segmentSize self.repairOnTheFly = config.evalConf(self, config.repairOnTheFly, shape) diff --git a/DAS/observer.py b/DAS/observer.py index 7abc606..04009de 100644 --- a/DAS/observer.py +++ b/DAS/observer.py @@ -83,8 +83,8 @@ class Observer: sampleProgress = arrived / expected nodeProgress = ready / (len(validators)-1) validatorCnt = sum([v.vpn for v in validators[1:]]) - validatorAllProgress = validatedall / validatorCnt - validatorProgress = validated / validatorCnt + validatorAllProgress = (validatedall / validatorCnt) if validatorCnt != 0 else 1 + validatorProgress = (validated / validatorCnt) if validatorCnt != 0 else 1 return missingSamples, sampleProgress, nodeProgress, validatorAllProgress, validatorProgress @@ -96,7 +96,7 @@ class Observer: return np.mean(l) if l else np.NaN trafficStats = {} - for cl in range(0,3): + for cl in self.config.nodeClasses: Tx = [v.statsTxInSlot for v in validators if v.nodeClass == cl] Rx = [v.statsRxInSlot for v in validators if v.nodeClass == cl] RxDup = [v.statsRxDupInSlot for v in validators if v.nodeClass == cl] diff --git a/DAS/results.py b/DAS/results.py index f679702..2dc8db4 100644 --- a/DAS/results.py +++ b/DAS/results.py @@ -24,7 +24,6 @@ class Result: self.restoreColumnCount = [0] * shape.numberNodes self.repairedSampleCount = [0] * shape.numberNodes self.numberNodes = shape.numberNodes - self.class1ratio = shape.class1ratio def copyValidators(self, validators): """Copy information from simulator.validators to result.""" diff --git a/DAS/shape.py b/DAS/shape.py index ab17c4a..f559176 100644 --- a/DAS/shape.py +++ b/DAS/shape.py @@ -3,7 +3,7 @@ class Shape: """This class represents a set of parameters for a specific simulation.""" def __init__(self, nbCols, nbColsK, nbRows, nbRowsK, - numberNodes, failureModel, failureRate, maliciousNodes, class1ratio, custodyRows, custodyCols, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run): + numberNodes, failureModel, failureRate, maliciousNodes, custodyRows, custodyCols, minCustodyRows, minCustodyCols, netDegree, bwUplinkProd, run, nodeTypes): """Initializes the shape with the parameters passed in argument.""" self.run = run self.numberNodes = numberNodes @@ -15,14 +15,13 @@ class Shape: self.failureRate = failureRate self.maliciousNodes = maliciousNodes self.netDegree = netDegree - self.class1ratio = class1ratio self.custodyRows = custodyRows self.custodyCols = custodyCols - self.vpn1 = vpn1 - self.vpn2 = vpn2 + self.minCustodyRows = minCustodyRows + self.minCustodyCols = minCustodyCols self.bwUplinkProd = bwUplinkProd - self.bwUplink1 = bwUplink1 - self.bwUplink2 = bwUplink2 + self.nodeTypes = nodeTypes + self.nodeClasses = [0] + [_k for _k in nodeTypes["classes"].keys()] self.randomSeed = "" def __repr__(self): @@ -35,17 +34,15 @@ class Shape: shastr += "-nn-"+str(self.numberNodes) shastr += "-fm-"+str(self.failureModel) shastr += "-fr-"+str(self.failureRate) - shastr += "-c1r-"+str(self.class1ratio) shastr += "-cusr-"+str(self.custodyRows) shastr += "-cusc-"+str(self.custodyCols) - shastr += "-vpn1-"+str(self.vpn1) - shastr += "-vpn2-"+str(self.vpn2) + shastr += "-mcusr-"+str(self.minCustodyRows) + shastr += "-mcusc-"+str(self.minCustodyCols) shastr += "-bwupprod-"+str(self.bwUplinkProd) - shastr += "-bwup1-"+str(self.bwUplink1) - shastr += "-bwup2-"+str(self.bwUplink2) shastr += "-nd-"+str(self.netDegree) shastr += "-r-"+str(self.run) shastr += "-mn-"+str(self.maliciousNodes) + shastr += "-ntypes-"+str(self.nodeTypes['group']) return shastr def setSeed(self, seed): diff --git a/DAS/simulator.py b/DAS/simulator.py index 3657b03..fe6f3f9 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -44,6 +44,15 @@ class Simulator: self.proposerPublishToR = config.evalConf(self, config.proposerPublishToR, shape) self.proposerPublishToC = config.evalConf(self, config.proposerPublishToR, shape) + def getNodeClass(self, nodeIdx): + nodeRatios = [_v['weight'] for _k, _v in self.shape.nodeTypes["classes"].items()] + nodeCounts = [int(self.shape.numberNodes * ratio / sum(nodeRatios)) for ratio in nodeRatios] + commulativeSum = [sum(nodeCounts[:i+1]) for i in range(len(nodeCounts))] + commulativeSum[-1] = self.shape.numberNodes + for i, idx in enumerate(commulativeSum): + if nodeIdx <= idx: + return self.shape.nodeClasses[i + 1] + def initValidators(self): """It initializes all the validators in the network.""" self.glob = Observer(self.logger, self.shape) @@ -125,11 +134,11 @@ class Simulator: self.logger.error("custodyRows has to be smaller than %d" % self.shape.nbRows) vs = [] - nodeClass = 1 if (i <= self.shape.numberNodes * self.shape.class1ratio) else 2 - vpn = self.shape.vpn1 if (nodeClass == 1) else self.shape.vpn2 + nodeClass = self.getNodeClass(i) + vpn = self.shape.nodeTypes["classes"][nodeClass]["def"]['validatorsPerNode'] for v in range(vpn): vs.append(initValidator(self.shape.nbRows, self.shape.custodyRows, self.shape.nbCols, self.shape.custodyCols)) - val = Node(i, int(not i!=0), amImalicious_value, self.logger, self.shape, self.config, vs) + val = Node(i, int(not i!=0), nodeClass, amImalicious_value, self.logger, self.shape, self.config, vs) if i == self.proposerID: val.initBlock() else: @@ -311,12 +320,9 @@ class Simulator: cnN = "nodes ready" cnV = "validators ready" cnT0 = "TX builder mean" - cnT1 = "TX class1 mean" - cnT2 = "TX class2 mean" - cnR1 = "RX class1 mean" - cnR2 = "RX class2 mean" - cnD1 = "Dup class1 mean" - cnD2 = "Dup class2 mean" + cnT = lambda i: f"TX class{i} mean" + cnR = lambda i: f"RX class{i} mean" + cnD = lambda i: f"Dup class{i} mean" # if custody is based on the requirements of underlying individual # validators, we can get detailed data on how many validated. @@ -325,19 +331,20 @@ class Simulator: cnVv = validatorProgress else: cnVv = validatorAllProgress - - progressVector.append({ - cnS:sampleProgress, - cnN:nodeProgress, - cnV:cnVv, - cnT0: trafficStats[0]["Tx"]["mean"], - cnT1: trafficStats[1]["Tx"]["mean"], - cnT2: trafficStats[2]["Tx"]["mean"], - cnR1: trafficStats[1]["Rx"]["mean"], - cnR2: trafficStats[2]["Rx"]["mean"], - cnD1: trafficStats[1]["RxDup"]["mean"], - cnD2: trafficStats[2]["RxDup"]["mean"], - }) + + progressDict = { + cnS: sampleProgress, + cnN: nodeProgress, + cnV: cnVv, + cnT0: trafficStats[0]["Tx"]["mean"] + } + for nc in self.shape.nodeClasses: + if nc != 0: + progressDict[cnT(nc)] = trafficStats[nc]["Tx"]["mean"] + progressDict[cnR(nc)] = trafficStats[nc]["Rx"]["mean"] + progressDict[cnD(nc)] = trafficStats[nc]["RxDup"]["mean"] + + progressVector.append(progressDict) if missingSamples == oldMissingSamples: if len(missingVector) > self.config.steps4StopCondition: diff --git a/DAS/visualizor.py b/DAS/visualizor.py index a95c9c4..0db4262 100644 --- a/DAS/visualizor.py +++ b/DAS/visualizor.py @@ -14,14 +14,15 @@ def plotData(conf): plt.text(1.05, 0.05, conf["textBox"], fontsize=14, verticalalignment='bottom', transform=plt.gca().transAxes, bbox=props) if conf["type"] == "plot" or conf["type"] == "plot_with_1line": for i in range(len(conf["data"])): - plt.plot(conf["xdots"], conf["data"][i], conf["colors"][i], label=conf["labels"][i]) + # plt.plot(conf["xdots"], conf["data"][i], conf["colors"][i], label=conf["labels"][i]) + plt.plot(conf["xdots"], conf["data"][i], label=conf["labels"][i]) elif conf["type"] == "individual_bar" or conf["type"] == "individual_bar_with_2line": plt.bar(conf["xdots"], conf["data"]) elif conf["type"] == "grouped_bar": for i in range(len(conf["data"])): plt.bar(conf["xdots"], conf["data"][i], label=conf["labels"][i]) if conf["type"] == "individual_bar_with_2line": - plt.axhline(y = conf["expected_value1"], color='r', linestyle='--', label=conf["line_label1"]) + plt.axhline(y = conf["expected_value1"], color='w', linestyle='--', label=conf["line_label1"]) plt.axhline(y = conf["expected_value2"], color='g', linestyle='--', label=conf["line_label2"]) if conf["type"] == "plot_with_1line": plt.axhline(y = conf["expected_value"], color='g', linestyle='--', label=conf["line_label"]) @@ -63,7 +64,32 @@ class Visualizor: for i in range(0, len(text), 2): d[text[i]] = text[i + 1] return d - + + def __getNodeTypes__(self, group): + theGroup = dict() + for nt in self.config.nodeTypesGroup: + if nt['group'] == group: + for _k, _v in nt["classes"].items(): + theGroup[_k] = { + "vpn": _v["def"]["validatorsPerNode"], + "bw": _v["def"]["bwUplinks"], + "w": _v["weight"] + } + break + + return theGroup + + def __getNodeRanges(self, shape): + nodeClasses, nodeRatios = [], [] + for _k, _v in shape.nodeTypes["classes"].items(): + nodeClasses.append(_k) + nodeRatios.append(_v['weight']) + nodeCounts = [int(shape.numberNodes * ratio / sum(nodeRatios)) for ratio in nodeRatios] + commulativeSum = [sum(nodeCounts[:i+1]) for i in range(len(nodeCounts))] + commulativeSum[-1] = shape.numberNodes + + return nodeClasses, commulativeSum + def plotHeatmaps(self, x, y): """Plot the heatmap using the parameters given as x axis and y axis""" print("Plotting heatmap "+x+" vs "+y) @@ -133,8 +159,8 @@ class Visualizor: # self.plotSampleRecv(result, plotPath) # self.plotRestoreRowCount(result, plotPath) # self.plotRestoreColumnCount(result, plotPath) - # if self.config.saveRCdist: - # self.plotRowCol(result, plotPath) + if self.config.saveRCdist: + self.plotRowCol(result, plotPath) # self.plotBoxSamplesRepaired(result, plotPath) # self.plotBoxMessagesSent(result, plotPath) @@ -169,10 +195,15 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Box Plot of Restore Row Count by Nodes" conf["xlabel"] = "Node Type" @@ -196,10 +227,15 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Box Plot of Restore Column Count by Nodes" conf["xlabel"] = "Node Type" @@ -223,18 +259,35 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Boxen Plot of Restore Row Count by Nodes" conf["xlabel"] = "Restore Row Count" conf["ylabel"] = "Nodes" - n1 = int(result.numberNodes * result.class1ratio) - data = [result.restoreRowCount[1: n1], result.restoreRowCount[n1+1: ]] + data = [] + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + _start = 1 + for _range in nodeRanges: + data.append(result.restoreRowCount[_start: _range]) + _start = _range + _values, _categories = [], [] + for _d, _nc in zip(data, nodeClasses): + _values += _d + _categories += [f'Class {_nc}'] * len(_d) + data = pd.DataFrame({ + 'values': _values, + 'category': _categories + }) plt.figure(figsize=(8, 6)) - sns.boxenplot(data=data, width=0.8) + sns.boxenplot(x='category', y='values', hue='category', data=data, palette="Set2", ax=plt.gca(), width=0.8) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -248,18 +301,35 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Boxen Plot of Restore Column Count by Nodes" conf["xlabel"] = "Restore Column Count" conf["ylabel"] = "Nodes" - n1 = int(result.numberNodes * result.class1ratio) - data = [result.restoreColumnCount[1: n1], result.restoreColumnCount[n1+1: ]] + data = [] + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + _start = 1 + for _range in nodeRanges: + data.append(result.restoreColumnCount[_start: _range]) + _start = _range + _values, _categories = [], [] + for _d, _nc in zip(data, nodeClasses): + _values += _d + _categories += [f'Class {_nc}'] * len(_d) + data = pd.DataFrame({ + 'values': _values, + 'category': _categories + }) plt.figure(figsize=(8, 6)) - sns.boxenplot(data=data, width=0.8) + sns.boxenplot(x='category', y='values', hue='category', data=data, palette="Set2", ax=plt.gca(), width=0.8) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -273,19 +343,28 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "ECDF of Restore Row Count by Nodes" conf["xlabel"] = "Restore Row Count" conf["ylabel"] = "ECDF" - n1 = int(result.numberNodes * result.class1ratio) - class1_data = result.restoreRowCount[1: n1] - class2_data = result.restoreRowCount[n1+1: ] - sns.ecdfplot(data=class1_data, label='Class 1 Nodes') - sns.ecdfplot(data=class2_data, label='Class 2 Nodes') + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + start = 1 + labels = [] + for i, rng in enumerate(nodeRanges): + class_data = result.repairedSampleCount[start: rng + 1] + label = f"Class {nodeClasses[i]} Nodes" + labels.append(label) + start = rng + 1 + sns.ecdfplot(data=class_data, label=label) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -293,7 +372,7 @@ class Visualizor: plt.xlim(left=0, right=max_val if max_val > 0 else 1) props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) plt.text(1.05, 0.05, conf["textBox"], fontsize=14, verticalalignment='bottom', transform=plt.gca().transAxes, bbox=props) - plt.legend(title='Node Class', labels=['Class 1 Nodes', 'Class 2 Nodes'], loc=1) + plt.legend(title='Node Class', labels=labels, loc=1) plt.savefig(plotPath + "/ecdf_restoreRowCount.png", bbox_inches="tight") print("Plot %s created." % (plotPath + "/ecdf_restoreRowCount.png")) @@ -302,19 +381,28 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "ECDF of Restore Column Count by Nodes" conf["xlabel"] = "Restore Column Count" conf["ylabel"] = "ECDF" - n1 = int(result.numberNodes * result.class1ratio) - class1_data = result.restoreColumnCount[1: n1] - class2_data = result.restoreColumnCount[n1+1: ] - sns.ecdfplot(data=class1_data, label='Class 1 Nodes') - sns.ecdfplot(data=class2_data, label='Class 2 Nodes') + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + start = 1 + labels = [] + for i, rng in enumerate(nodeRanges): + class_data = result.repairedSampleCount[start: rng + 1] + label = f"Class {nodeClasses[i]} Nodes" + labels.append(label) + start = rng + 1 + sns.ecdfplot(data=class_data, label=label) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -322,7 +410,7 @@ class Visualizor: plt.xlim(left=0, right=max_val if max_val > 0 else 1) props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) plt.text(1.05, 0.05, conf["textBox"], fontsize=14, verticalalignment='bottom', transform=plt.gca().transAxes, bbox=props) - plt.legend(title='Node Class', labels=['Class 1 Nodes', 'Class 2 Nodes'], loc=1) + plt.legend(title='Node Class', labels=labels, loc=1) plt.savefig(plotPath + "/ecdf_restoreColumnCount.png", bbox_inches="tight") print("Plot %s created." % (plotPath + "/ecdf_restoreColumnCount.png")) @@ -331,20 +419,29 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "ECDF of Messages Sent by Nodes" conf["xlabel"] = "Number of Messages Sent" conf["ylabel"] = "ECDF" - n1 = int(result.numberNodes * result.class1ratio) - class1_data = result.msgSentCount[1: n1] - class2_data = result.msgSentCount[n1+1: ] - sns.ecdfplot(data=class1_data, label='Class 1 Nodes') - sns.ecdfplot(data=class2_data, label='Class 2 Nodes') - plt.legend(title='Node Class', labels=['Class 1 Nodes', 'Class 2 Nodes'], loc=1) + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + start = 1 + labels = [] + for i, rng in enumerate(nodeRanges): + class_data = result.msgSentCount[start: rng + 1] + label = f"Class {nodeClasses[i]} Nodes" + labels.append(label) + start = rng + 1 + sns.ecdfplot(data=class_data, label=label) + plt.legend(title='Node Class', labels=labels) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -359,20 +456,29 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "ECDF of Messages Received by Nodes" conf["xlabel"] = "Number of Messages Received" conf["ylabel"] = "ECDF" - n1 = int(result.numberNodes * result.class1ratio) - class1_data = result.msgRecvCount[1: n1] - class2_data = result.msgRecvCount[n1+1: ] - sns.ecdfplot(data=class1_data, label='Class 1 Nodes') - sns.ecdfplot(data=class2_data, label='Class 2 Nodes') - plt.legend(title='Node Class', labels=['Class 1 Nodes', 'Class 2 Nodes'], loc=1) + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + start = 1 + labels = [] + for i, rng in enumerate(nodeRanges): + class_data = result.msgRecvCount[start: rng + 1] + label = f"Class {nodeClasses[i]} Nodes" + labels.append(label) + start = rng + 1 + sns.ecdfplot(data=class_data, label=label) + plt.legend(title='Node Class', labels=labels) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -387,20 +493,29 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "ECDF of Samples Received by Nodes" conf["xlabel"] = "Number of Samples Received" conf["ylabel"] = "ECDF" - n1 = int(result.numberNodes * result.class1ratio) - class1_data = result.sampleRecvCount[1: n1] - class2_data = result.sampleRecvCount[n1+1: ] - sns.ecdfplot(data=class1_data, label='Class 1 Nodes') - sns.ecdfplot(data=class2_data, label='Class 2 Nodes') - plt.legend(title='Node Class', labels=['Class 1 Nodes', 'Class 2 Nodes'], loc=1) + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + start = 1 + labels = [] + for i, rng in enumerate(nodeRanges): + class_data = result.sampleRecvCount[start: rng + 1] + label = f"Class {nodeClasses[i]} Nodes" + labels.append(label) + start = rng + 1 + sns.ecdfplot(data=class_data, label=label) + plt.legend(title='Node Class', labels=labels) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -415,17 +530,21 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "ECDF of Row-Col Distribution by Nodes" conf["xlabel"] = "Row-Col Distribution" conf["ylabel"] = "ECDF" vector1 = result.metrics["rowDist"] vector2 = result.metrics["columnDist"] - n1 = int(result.numberNodes * result.class1ratio) sns.ecdfplot(data=vector1, label='Rows') sns.ecdfplot(data=vector2, label='Columns') plt.xlabel(conf["xlabel"], fontsize=12) @@ -443,20 +562,29 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "ECDF of Samples Repaired by Nodes" conf["xlabel"] = "Number of Samples Repaired" conf["ylabel"] = "ECDF" - n1 = int(result.numberNodes * result.class1ratio) - class1_data = result.repairedSampleCount[1: n1] - class2_data = result.repairedSampleCount[n1+1: ] - sns.ecdfplot(data=class1_data, label='Class 1 Nodes') - sns.ecdfplot(data=class2_data, label='Class 2 Nodes') - plt.legend(title='Node Class', labels=['Class 1 Nodes', 'Class 2 Nodes']) + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + start = 1 + labels = [] + for i, rng in enumerate(nodeRanges): + class_data = result.repairedSampleCount[start: rng + 1] + label = f"Class {nodeClasses[i]} Nodes" + labels.append(label) + start = rng + 1 + sns.ecdfplot(data=class_data, label=label) + plt.legend(title='Node Class', labels=labels) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -471,18 +599,35 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Samples Received by Nodes" conf["xlabel"] = "Node Type" conf["ylabel"] = "Number of Samples Received" - n1 = int(result.numberNodes * result.class1ratio) - data = [result.sampleRecvCount[1: n1], result.sampleRecvCount[n1+1: ]] + data = [] + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + _start = 1 + for _range in nodeRanges: + data.append(result.sampleRecvCount[_start: _range]) + _start = _range + _values, _categories = [], [] + for _d, _nc in zip(data, nodeClasses): + _values += _d + _categories += [f'Class {_nc}'] * len(_d) + data = pd.DataFrame({ + 'values': _values, + 'category': _categories + }) plt.figure(figsize=(8, 6)) - sns.boxenplot(data=data, width=0.8) + sns.boxenplot(x='category', y='values', hue='category', data=data, palette="Set2", ax=plt.gca(), width=0.8) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -498,18 +643,35 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Samples Repaired by Nodes" conf["xlabel"] = "Node Type" conf["ylabel"] = "Number of Samples Repaired" - n1 = int(result.numberNodes * result.class1ratio) - data = [result.repairedSampleCount[1: n1], result.repairedSampleCount[n1+1: ]] + data = [] + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + _start = 1 + for _range in nodeRanges: + data.append(result.repairedSampleCount[_start: _range]) + _start = _range + _values, _categories = [], [] + for _d, _nc in zip(data, nodeClasses): + _values += _d + _categories += [f'Class {_nc}'] * len(_d) + data = pd.DataFrame({ + 'values': _values, + 'category': _categories + }) plt.figure(figsize=(8, 6)) - sns.boxenplot(data=data, width=0.8) + sns.boxenplot(x='category', y='values', hue='category', data=data, width=0.8, palette="Set2", ax=plt.gca()) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -525,10 +687,15 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Row/Column Distribution" conf["xlabel"] = "Row/Column Type" @@ -557,18 +724,34 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Messages Sent by Nodes" conf["xlabel"] = "Node Type" conf["ylabel"] = "Number of Messages Sent" - n1 = int(result.numberNodes * result.class1ratio) - data = [result.msgSentCount[1: n1], result.msgSentCount[n1+1: ]] - labels = ["Class 1", "Class 2"] - sns.boxenplot(data=data, palette="Set2", ax=plt.gca()) + data = [] + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + _start = 1 + for _range in nodeRanges: + data.append(result.msgSentCount[_start: _range]) + _start = _range + _values, _categories = [], [] + for _d, _nc in zip(data, nodeClasses): + _values += _d + _categories += [f'Class {_nc}'] * len(_d) + data = pd.DataFrame({ + 'values': _values, + 'category': _categories + }) + sns.boxenplot(x='category', y='values', hue='category', data=data, width=0.8, palette="Set2", ax=plt.gca()) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -582,18 +765,34 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Messages Received by Nodes" conf["xlabel"] = "Node Type" conf["ylabel"] = "Number of Messages Received" - n1 = int(result.numberNodes * result.class1ratio) - data = [result.msgRecvCount[1: n1], result.msgRecvCount[n1+1: ]] - labels = ["Class 1", "Class 2"] - sns.boxenplot(data=data, palette="Set2", ax=plt.gca()) + data = [] + nodeClasses, nodeRanges = self.__getNodeRanges(result.shape) + _start = 1 + for _range in nodeRanges: + data.append(result.msgRecvCount[_start: _range]) + _start = _range + _values, _categories = [], [] + for _d, _nc in zip(data, nodeClasses): + _values += _d + _categories += [f'Class {_nc}'] * len(_d) + data = pd.DataFrame({ + 'values': _values, + 'category': _categories + }) + sns.boxenplot(x='category', y='values', hue='category', data=data, palette="Set2", ax=plt.gca()) plt.xlabel(conf["xlabel"], fontsize=12) plt.ylabel(conf["ylabel"], fontsize=12) plt.title(conf["title"], fontsize=14) @@ -607,10 +806,15 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Samples Repaired by Nodes" conf["type"] = "individual_bar" @@ -629,10 +833,15 @@ class Visualizor: plt.clf() conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Row/Column Distribution" conf["xlabel"] = "" @@ -653,10 +862,15 @@ class Visualizor: """Plots the restoreRowCount for each node""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Restore Row Count for Each Node" conf["type"] = "individual_bar" @@ -676,10 +890,15 @@ class Visualizor: """Plots the restoreColumnCount for each node""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Restore Column Count for Each Node" conf["type"] = "individual_bar" @@ -699,10 +918,15 @@ class Visualizor: """Plots the percentage sampleRecv for each node""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Percentage of Samples Received by Nodes" conf["type"] = "individual_bar_with_2line" @@ -735,10 +959,15 @@ class Visualizor: """Box Plot of the sampleRecv for each node""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Samples Received by Nodes" conf["type"] = "individual_bar_with_2line" @@ -757,10 +986,15 @@ class Visualizor: """Plots the missing segments in the network""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize)+"\nMissing Segment: "+str(round(min(result.missingVector) * 100 / max(result.missingVector), 3))+"%"\ +"\nMissing Segments: "+str(result.missingVector[-1]) conf["title"] = "Missing Segments" @@ -780,7 +1014,7 @@ class Visualizor: maxi = max(v) conf["yaxismax"] = maxi x = result.shape.nbCols * result.shape.custodyRows + result.shape.nbRows * result.shape.custodyCols - conf["expected_value"] = (result.shape.numberNodes - 1) * (result.shape.class1ratio * result.shape.vpn1 * x + (1 - result.shape.class1ratio) * result.shape.vpn2 * x) + conf["expected_value"] = (result.shape.numberNodes - 1) * x * sum([(_v['w'] * _v['vpn']) for _v in nodeTypes.values()]) / sum([_v['w'] for _v in nodeTypes.values()]) conf["line_label"] = "Total segments to deliver" plotData(conf) print("Plot %s created." % conf["path"]) @@ -792,10 +1026,15 @@ class Visualizor: vector3 = [x * 100 for x in result.metrics["progress"]["samples received"]] conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Nodes/validators ready" conf["type"] = "plot" @@ -814,30 +1053,38 @@ class Visualizor: def plotSentData(self, result, plotPath): """Plots the percentage of nodes ready in the network""" - vector1 = result.metrics["progress"]["TX builder mean"] - vector2 = result.metrics["progress"]["TX class1 mean"] - vector3 = result.metrics["progress"]["TX class2 mean"] - for i in range(len(vector1)): - vector1[i] = (vector1[i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 - vector2[i] = (vector2[i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 - vector3[i] = (vector3[i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 + vectors = { 0: result.metrics["progress"]["TX builder mean"] } + for nc in result.shape.nodeClasses: + if nc != 0: vectors[nc] = result.metrics["progress"][f"TX class{nc} mean"] + for _k in vectors.keys(): + for i in range(len(list(vectors.values())[0])): + vectors[_k][i] = (vectors[_k][i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Sent data" conf["type"] = "plot" conf["legLoc"] = 2 conf["desLoc"] = 2 - conf["colors"] = ["y-", "c-", "m-"] - conf["labels"] = ["Block Builder", "Solo stakers", "Staking pools"] + # conf["colors"] = ["y-", "c-", "m-"] + conf["labels"] = ["Block Builder"] + conf["data"] = [vectors[0]] + for _k, _v in vectors.items(): + if _k != 0: + conf["labels"].append(f"Node Class: {_k}") + conf["data"].append(_v) conf["xlabel"] = "Time (ms)" conf["ylabel"] = "Bandwidth (MBits/s)" - conf["data"] = [vector1, vector2, vector3] - conf["xdots"] = [x*self.config.stepDuration for x in range(len(vector1))] + conf["xdots"] = [x*self.config.stepDuration for x in range(len(list(vectors.values())[0]))] conf["path"] = plotPath+"/sentData.png" maxi = 0 for v in conf["data"]: @@ -849,28 +1096,37 @@ class Visualizor: def plotRecvData(self, result, plotPath): """Plots the percentage of nodes ready in the network""" - vector1 = result.metrics["progress"]["RX class1 mean"] - vector2 = result.metrics["progress"]["RX class2 mean"] - for i in range(len(vector1)): - vector1[i] = (vector1[i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 - vector2[i] = (vector2[i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 + vectors = {} + for nc in result.shape.nodeClasses: + if nc != 0: vectors[nc] = result.metrics["progress"][f"RX class{nc} mean"] + for _k in vectors.keys(): + for i in range(len(list(vectors.values())[0])): + vectors[_k][i] = (vectors[_k][i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Received data" conf["type"] = "plot" conf["legLoc"] = 2 conf["desLoc"] = 2 - conf["colors"] = ["c-", "m-"] - conf["labels"] = ["Solo stakers", "Staking pools"] + # conf["colors"] = ["c-", "m-"] + conf["labels"] = [] + conf["data"] = [] + for _k, _v in vectors.items(): + conf["labels"].append(f"Node Class: {_k}") + conf["data"].append(_v) conf["xlabel"] = "Time (ms)" conf["ylabel"] = "Bandwidth (MBits/s)" - conf["data"] = [vector1, vector2] - conf["xdots"] = [x*self.config.stepDuration for x in range(len(vector1))] + conf["xdots"] = [x*self.config.stepDuration for x in range(len(list(vectors.values())[0]))] conf["path"] = plotPath+"/recvData.png" maxi = 0 for v in conf["data"]: @@ -882,28 +1138,37 @@ class Visualizor: def plotDupData(self, result, plotPath): """Plots the percentage of nodes ready in the network""" - vector1 = result.metrics["progress"]["Dup class1 mean"] - vector2 = result.metrics["progress"]["Dup class2 mean"] - for i in range(len(vector1)): - vector1[i] = (vector1[i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 - vector2[i] = (vector2[i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 + vectors = {} + for nc in result.shape.nodeClasses: + if nc != 0: vectors[nc] = result.metrics["progress"][f"Dup class{nc} mean"] + for _k in vectors.keys(): + for i in range(len(list(vectors.values())[0])): + vectors[_k][i] = (vectors[_k][i] * 8 * (1000/self.config.stepDuration) * self.config.segmentSize) / 1000000 conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Duplicated data" conf["type"] = "plot" conf["legLoc"] = 2 conf["desLoc"] = 2 - conf["colors"] = ["c-", "m-"] - conf["labels"] = ["Solo stakers", "Staking pools"] + # conf["colors"] = ["c-", "m-"] + conf["labels"] = [] + conf["data"] = [] + for _k, _v in vectors.items(): + conf["labels"].append(f"Node Class: {_k}") + conf["data"].append(_v) conf["xlabel"] = "Time (ms)" conf["ylabel"] = "Bandwidth (MBits/s)" - conf["data"] = [vector1, vector2] - conf["xdots"] = [x*self.config.stepDuration for x in range(len(vector1))] + conf["xdots"] = [x*self.config.stepDuration for x in range(len(list(vectors.values())[0]))] conf["path"] = plotPath+"/dupData.png" maxi = 0 for v in conf["data"]: @@ -923,10 +1188,15 @@ class Visualizor: vector1 += [np.nan] * (len(vector2) - len(vector1)) conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Row/Column distribution" conf["type"] = "grouped_bar" @@ -951,10 +1221,15 @@ class Visualizor: """Plots the number of messages sent by all nodes""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Messages Sent by Nodes" conf["type"] = "individual_bar" @@ -974,10 +1249,15 @@ class Visualizor: """Box Plot of the number of messages sent by all nodes""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Messages Sent by Nodes" conf["xlabel"] = "Node Type" @@ -992,10 +1272,15 @@ class Visualizor: """Plots the number of messages received by all nodes""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Messages Received by Nodes" conf["type"] = "individual_bar" @@ -1015,10 +1300,15 @@ class Visualizor: """Plots the number of messages received by all nodes""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Messages Received by Nodes" conf["type"] = "individual_bar" @@ -1039,10 +1329,15 @@ class Visualizor: """Plots the number of samples repaired by all nodes""" conf = {} attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] conf["textBox"] = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNumber of nodes: "+attrbs['nn']+"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"+"\nNetwork degree: "+attrbs['nd']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']+"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2']\ + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"+"\n"+nodeTypesTxt\ +"\nSegment Size: "+str(self.config.segmentSize) conf["title"] = "Number of Samples Repaired by Nodes" conf["type"] = "individual_bar" @@ -1097,11 +1392,16 @@ class Visualizor: xyS = dict() for result in self.results: attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] textBox = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nFailure rate: "+attrbs['fr']+"%"+"\nMalicious Node: "+attrbs['mn']+"%"\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']\ - +"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2'] + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"\ + +"\n"+nodeTypesTxt filename = "bsrn_" + attrbs['bsrn'] +\ "_bsrk_" + attrbs['bsrk'] +\ "_bscn_" + attrbs['bscn' ] +\ @@ -1110,13 +1410,11 @@ class Visualizor: "_mn_" + attrbs['mn'] +\ "_cusr_" + attrbs['cusr'] +\ "_cusc_" + attrbs['cusc'] +\ - "_vpn1_" + attrbs['vpn1'] +\ - "_vpn2_" + attrbs['vpn2'] + "_ntypes_" + attrbs['ntypes'] identifier = ( attrbs['bsrn'], attrbs['bsrk'], attrbs['bscn'], attrbs['bsck'], attrbs['fr'], attrbs['mn'], - attrbs['cusr'], attrbs['cusc'], attrbs['vpn1'], - attrbs['vpn2'] + attrbs['cusr'], attrbs['cusc'], attrbs['ntypes'] ) if identifier in xyS.keys(): xyS[identifier]['x'].append(result.shape.netDegree) @@ -1158,11 +1456,16 @@ class Visualizor: xyS = dict() for result in self.results: attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] textBox = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nFailure rate: "+attrbs['fr']+"%"+"\nNodes: "+attrbs['nn']\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']\ - +"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2'] + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"\ + +"\n"+nodeTypesTxt filename = "bsrn_" + attrbs['bsrn'] +\ "_bsrk_" + attrbs['bsrk'] +\ "_bscn_" + attrbs['bscn' ] +\ @@ -1171,13 +1474,11 @@ class Visualizor: "_fr_" + attrbs['fr'] +\ "_cusr_" + attrbs['cusr'] +\ "_cusc_" + attrbs['cusc'] +\ - "_vpn1_" + attrbs['vpn1'] +\ - "_vpn2_" + attrbs['vpn2'] + "_ntypes_" + attrbs['ntypes'] identifier = ( attrbs['bsrn'], attrbs['bsrk'], attrbs['bscn'], attrbs['bsck'], attrbs['fr'], attrbs['nn'], - attrbs['cusr'], attrbs['cusc'], attrbs['vpn1'], - attrbs['vpn2'] + attrbs['cusr'], attrbs['cusc'], attrbs['ntypes'] ) if identifier in xyS.keys(): xyS[identifier]['x'].append(result.shape.netDegree) @@ -1219,11 +1520,16 @@ class Visualizor: xyS = dict() for result in self.results: attrbs = self.__get_attrbs__(result) + nodeTypes = self.__getNodeTypes__(attrbs['ntypes']) + nodeTypesTxt = "" + for _k, _v in nodeTypes.items(): + nodeTypesTxt += f"Type ({_k}): " + str(_v) + "\n" + if nodeTypesTxt != "": nodeTypesTxt = nodeTypesTxt[: -1] textBox = "Row Size (N, K): "+attrbs['bsrn']+ ", "+attrbs['bsrk']\ +"\nColumn Size: (N, K): "+attrbs['bscn']+ ", "+attrbs['bsck']\ +"\nNodes: "+attrbs['nn']+"\nMalicious Node: "+attrbs['mn']+"%"\ - +"\nCustody Rows: "+attrbs['cusr']+"\nCustody Cols: "+attrbs['cusc']\ - +"\nCustody 1: "+attrbs['vpn1']+"\nCustody 2: "+attrbs['vpn2'] + +"\nCustody Rows: "+attrbs['cusr']+" (Min: "+attrbs['mcusr']+")"+"\nCustody Cols: "+attrbs['cusc']+" (Min: "+attrbs['mcusc']+")"\ + +"\n"+nodeTypesTxt filename = "bsrn_" + attrbs['bsrn'] +\ "_bsrk_" + attrbs['bsrk'] +\ "_bscn_" + attrbs['bscn' ] +\ @@ -1232,13 +1538,11 @@ class Visualizor: "_mn_" + attrbs['mn'] +\ "_cusr_" + attrbs['cusr'] +\ "_cusc_" + attrbs['cusc'] +\ - "_vpn1_" + attrbs['vpn1'] +\ - "_vpn2_" + attrbs['vpn2'] + "_ntypes_" + attrbs['ntypes'] identifier = ( attrbs['bsrn'], attrbs['bsrk'], attrbs['bscn'], attrbs['bsck'], attrbs['mn'], attrbs['nn'], - attrbs['cusr'], attrbs['cusc'], attrbs['vpn1'], - attrbs['vpn2'] + attrbs['cusr'], attrbs['cusc'], attrbs['ntypes'] ) if identifier in xyS.keys(): xyS[identifier]['x'].append(result.shape.netDegree) diff --git a/smallConf.py b/smallConf.py index 18a9c17..df3a546 100644 --- a/smallConf.py +++ b/smallConf.py @@ -76,18 +76,31 @@ proposerPublishToC = "shape.netDegree" validatorBasedCustody = False custodyRows = range(2, 3, 2) custodyCols = range(2, 3, 2) - -# ratio of class1 nodes (see below for parameters per class) -class1ratios = [0.8] - -# Number of validators per beacon node -validatorsPerNode1 = [1] -validatorsPerNode2 = [5] +minCustodyRows = range(2, 3, 2) +minCustodyCols = range(2, 3, 2) # Set uplink bandwidth in megabits/second bwUplinksProd = [200] -bwUplinks1 = [10] -bwUplinks2 = [200] + +nodeTypesGroup = [ + { + "group": "g1", + "classes": { + 1: { + "weight": 70, + "def": {'validatorsPerNode': 1, 'bwUplinks': 10} + }, + 2: { + "weight": 20, + "def": {'validatorsPerNode': 5, 'bwUplinks': 200} + }, + 3: { + "weight": 10, + "def": {'validatorsPerNode': 10, 'bwUplinks': 500} + } + } + } +] # Step duration in miliseconds (Classic RTT is about 100ms) stepDuration = 50 @@ -135,11 +148,11 @@ colsK = range(32, 65, 128) rowsK = range(32, 65, 128) def nextShape(): - for nbCols, nbColsK, nbRows, nbRowsK, run, fm, fr, mn, class1ratio, chR, chC, vpn1, vpn2, nn, netDegree, bwUplinkProd, bwUplink1, bwUplink2 in itertools.product( - cols, colsK, rows, rowsK, runs, failureModels, failureRates, maliciousNodes, class1ratios, custodyRows, custodyCols, validatorsPerNode1, validatorsPerNode2, numberNodes, netDegrees, bwUplinksProd, bwUplinks1, bwUplinks2): + for nbCols, nbColsK, nbRows, nbRowsK, run, fm, fr, mn, chR, chC, minChR, minChC, nn, netDegree, bwUplinkProd, nodeTypes in itertools.product( + cols, colsK, rows, rowsK, runs, failureModels, failureRates, maliciousNodes, custodyRows, custodyCols, minCustodyRows, minCustodyCols, numberNodes, netDegrees, bwUplinksProd, nodeTypesGroup): # Network Degree has to be an even number if netDegree % 2 == 0: - shape = Shape(nbCols, nbColsK, nbRows, nbRowsK, nn, fm, fr, mn, class1ratio, chR, chC, vpn1, vpn2, netDegree, bwUplinkProd, bwUplink1, bwUplink2, run) + shape = Shape(nbCols, nbColsK, nbRows, nbRowsK, nn, fm, fr, mn, chR, chC, minChR, minChC, netDegree, bwUplinkProd, run, nodeTypes) yield shape def evalConf(self, param, shape = None): diff --git a/study.py b/study.py index a824e66..0e47a77 100644 --- a/study.py +++ b/study.py @@ -213,11 +213,11 @@ def study(): logger.info("A total of %d simulations ran in %d seconds" % (len(results), end-start), extra=format) if config.visualization: - vis = Visualizer(execID, config) - vis.plotHeatmaps() + # vis = Visualizer(execID, config) + # vis.plotHeatmaps() visual = Visualizor(execID, config, results) - visual.plotHeatmaps("nn", "fr") + # visual.plotHeatmaps("nn", "fr") visual.plotAllHeatMaps() if __name__ == "__main__":