change config language to simple (or complex) code
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
37ff89bd82
commit
4a4f02427c
|
@ -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
|
32
study.py
32
study.py
|
@ -1,6 +1,7 @@
|
||||||
#! /bin/python3
|
#! /bin/python3
|
||||||
|
|
||||||
import time, sys, random, copy
|
import time, sys, random, copy
|
||||||
|
import importlib
|
||||||
from DAS import *
|
from DAS import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ def study():
|
||||||
print("You need to pass a configuration file in parameter")
|
print("You need to pass a configuration file in parameter")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
config = Configuration(sys.argv[1])
|
config = importlib.import_module(sys.argv[1])
|
||||||
shape = Shape(0, 0, 0, 0, 0, 0)
|
shape = Shape(0, 0, 0, 0, 0, 0)
|
||||||
sim = Simulator(shape, config)
|
sim = Simulator(shape, config)
|
||||||
sim.initLogger()
|
sim.initLogger()
|
||||||
|
@ -22,26 +23,17 @@ def study():
|
||||||
sim.logger.info("Starting simulations:", extra=sim.format)
|
sim.logger.info("Starting simulations:", extra=sim.format)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
for run in range(config.numberRuns):
|
for shape in config.nextShape():
|
||||||
for nv in range(config.nvStart, config.nvStop+1, config.nvStep):
|
if not config.deterministic:
|
||||||
for blockSize in range(config.blockSizeStart, config.blockSizeStop+1, config.blockSizeStep):
|
random.seed(datetime.now())
|
||||||
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):
|
|
||||||
|
|
||||||
if not config.deterministic:
|
sim.resetShape(shape)
|
||||||
random.seed(datetime.now())
|
sim.initValidators()
|
||||||
|
sim.initNetwork()
|
||||||
# Network Degree has to be an even number
|
result = sim.run()
|
||||||
if netDegree % 2 == 0:
|
sim.logger.info("Shape: %s ... Block Available: %d in %d steps" % (str(sim.shape.__dict__), result.blockAvailable, len(result.missingVector)), extra=sim.format)
|
||||||
shape = Shape(blockSize, nv, fr, chi, netDegree, run)
|
results.append(copy.deepcopy(result))
|
||||||
sim.resetShape(shape)
|
simCnt += 1
|
||||||
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()
|
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" % (simCnt, end-start), extra=sim.format)
|
||||||
|
|
Loading…
Reference in New Issue