From 4a4f02427c640dcdcaea046736d0161280ecb7d3 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Fri, 24 Feb 2023 19:08:41 +0100 Subject: [PATCH] change config language to simple (or complex) code Signed-off-by: Csaba Kiraly --- config_example.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ study.py | 32 +++++++++++----------------- 2 files changed, 65 insertions(+), 20 deletions(-) create mode 100644 config_example.py diff --git a/config_example.py b/config_example.py new file mode 100644 index 0000000..0ac65ad --- /dev/null +++ b/config_example.py @@ -0,0 +1,53 @@ +"""Example configuration file + +This file illustrates how to define options and simulation parameter ranges. +It also defines the traversal order of the simulation space. As the file +extension suggests, configuration is pure python code, allowing complex +setups. Use at your own risk. + +To use this example, run + python3 study.py config_example + +Otherwise copy it and modify as needed. The default traversal order defined +in the nested loop of nextShape() is good for most cases, but customizable +if needed. +""" + +import logging +from DAS.shape import Shape + +dumpXML = 1 +visualization = 1 +logLevel = logging.INFO + +# Number of simulation runs with the same parameters for statistical relevance +runs = range(10) + +# Number of validators +numberValidators = range(256, 513, 128) + +# Percentage of block not released by producer +failureRates = range(10, 91, 40) + +# Block size in one dimension in segments. Block is blockSizes * blockSizes segments. +blockSizes = range(32,65,16) + +# Per-topic mesh neighborhood size +netDegrees = range(6, 9, 2) + +# number of rows and columns a validator is interested in +chis = range(4, 9, 2) + +deterministic = False + +def nextShape(): + for run in runs: + for fr in failureRates: + for chi in chis: + for blockSize in blockSizes: + for nv in numberValidators: + for netDegree in netDegrees: + # Network Degree has to be an even number + if netDegree % 2 == 0: + shape = Shape(blockSize, nv, fr, chi, netDegree, run) + yield shape diff --git a/study.py b/study.py index 028d327..20c1475 100644 --- a/study.py +++ b/study.py @@ -1,6 +1,7 @@ #! /bin/python3 import time, sys, random, copy +import importlib from DAS import * @@ -9,7 +10,7 @@ def study(): print("You need to pass a configuration file in parameter") exit(1) - config = Configuration(sys.argv[1]) + config = importlib.import_module(sys.argv[1]) shape = Shape(0, 0, 0, 0, 0, 0) sim = Simulator(shape, config) sim.initLogger() @@ -22,26 +23,17 @@ def study(): sim.logger.info("Starting simulations:", extra=sim.format) start = time.time() - for run in range(config.numberRuns): - for nv in range(config.nvStart, config.nvStop+1, config.nvStep): - for blockSize in range(config.blockSizeStart, config.blockSizeStop+1, config.blockSizeStep): - for fr in range(config.failureRateStart, config.failureRateStop+1, config.failureRateStep): - for netDegree in range(config.netDegreeStart, config.netDegreeStop+1, config.netDegreeStep): - for chi in range(config.chiStart, config.chiStop+1, config.chiStep): + for shape in config.nextShape(): + if not config.deterministic: + random.seed(datetime.now()) - if not config.deterministic: - random.seed(datetime.now()) - - # Network Degree has to be an even number - if netDegree % 2 == 0: - shape = Shape(blockSize, nv, fr, chi, netDegree, run) - 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) - results.append(copy.deepcopy(result)) - simCnt += 1 + 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) + 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)