From dc51727b329ede185e7008e6d5a0f88b4e611025 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Mon, 27 Mar 2023 23:16:05 +0200 Subject: [PATCH] plot progress per run Signed-off-by: Csaba Kiraly --- DAS/simulator.py | 14 +++++++++++++- config_example.py | 4 ++++ study.py | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/DAS/simulator.py b/DAS/simulator.py index 677a260..c2f4654 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -3,6 +3,7 @@ import networkx as nx import logging, random import pandas as pd +import matplotlib from functools import partial, partialmethod from datetime import datetime from DAS.tools import * @@ -13,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 @@ -24,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 @@ -240,6 +242,16 @@ class Simulator: progress = pd.DataFrame(progressVector) if self.config.saveProgress: self.result.addMetric("progress", progress.to_dict(orient='list')) + if self.config.plotProgress: + 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) return self.result diff --git a/config_example.py b/config_example.py index 5b1a396..461ee36 100644 --- a/config_example.py +++ b/config_example.py @@ -22,6 +22,10 @@ dumpXML = 1 # save progress vectors to XML saveProgress = 1 + +# plot progress for each run to PNG +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()