From dc7a4d3c032160762fe5191025bf8e3c7e087beb Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Mon, 6 Mar 2023 15:15:57 +0100 Subject: [PATCH] generate row/column interest locally in validator Signed-off-by: Csaba Kiraly --- DAS/simulator.py | 17 ++++++++++++----- DAS/validator.py | 21 +++++++++++++++------ config_example.py | 4 ++++ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/DAS/simulator.py b/DAS/simulator.py index 8b79e2c..f0195cd 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -15,6 +15,7 @@ class Simulator: def __init__(self, shape, config): """It initializes the simulation with a set of parameters (shape).""" self.shape = shape + self.config = config self.format = {"entity": "Simulator"} self.result = Result(self.shape) self.validators = [] @@ -28,12 +29,18 @@ class Simulator: self.glob = Observer(self.logger, self.shape) self.glob.reset() self.validators = [] - rows = list(range(self.shape.blockSize)) * int(self.shape.chi*self.shape.numberValidators/self.shape.blockSize) - columns = list(range(self.shape.blockSize)) * int(self.shape.chi*self.shape.numberValidators/self.shape.blockSize) - random.shuffle(rows) - random.shuffle(columns) + if self.config.evenLineDistribution: + rows = list(range(self.shape.blockSize)) * int(self.shape.chi*self.shape.numberValidators/self.shape.blockSize) + columns = list(range(self.shape.blockSize)) * int(self.shape.chi*self.shape.numberValidators/self.shape.blockSize) + random.shuffle(rows) + random.shuffle(columns) for i in range(self.shape.numberValidators): - val = Validator(i, int(not i!=0), self.logger, self.shape, rows, columns) + if self.config.evenLineDistribution: + val = Validator(i, int(not i!=0), self.logger, self.shape, + rows[(i*self.shape.chi):((i+1)*self.shape.chi)], + columns[(i*self.shape.chi):((i+1)*self.shape.chi)]) + else: + val = Validator(i, int(not i!=0), self.logger, self.shape) if i == self.proposerID: val.initBlock() self.glob.setGoldenData(val.block) diff --git a/DAS/validator.py b/DAS/validator.py index 4647df5..6a1b80a 100644 --- a/DAS/validator.py +++ b/DAS/validator.py @@ -38,8 +38,13 @@ class Validator: """It returns the validator ID.""" return str(self.ID) - def __init__(self, ID, amIproposer, logger, shape, rows, columns): - """It initializes the validator with the logger, shape and assigned rows/columns.""" + def __init__(self, ID, amIproposer, logger, shape, rows = None, columns = None): + """It initializes the validator with the logger shape and rows/columns. + + If rows/columns are specified these are observed, otherwise (default) + chi rows and columns are selected randomly. + """ + self.shape = shape FORMAT = "%(levelname)s : %(entity)s : %(message)s" self.ID = ID @@ -59,12 +64,16 @@ class Validator: self.rowIDs = range(shape.blockSize) self.columnIDs = range(shape.blockSize) else: - self.rowIDs = rows[(self.ID*self.shape.chi):(self.ID*self.shape.chi + self.shape.chi)] - self.columnIDs = columns[(self.ID*self.shape.chi):(self.ID*self.shape.chi + self.shape.chi)] #if shape.deterministic: # random.seed(self.ID) - #self.rowIDs = random.sample(range(self.shape.blockSize), self.shape.chi) - #self.columnIDs = random.sample(range(self.shape.blockSize), self.shape.chi) + if rows: + self.rowIDs = rows + else: + self.rowIDs = random.sample(range(self.shape.blockSize), self.shape.chi) + if columns: + self.columnIDs = columns + else: + self.columnIDs = random.sample(range(self.shape.blockSize), self.shape.chi) self.rowNeighbors = collections.defaultdict(dict) self.columnNeighbors = collections.defaultdict(dict) diff --git a/config_example.py b/config_example.py index 0967a4f..9235f10 100644 --- a/config_example.py +++ b/config_example.py @@ -24,6 +24,10 @@ logLevel = logging.INFO # for more details, see joblib.Parallel numJobs = 3 +# distribute rows/columns evenly between validators (True) +# or generate it using local randomness (False) +evenLineDistribution = False + # Number of simulation runs with the same parameters for statistical relevance runs = range(10)