generate row/column interest locally in validator

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-03-06 15:15:57 +01:00
parent 4a5d410f6a
commit dc7a4d3c03
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
3 changed files with 31 additions and 11 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)