Clean up logic in _minmax() for what steps to loop over
Just use (step, index) tuple in steplist provided, don't additionally
loop over all indices for each step (this resulted in extra work).
@@ -2246,13 +2246,15 @@ class Chip:
# Keeping track of the steps/indexes that have goals met
failed = {}
- for step, _ in steplist:
+ for step, index in steplist:
+ if step not in failed:
failed[step] = {}
- for index in self.getkeys('flowgraph', step):
+ failed[step][index] = False
+
if self.get('flowstatus', step, index, 'error'):
failed[step][index] = True
- else:
- failed[step][index] = False
+ continue
+
for metric in self.getkeys('metric', step, index):
if 'goal' in self.getkeys('metric', step, index, metric):
goal = self.get('metric', step, index, metric, 'goal')
@@ -2266,29 +2268,22 @@ class Chip:
# Calculate max/min values for each metric
max_val = {}
min_val = {}
- for step, _ in steplist:
- max_val[step] = {}
- min_val[step] = {}
for metric in self.getkeys('flowgraph', step, '0', 'weight'):
- max_val[step][metric] = 0
- min_val[step][metric] = float("inf")
- for index in self.getkeys('flowgraph', step):
- if not self.get('flowstatus', step, index, 'error'):
+ max_val[metric] = 0
+ min_val[metric] = float("inf")
+ for step, index in steplist:
+ if not failed[step][index]:
real = self.get('metric', step, index, metric, 'real')
- max_val[step][metric] = max(max_val[step][metric], real)
- min_val[step][metric] = min(min_val[step][metric], real)
+ max_val[metric] = max(max_val[metric], real)
+ min_val[metric] = min(min_val[metric], real)
# Select the minimum index
- min_score = None
+ min_score = float('inf')
winner = None
- for step, _ in steplist:
- min_score = float("inf")
- #TODO: why not run for all stepindex inputs?
- for index in self.getkeys('flowgraph', step):
+ for step, index in steplist:
if failed[step][index]:
continue
- if not self.get('flowstatus', step, index, 'error'):
score = 0.0
for metric in self.getkeys('flowgraph', step, index, 'weight'):
weight = self.get('flowgraph', step, index, 'weight', metric)
@@ -2297,10 +2292,11 @@ class Chip:
continue
real = self.get('metric', step, index, metric, 'real')
- if not (max_val[step][metric] - min_val[step][metric]) == 0:
- scaled = (real - min_val[step][metric]) / (max_val[step][metric] - min_val[step][metric])
+
+ if not (max_val[metric] - min_val[metric]) == 0:
+ scaled = (real - min_val[metric]) / (max_val[metric] - min_val[metric])
else:
- scaled = max_val[step][metric]
+ scaled = max_val[metric]
score = score + scaled * weight
if score < min_score:
