From 0b6cfad9675d3e2b12d1b379f750610ab6a61d74 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Fri, 3 Mar 2023 11:02:07 +0100 Subject: [PATCH] factorize study code Signed-off-by: Csaba Kiraly --- study.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/study.py b/study.py index 52433c5..2823fa1 100644 --- a/study.py +++ b/study.py @@ -4,6 +4,16 @@ import time, sys, random, copy import importlib from DAS import * +def runOnce(sim, config, shape): + if not config.deterministic: + random.seed(datetime.now()) + + sim.resetShape(shape) + sim.initValidators() + sim.initNetwork() + result = sim.run() + sim.logger.info("Shape: %s ... Block Available: %d in %d steps" % (str(sim.shape.__dict__), result.blockAvailable, len(result.missingVector)), extra=sim.format) + return result def study(): if len(sys.argv) < 2: @@ -24,7 +34,6 @@ def study(): sim = Simulator(shape, config) sim.initLogger() results = [] - simCnt = 0 now = datetime.now() execID = now.strftime("%Y-%m-%d_%H-%M-%S_")+str(random.randint(100,999)) @@ -33,19 +42,11 @@ def study(): start = time.time() for shape in config.nextShape(): - if not config.deterministic: - random.seed(datetime.now()) - - sim.resetShape(shape) - sim.initValidators() - sim.initNetwork() - result = sim.run() - sim.logger.info("Shape: %s ... Block Available: %d in %d steps" % (str(sim.shape.__dict__), result.blockAvailable, len(result.missingVector)), extra=sim.format) + result = runOnce(sim, config, shape) results.append(copy.deepcopy(result)) - simCnt += 1 end = time.time() - sim.logger.info("A total of %d simulations ran in %d seconds" % (simCnt, end-start), extra=sim.format) + sim.logger.info("A total of %d simulations ran in %d seconds" % (len(results), end-start), extra=sim.format) if config.dumpXML: for res in results: