mirror of
https://github.com/status-im/das-research.git
synced 2025-02-23 03:48:22 +00:00
commit
fa2ebccee5
@ -1,4 +1,3 @@
|
|||||||
from DAS.simulator import *
|
from DAS.simulator import *
|
||||||
from DAS.configuration import *
|
|
||||||
from DAS.shape import *
|
from DAS.shape import *
|
||||||
from DAS.visualizer import *
|
from DAS.visualizer import *
|
||||||
|
@ -1,85 +0,0 @@
|
|||||||
#!/bin/python3
|
|
||||||
|
|
||||||
import configparser, logging, sys
|
|
||||||
|
|
||||||
class Configuration:
|
|
||||||
"""This class stores all the configuration parameters for the given run."""
|
|
||||||
|
|
||||||
def __init__(self, fileName):
|
|
||||||
"""It initializes the configuration based on the given configuration."""
|
|
||||||
|
|
||||||
config = configparser.RawConfigParser()
|
|
||||||
config.read(fileName)
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.nvStart = int(config.get("Simulation Space", "numberValidatorStart"))
|
|
||||||
self.nvStop = int(config.get("Simulation Space", "numberValidatorStop"))
|
|
||||||
self.nvStep = int(config.get("Simulation Space", "numberValidatorStep"))
|
|
||||||
|
|
||||||
self.blockSizeStart = int(config.get("Simulation Space", "blockSizeStart"))
|
|
||||||
self.blockSizeStop = int(config.get("Simulation Space", "blockSizeStop"))
|
|
||||||
self.blockSizeStep = int(config.get("Simulation Space", "blockSizeStep"))
|
|
||||||
|
|
||||||
self.netDegreeStart = int(config.get("Simulation Space", "netDegreeStart"))
|
|
||||||
self.netDegreeStop = int(config.get("Simulation Space", "netDegreeStop"))
|
|
||||||
self.netDegreeStep = int(config.get("Simulation Space", "netDegreeStep"))
|
|
||||||
|
|
||||||
self.failureRateStart = int(config.get("Simulation Space", "failureRateStart"))
|
|
||||||
self.failureRateStop = int(config.get("Simulation Space", "failureRateStop"))
|
|
||||||
self.failureRateStep = int(config.get("Simulation Space", "failureRateStep"))
|
|
||||||
|
|
||||||
self.chiStart = int(config.get("Simulation Space", "chiStart"))
|
|
||||||
self.chiStop = int(config.get("Simulation Space", "chiStop"))
|
|
||||||
self.chiStep = int(config.get("Simulation Space", "chiStep"))
|
|
||||||
except:
|
|
||||||
sys.exit("Configuration Error: It seems some of the [Simulation Space] parameters are missing. Cannot continue :( ")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.numberRuns = int(config.get("Advanced", "numberRuns"))
|
|
||||||
self.deterministic = config.get("Advanced", "deterministic")
|
|
||||||
self.dumpXML = config.get("Advanced", "dumpXML")
|
|
||||||
self.logLevel = config.get("Advanced", "logLevel")
|
|
||||||
self.visualization = config.get("Advanced", "visualization")
|
|
||||||
except:
|
|
||||||
sys.exit("Configuration Error: It seems some of the [Advanced] parameters are missing. Cannot continue :( ")
|
|
||||||
self.test()
|
|
||||||
|
|
||||||
def test(self):
|
|
||||||
|
|
||||||
print("Testing configuration...")
|
|
||||||
if self.logLevel == "INFO":
|
|
||||||
self.logLevel = logging.INFO
|
|
||||||
elif self.logLevel == "DEBUG":
|
|
||||||
self.logLevel = logging.DEBUG
|
|
||||||
else:
|
|
||||||
self.logLevel = logging.INFO
|
|
||||||
|
|
||||||
if self.nvStart >= self.nvStop:
|
|
||||||
sys.exit("Configuration Error: numberValidatorStart has to be smaller than numberValidatorStop")
|
|
||||||
|
|
||||||
if self.failureRateStart >= self.failureRateStop:
|
|
||||||
sys.exit("Configuration Error: failureRateStart has to be smaller than failureRateStop")
|
|
||||||
|
|
||||||
if self.blockSizeStart >= self.blockSizeStop:
|
|
||||||
sys.exit("Configuration Error: blockSizeStart has to be smaller than blockSizeStop")
|
|
||||||
|
|
||||||
if self.netDegreeStart >= self.netDegreeStop:
|
|
||||||
sys.exit("Configuration Error: netDegreeStart has to be smaller than netDegreeStop")
|
|
||||||
|
|
||||||
if self.chiStart >= self.chiStop:
|
|
||||||
sys.exit("Configuration Error: chiStart has to be smaller than chiStop")
|
|
||||||
|
|
||||||
|
|
||||||
if self.nvStart < self.blockSizeStop:
|
|
||||||
sys.exit("Configuration Error: numberValidatorStart hast to be larger than blockSizeStop.")
|
|
||||||
|
|
||||||
if self.chiStart < 2:
|
|
||||||
sys.exit("Configuration Error: Chi has to be greater than 1.")
|
|
||||||
|
|
||||||
if self.chiStop > self.blockSizeStart:
|
|
||||||
sys.exit("Configuration Error: Chi (%d) has to be smaller or equal to block the size (%d)" % (self.chiStop, self.blockSizeStart))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
30
config.ini
30
config.ini
@ -1,30 +0,0 @@
|
|||||||
[Simulation Space]
|
|
||||||
|
|
||||||
numberValidatorStart = 256
|
|
||||||
numberValidatorStop = 512
|
|
||||||
numberValidatorStep = 128
|
|
||||||
|
|
||||||
failureRateStart = 10
|
|
||||||
failureRateStop = 90
|
|
||||||
failureRateStep = 40
|
|
||||||
|
|
||||||
blockSizeStart = 32
|
|
||||||
blockSizeStop = 64
|
|
||||||
blockSizeStep = 16
|
|
||||||
|
|
||||||
netDegreeStart = 6
|
|
||||||
netDegreeStop = 8
|
|
||||||
netDegreeStep = 2
|
|
||||||
|
|
||||||
chiStart = 4
|
|
||||||
chiStop = 8
|
|
||||||
chiStep = 2
|
|
||||||
|
|
||||||
|
|
||||||
[Advanced]
|
|
||||||
|
|
||||||
deterministic = 0
|
|
||||||
numberRuns = 2
|
|
||||||
dumpXML = 1
|
|
||||||
visualization = 1
|
|
||||||
logLevel = INFO
|
|
53
config_example.py
Normal file
53
config_example.py
Normal file
@ -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
|
41
study.py
41
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,16 @@ 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])
|
try:
|
||||||
|
config = importlib.import_module(sys.argv[1])
|
||||||
|
except ModuleNotFoundError as e:
|
||||||
|
try:
|
||||||
|
config = importlib.import_module(str(sys.argv[1]).replace(".py", ""))
|
||||||
|
except ModuleNotFoundError as e:
|
||||||
|
print(e)
|
||||||
|
print("You need to pass a configuration file in parameter")
|
||||||
|
exit(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 +32,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…
x
Reference in New Issue
Block a user