From 0e51082f71aa14ebca2dec409dc946fcc002bece Mon Sep 17 00:00:00 2001 From: Sudipta Basak Date: Mon, 10 Jun 2024 07:07:14 +0000 Subject: [PATCH] Changed nodeType configuration structure --- DAS/node.py | 2 +- DAS/shape.py | 2 +- DAS/simulator.py | 4 ++-- DAS/visualizor.py | 26 ++++++++++++-------------- smallConf.py | 17 ++++++++++++++--- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/DAS/node.py b/DAS/node.py index 1787af3..40e8dce 100644 --- a/DAS/node.py +++ b/DAS/node.py @@ -121,7 +121,7 @@ class Node: if self.amIproposer: self.bwUplink = shape.bwUplinkProd else: - self.bwUplink = shape.nodeTypes[self.nodeClass]['bwUplinks'] + 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/shape.py b/DAS/shape.py index dea8b7a..02ec6a7 100644 --- a/DAS/shape.py +++ b/DAS/shape.py @@ -19,7 +19,7 @@ class Shape: self.custodyCols = custodyCols self.bwUplinkProd = bwUplinkProd self.nodeTypes = nodeTypes - self.nodeClasses = [0] + [_k for _k in nodeTypes.keys() if _k != "group"] + self.nodeClasses = [0] + [_k for _k in nodeTypes["classes"].keys()] self.randomSeed = "" def __repr__(self): diff --git a/DAS/simulator.py b/DAS/simulator.py index b801e77..afbf418 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -45,7 +45,7 @@ class Simulator: self.proposerPublishToC = config.evalConf(self, config.proposerPublishToR, shape) def getNodeClass(self, nodeIdx): - nodeRatios = [_v['ratio'] for _k, _v in self.shape.nodeTypes.items() if _k != "group"] + 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 @@ -135,7 +135,7 @@ class Simulator: vs = [] nodeClass = self.getNodeClass(i) - vpn = self.shape.nodeTypes[nodeClass]['validatorsPerNode'] + 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), nodeClass, amImalicious_value, self.logger, self.shape, self.config, vs) diff --git a/DAS/visualizor.py b/DAS/visualizor.py index 83c96ab..6fde77d 100644 --- a/DAS/visualizor.py +++ b/DAS/visualizor.py @@ -22,7 +22,7 @@ def plotData(conf): 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"]) @@ -69,23 +69,21 @@ class Visualizor: theGroup = dict() for nt in self.config.nodeTypesGroup: if nt['group'] == group: - for _k, _v in nt.items(): - if _k != 'group': - theGroup[_k] = { - "vpn": _v["validatorsPerNode"], - "bw": _v["bwUplinks"], - "r": _v["ratio"] - } + 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.items(): - if _k != "group": - nodeClasses.append(_k) - nodeRatios.append(_v['ratio']) + 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 @@ -993,7 +991,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) * x * sum([(_v['r'] * _v['vpn']) for _v in nodeTypes.values()]) / sum([_v['r'] for _v in nodeTypes.values()]) + 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"]) @@ -1362,7 +1360,7 @@ class Visualizor: rs = [] for result in self.results: attrbs = self.__get_attrbs__(result) - rs.append(int(attrbs['r'])) + rs.append(int(attrbs['w'])) return max(rs) - min(rs) + 1 diff --git a/smallConf.py b/smallConf.py index 87334dd..c5c497a 100644 --- a/smallConf.py +++ b/smallConf.py @@ -83,9 +83,20 @@ bwUplinksProd = [200] nodeTypesGroup = [ { "group": "g1", - # nodeClass: node config - 1: {'validatorsPerNode': 1, 'bwUplinks': 10, 'ratio': 8}, - 2: {'validatorsPerNode': 5, 'bwUplinks': 200, 'ratio': 2} + "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} + } + } } ]