From 731331046cf2c825fbb0c6c2242bef96addd40bf Mon Sep 17 00:00:00 2001 From: leobago Date: Sun, 11 Jun 2023 18:46:55 +0200 Subject: [PATCH 1/7] Better order for the plots --- DAS/visualizor.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/DAS/visualizor.py b/DAS/visualizor.py index b3147f2..acecbc6 100644 --- a/DAS/visualizor.py +++ b/DAS/visualizor.py @@ -38,14 +38,16 @@ class Visualizor: def plotAll(self): """Plot all the important elements of each result""" for result in self.results: - self.plotMissingSamples(result) - self.plotProgress(result) - self.plotSentData(result) - self.plotRecvData(result) - self.plotDupData(result) - self.plotRowCol(result) + plotPath = "results/"+self.execID+"/plots/"+str(result.shape) + os.makedirs(plotPath, exist_ok=True) + self.plotMissingSamples(result, plotPath) + self.plotProgress(result, plotPath) + self.plotSentData(result, plotPath) + self.plotRecvData(result, plotPath) + self.plotDupData(result, plotPath) + self.plotRowCol(result, plotPath) - def plotMissingSamples(self, result): + def plotMissingSamples(self, result, plotPath): """Plots the missing samples in the network""" conf = {} text = str(result.shape).split("-") @@ -61,7 +63,7 @@ class Visualizor: conf["ylabel"] = "Number of Missing Samples" conf["data"] = [result.missingVector] conf["xdots"] = [x*self.config.stepDuration for x in range(len(result.missingVector))] - conf["path"] = "results/"+self.execID+"/plots/missingSamples-"+str(result.shape)+".png" + conf["path"] = plotPath+"/missingSamples.png" maxi = 0 for v in conf["data"]: if max(v) > maxi: @@ -70,7 +72,7 @@ class Visualizor: plotData(conf) print("Plot %s created." % conf["path"]) - def plotProgress(self, result): + def plotProgress(self, result, plotPath): """Plots the percentage of nodes ready in the network""" vector1 = result.metrics["progress"]["nodes ready"] vector2 = result.metrics["progress"]["validators ready"] @@ -89,7 +91,7 @@ class Visualizor: conf["ylabel"] = "Percentage (%)" conf["data"] = [vector1, vector2, vector3] conf["xdots"] = [x*self.config.stepDuration for x in range(len(vector1))] - conf["path"] = "results/"+self.execID+"/plots/nodesReady-"+str(result.shape)+".png" + conf["path"] = plotPath+"/nodesReady.png" maxi = 0 for v in conf["data"]: if max(v) > maxi: @@ -98,7 +100,7 @@ class Visualizor: plotData(conf) print("Plot %s created." % conf["path"]) - def plotSentData(self, result): + 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"] @@ -121,7 +123,7 @@ class Visualizor: conf["ylabel"] = "Bandwidth (MBits/s)" conf["data"] = [vector1, vector2, vector3] conf["xdots"] = [x*self.config.stepDuration for x in range(len(vector1))] - conf["path"] = "results/"+self.execID+"/plots/sentData-"+str(result.shape)+".png" + conf["path"] = plotPath+"/sentData.png" maxi = 0 for v in conf["data"]: if max(v) > maxi: @@ -130,7 +132,7 @@ class Visualizor: plotData(conf) print("Plot %s created." % conf["path"]) - def plotRecvData(self, result): + 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"] @@ -151,7 +153,7 @@ class Visualizor: conf["ylabel"] = "Bandwidth (MBits/s)" conf["data"] = [vector1, vector2] conf["xdots"] = [x*self.config.stepDuration for x in range(len(vector1))] - conf["path"] = "results/"+self.execID+"/plots/recvData-"+str(result.shape)+".png" + conf["path"] = plotPath+"/recvData.png" maxi = 0 for v in conf["data"]: if max(v) > maxi: @@ -160,7 +162,7 @@ class Visualizor: plotData(conf) print("Plot %s created." % conf["path"]) - def plotDupData(self, result): + 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"] @@ -181,7 +183,7 @@ class Visualizor: conf["ylabel"] = "Bandwidth (MBits/s)" conf["data"] = [vector1, vector2] conf["xdots"] = [x*self.config.stepDuration for x in range(len(vector1))] - conf["path"] = "results/"+self.execID+"/plots/dupData-"+str(result.shape)+".png" + conf["path"] = plotPath+"/dupData.png" maxi = 0 for v in conf["data"]: if max(v) > maxi: @@ -190,7 +192,7 @@ class Visualizor: plotData(conf) print("Plot %s created." % conf["path"]) - def plotRowCol(self, result): + def plotRowCol(self, result, plotPath): """Plots the percentage of nodes ready in the network""" vector1 = result.metrics["rowDist"] vector2 = result.metrics["columnDist"] @@ -208,7 +210,7 @@ class Visualizor: conf["ylabel"] = "Validators subscribed" conf["data"] = [vector1, vector2] conf["xdots"] = range(len(vector1)) - conf["path"] = "results/"+self.execID+"/plots/RowColDist-"+str(result.shape)+".png" + conf["path"] = plotPath+"/RowColDist.png" maxi = 0 for v in conf["data"]: if max(v) > maxi: From 8a24e4f88e25fbe36e96d6fcfee362193d513099 Mon Sep 17 00:00:00 2001 From: leobago Date: Sun, 11 Jun 2023 19:26:44 +0200 Subject: [PATCH 2/7] heatmap plotting WIP --- DAS/visualizor.py | 26 ++++++++++++++++++++++++++ study.py | 1 + 2 files changed, 27 insertions(+) diff --git a/DAS/visualizor.py b/DAS/visualizor.py index acecbc6..ad9d31b 100644 --- a/DAS/visualizor.py +++ b/DAS/visualizor.py @@ -35,6 +35,32 @@ class Visualizor: self.results = results os.makedirs("results/"+self.execID+"/plots", exist_ok=True) + def plotHeatmaps(self, x, y): + """Plot the heatmap using the parameters given as x axis and y axis""" + print("Plotting heatmap "+x+" vs "+y) + #Find the location of x in shape + #Find the location of y in shape + #Find the location od r in shape + + #Loop over all results + #Add unique values foir every parameter + + #Find number of runs from r + #If number of values for x and y > 3 then plot heatmap, otherwise finish + + #Create a 2D grid with the dimensions of the number of values for x and y + #For all values of x + #For all values of y + # For all values in r + #Fixing all other values to 1 (in the mean time) + #Add/sum TTA into 2D grid + #if last r divide by number of runs + + #Plot 2D grid + + + + def plotAll(self): """Plot all the important elements of each result""" for result in self.results: diff --git a/study.py b/study.py index fff5205..8d069ad 100644 --- a/study.py +++ b/study.py @@ -89,6 +89,7 @@ def study(): visual = Visualizor(execID, config, results) visual.plotAll() + visual.plotHeatmaps("nn", "fr") if __name__ == "__main__": study() From 562ef5122f8c88a2c4c8c785ad33d0be7e5eb749 Mon Sep 17 00:00:00 2001 From: leobago Date: Sun, 11 Jun 2023 19:30:10 +0200 Subject: [PATCH 3/7] More output --- DAS/simulator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DAS/simulator.py b/DAS/simulator.py index b46a340..147d499 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -257,7 +257,7 @@ class Simulator: trafficStatsVector.append(trafficStats) missingSamples, sampleProgress, nodeProgress, validatorAllProgress, validatorProgress = self.glob.getProgress(self.validators) - self.logger.debug("step %d, arrived %0.02f %%, ready %0.02f %%, validatedall %0.02f %%, , validated %0.02f %%" + self.logger.info("step %d, arrived %0.02f %%, ready %0.02f %%, validatedall %0.02f %%, , validated %0.02f %%" % (steps, sampleProgress*100, nodeProgress*100, validatorAllProgress*100, validatorProgress*100), extra=self.format) cnS = "samples received" From 0dfbace655808450dbd100e6618efe43a9607af3 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Wed, 12 Jul 2023 21:15:08 +0200 Subject: [PATCH 4/7] fix heatmap when spacing in not equal Histogram2d was binning data, even if axes values were not on a linear scale, creating some strange figures. We do not need the binning here. Signed-off-by: Csaba Kiraly --- DAS/visualizer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DAS/visualizer.py b/DAS/visualizer.py index cf095c1..ec22cb7 100644 --- a/DAS/visualizer.py +++ b/DAS/visualizer.py @@ -4,6 +4,7 @@ import time import xml.etree.ElementTree as ET import matplotlib.pyplot as plt import numpy as np +import pandas as pd import seaborn as sns from itertools import combinations from mplfinance.original_flavor import candlestick_ohlc @@ -197,10 +198,9 @@ class Visualizer: ylabels = np.sort(np.unique(data[key][labels[1]])) if len(xlabels) < self.minimumDataPoints or len(ylabels) < self.minimumDataPoints: continue - hist, xedges, yedges = np.histogram2d(data[key][labels[0]], data[key][labels[1]], bins=(len(xlabels), len(ylabels)), weights=data[key]['ttas']) - hist = hist.T + df = pd.DataFrame.from_dict(data[key]).pivot(labels[0], labels[1], 'ttas') fig, ax = plt.subplots(figsize=(10, 6)) - sns.heatmap(hist, xticklabels=xlabels, yticklabels=ylabels, cmap='hot_r', cbar_kws={'label': 'Time to block availability (ms)'}, linecolor='black', linewidths=0.3, annot=True, fmt=".2f", ax=ax, vmin=vmin, vmax=vmax) + sns.heatmap(df, cmap='hot_r', cbar_kws={'label': 'Time to block availability (ms)'}, linecolor='black', linewidths=0.3, annot=True, fmt=".2f", ax=ax) #vmin=vmin, vmax=vmax plt.xlabel(self.formatLabel(labels[0])) plt.ylabel(self.formatLabel(labels[1])) filename = "" From b427cf93c0fb21fc864d9662a8092c8a25258b73 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Wed, 12 Jul 2023 21:28:21 +0200 Subject: [PATCH 5/7] plot figures right after simulation run This allows to observe partial results during long studies. Signed-off-by: Csaba Kiraly --- study.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/study.py b/study.py index 8d069ad..380cf30 100644 --- a/study.py +++ b/study.py @@ -39,6 +39,10 @@ def runOnce(config, shape, execID): if config.dumpXML: result.dump() + if config.visualization: + visual = Visualizor(execID, config, [result]) + visual.plotAll() + return result def study(): @@ -88,7 +92,6 @@ def study(): vis.plotHeatmaps() visual = Visualizor(execID, config, results) - visual.plotAll() visual.plotHeatmaps("nn", "fr") if __name__ == "__main__": From 866229f8e8599f07f033173274e44653b35fa62b Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Thu, 13 Jul 2023 09:30:07 +0000 Subject: [PATCH 6/7] fixup: df.pivot needs parameter names --- DAS/visualizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DAS/visualizer.py b/DAS/visualizer.py index ec22cb7..02bb432 100644 --- a/DAS/visualizer.py +++ b/DAS/visualizer.py @@ -198,7 +198,7 @@ class Visualizer: ylabels = np.sort(np.unique(data[key][labels[1]])) if len(xlabels) < self.minimumDataPoints or len(ylabels) < self.minimumDataPoints: continue - df = pd.DataFrame.from_dict(data[key]).pivot(labels[0], labels[1], 'ttas') + df = pd.DataFrame.from_dict(data[key]).pivot(columns=labels[0], index=labels[1], values='ttas') fig, ax = plt.subplots(figsize=(10, 6)) sns.heatmap(df, cmap='hot_r', cbar_kws={'label': 'Time to block availability (ms)'}, linecolor='black', linewidths=0.3, annot=True, fmt=".2f", ax=ax) #vmin=vmin, vmax=vmax plt.xlabel(self.formatLabel(labels[0])) From 4f5205e2479af0886a46870d587cf7566d952120 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Sat, 15 Jul 2023 12:20:13 +0000 Subject: [PATCH 7/7] plot RCdist only if saveRCdist --- DAS/visualizor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DAS/visualizor.py b/DAS/visualizor.py index ad9d31b..cb3c5d9 100644 --- a/DAS/visualizor.py +++ b/DAS/visualizor.py @@ -71,7 +71,8 @@ class Visualizor: self.plotSentData(result, plotPath) self.plotRecvData(result, plotPath) self.plotDupData(result, plotPath) - self.plotRowCol(result, plotPath) + if self.config.saveRCdist: + self.plotRowCol(result, plotPath) def plotMissingSamples(self, result, plotPath): """Plots the missing samples in the network"""