measure validation progress more precisely

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-04-09 23:21:23 +02:00
parent 5496249987
commit 3e822ab6ca
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
3 changed files with 41 additions and 22 deletions

View File

@ -46,16 +46,18 @@ class Observer:
arrived = 0 arrived = 0
expected = 0 expected = 0
ready = 0 ready = 0
validatedall = 0
validated = 0 validated = 0
for val in validators: for val in validators:
if val.amIproposer == 0: if val.amIproposer == 0:
(a, e) = val.checkStatus() (a, e, v) = val.checkStatus()
arrived += a arrived += a
expected += e expected += e
if a == e: if a == e:
ready += 1 ready += 1
validated += val.vpn validatedall += val.vpn
return (arrived, expected, ready, validated) validated += v
return (arrived, expected, ready, validatedall, validated)
def getProgress(self, validators): def getProgress(self, validators):
"""Calculate current simulation progress with different metrics. """Calculate current simulation progress with different metrics.
@ -69,14 +71,15 @@ class Observer:
but counts a validator only if its support node's all validators see all interesting segments but counts a validator only if its support node's all validators see all interesting segments
TODO: add real per validator progress counter TODO: add real per validator progress counter
""" """
arrived, expected, ready, validated = self.checkStatus(validators) arrived, expected, ready, validatedall, validated = self.checkStatus(validators)
missingSamples = expected - arrived missingSamples = expected - arrived
sampleProgress = arrived / expected sampleProgress = arrived / expected
nodeProgress = ready / (len(validators)-1) nodeProgress = ready / (len(validators)-1)
validatorCnt = sum([v.vpn for v in validators[1:]]) validatorCnt = sum([v.vpn for v in validators[1:]])
validatorAllProgress = validatedall / validatorCnt
validatorProgress = validated / validatorCnt validatorProgress = validated / validatorCnt
return missingSamples, sampleProgress, nodeProgress, validatorProgress return missingSamples, sampleProgress, nodeProgress, validatorAllProgress, validatorProgress
def getTrafficStats(self, validators): def getTrafficStats(self, validators):
"""Summary statistics of traffic measurements in a timestep.""" """Summary statistics of traffic measurements in a timestep."""

View File

@ -167,7 +167,7 @@ class Simulator:
def run(self): def run(self):
"""It runs the main simulation until the block is available or it gets stucked.""" """It runs the main simulation until the block is available or it gets stucked."""
self.glob.checkRowsColumns(self.validators) self.glob.checkRowsColumns(self.validators)
arrived, expected, ready, validated = self.glob.checkStatus(self.validators) arrived, expected, ready, validatedall, validated = self.glob.checkStatus(self.validators)
missingSamples = expected - arrived missingSamples = expected - arrived
missingVector = [] missingVector = []
progressVector = [] progressVector = []
@ -199,9 +199,9 @@ class Simulator:
self.validators[i].updateStats() self.validators[i].updateStats()
trafficStatsVector.append(trafficStats) trafficStatsVector.append(trafficStats)
missingSamples, sampleProgress, nodeProgress, validatorProgress = self.glob.getProgress(self.validators) missingSamples, sampleProgress, nodeProgress, validatorAllProgress, validatorProgress = self.glob.getProgress(self.validators)
self.logger.debug("step %d, arrived %0.02f %%, ready %0.02f %%, validated %0.02f %%" self.logger.info("step %d, arrived %0.02f %%, ready %0.02f %%, validatedall %0.02f %%, , validated %0.02f %%"
% (steps, sampleProgress*100, nodeProgress*100, validatorProgress*100), extra=self.format) % (steps, sampleProgress*100, nodeProgress*100, validatorAllProgress*100, validatorProgress*100), extra=self.format)
cnS = "samples received" cnS = "samples received"
cnN = "nodes ready" cnN = "nodes ready"

View File

@ -69,8 +69,13 @@ class Validator:
# random.seed(self.ID) # random.seed(self.ID)
self.nodeClass = 1 if (self.ID <= shape.numberNodes * shape.class1ratio) else 2 self.nodeClass = 1 if (self.ID <= shape.numberNodes * shape.class1ratio) else 2
self.vpn = self.shape.vpn1 if (self.nodeClass == 1) else self.shape.vpn2 self.vpn = self.shape.vpn1 if (self.nodeClass == 1) else self.shape.vpn2
self.rowIDs = rows if rows else unionOfSamples(range(self.shape.blockSize), self.shape.chi, self.vpn) self.vRowIDs = []
self.columnIDs = columns if columns else unionOfSamples(range(self.shape.blockSize), self.shape.chi, self.vpn) self.vColumnIDs = []
for i in range(self.vpn):
self.vRowIDs.append(set(rows[i*self.shape.chi:(i+1)*self.shape.chi]) if rows else set(random.sample(range(self.shape.blockSize), self.shape.chi)))
self.vColumnIDs.append(set(columns[i*self.shape.chi:(i+1)*self.shape.chi]) if columns else set(random.sample(range(self.shape.blockSize), self.shape.chi)))
self.rowIDs = set.union(*self.vRowIDs)
self.columnIDs = set.union(*self.vColumnIDs)
self.rowNeighbors = collections.defaultdict(dict) self.rowNeighbors = collections.defaultdict(dict)
self.columnNeighbors = collections.defaultdict(dict) self.columnNeighbors = collections.defaultdict(dict)
@ -469,16 +474,27 @@ class Validator:
def checkStatus(self): def checkStatus(self):
"""It checks how many expected/arrived samples are for each assigned row/column.""" """It checks how many expected/arrived samples are for each assigned row/column."""
arrived = 0
expected = 0 def checkStatus(columnIDs, rowIDs):
for id in self.columnIDs: arrived = 0
line = self.getColumn(id) expected = 0
arrived += line.count(1) for id in columnIDs:
expected += len(line) line = self.getColumn(id)
for id in self.rowIDs: arrived += line.count(1)
line = self.getRow(id) expected += len(line)
arrived += line.count(1) for id in rowIDs:
expected += len(line) line = self.getRow(id)
arrived += line.count(1)
expected += len(line)
return arrived, expected
arrived, expected = checkStatus(self.columnIDs, self.rowIDs)
self.logger.debug("status: %d / %d", arrived, expected, extra=self.format) self.logger.debug("status: %d / %d", arrived, expected, extra=self.format)
return (arrived, expected) validated = 0
for i in range(self.vpn):
a, e = checkStatus(self.vColumnIDs[i], self.vRowIDs[i])
if a == e:
validated+=1
return arrived, expected, validated