From d20d8c7c3cfa20cd16a2bdc1e0234fbce339416a Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Tue, 21 Mar 2023 15:12:38 +0100 Subject: [PATCH] add per-run progress plots Signed-off-by: Csaba Kiraly --- DAS/simulator.py | 17 ++++++++++++----- config_example.py | 1 + config_scenario1.py | 1 + study.py | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/DAS/simulator.py b/DAS/simulator.py index cfdae4d..961f1df 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -14,7 +14,7 @@ from DAS.validator import * class Simulator: """This class implements the main DAS simulator.""" - def __init__(self, shape, config): + def __init__(self, shape, config, execID): """It initializes the simulation with a set of parameters (shape).""" self.shape = shape self.config = config @@ -25,6 +25,7 @@ class Simulator: self.logLevel = config.logLevel self.proposerID = 0 self.glob = [] + self.execID = execID # In GossipSub the initiator might push messages without participating in the mesh. # proposerPublishOnly regulates this behavior. If set to true, the proposer is not @@ -217,10 +218,16 @@ class Simulator: else: steps += 1 - progress = pd.DataFrame(progressVector) - progress.plot.line(subplots = [[cnS, cnN, cnV], [cnT0], [cnT1, cnR1, cnD1], [cnT2, cnR2, cnD2]], - title = str(self.shape)) - matplotlib.pyplot.pause(30) + if self.config.plotProgress: + progress = pd.DataFrame(progressVector) + progress.plot.line(subplots = [[cnS, cnN, cnV], [cnT0], [cnT1, cnR1, cnD1], [cnT2, cnR2, cnD2]], + title = str(self.shape)) + if not os.path.exists("results"): + os.makedirs("results") + if not os.path.exists("results/"+self.execID): + os.makedirs("results/"+self.execID) + filePath = "results/"+self.execID+"/"+str(self.shape)+".png" + matplotlib.pyplot.savefig(filePath) self.result.populate(self.shape, missingVector) self.result.addMetric("trafficStats", trafficStatsVector) diff --git a/config_example.py b/config_example.py index b54dff1..0b179ad 100644 --- a/config_example.py +++ b/config_example.py @@ -19,6 +19,7 @@ import numpy as np from DAS.shape import Shape dumpXML = 1 +plotProgress = 1 visualization = 1 logLevel = logging.INFO diff --git a/config_scenario1.py b/config_scenario1.py index 14432d5..24f8db9 100644 --- a/config_scenario1.py +++ b/config_scenario1.py @@ -9,6 +9,7 @@ import numpy as np from DAS.shape import Shape dumpXML = 1 +plotProgress = 1 visualization = 1 logLevel = logging.INFO diff --git a/study.py b/study.py index fde8099..aa27a5f 100644 --- a/study.py +++ b/study.py @@ -28,7 +28,7 @@ def runOnce(config, shape, execID): shape.setSeed(config.randomSeed+"-"+str(shape)) random.seed(shape.randomSeed) - sim = Simulator(shape, config) + sim = Simulator(shape, config, execID) sim.initLogger() sim.initValidators() sim.initNetwork()