Skip to content

Commit

Permalink
ZLT: Configurable margin and add allzlt
Browse files Browse the repository at this point in the history
ALLZLT will run all rates for any zero-loss throughput.
For instance if the system supports 50Gbps, and you want to study
[0-100#5]
it will run 100, 50, 45, 40 ... avoiding infeasable values by seeing the
output is not more than 50 for the first run at 100Gbps.
  • Loading branch information
tbarbette committed Aug 2, 2024
1 parent dfaa8b9 commit ff5f889
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 12 additions & 7 deletions npf/expdesign/zltexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class ZLTVariableExpander(FullVariableExpander):

def __init__(self, vlist:Dict[str,Variable], results, overriden, input, output):
def __init__(self, vlist:Dict[str,Variable], results, overriden, input, output, margin, all=False):


if not input in vlist:
Expand All @@ -21,6 +21,8 @@ def __init__(self, vlist:Dict[str,Variable], results, overriden, input, output):
self.current = None
self.output = output
self.passed = 0
self.margin = margin
self.all = all
super().__init__(vlist, overriden)

def __iter__(self):
Expand All @@ -32,7 +34,7 @@ def __len__(self):
return len(self.expanded) * len(self.input_values) - self.passed

def __next__(self):
margin=1.01

if self.current == None:
self.current = self.it.__next__()

Expand All @@ -47,7 +49,7 @@ def __next__(self):
r_out = np.mean(vals[self.output])
r_in = r.variables[self.input]
vals_for_current[r_in] = r_out
if r_out >= r_in/margin:
if r_out >= r_in/self.margin:
acceptable_rates.append(r_in)
else:
max_r = min(max_r, r_out)
Expand All @@ -60,7 +62,7 @@ def __next__(self):
elif len(vals_for_current) == 1:
#If we're lucky, the max rate is doable

if len(acceptable_rates) == 1:
if len(acceptable_rates) == 1 and not self.all:
self.current = None
self.passed += len(self.input_values) - 1
return self.__next__()
Expand All @@ -70,7 +72,7 @@ def __next__(self):
next_val = max(maybe_achievable_inputs)
else:

maybe_achievable_inputs = list(filter(lambda x : x <= max_r*margin, self.input_values))
maybe_achievable_inputs = list(filter(lambda x : x <= max_r*self.margin, self.input_values))
left_to_try = set(maybe_achievable_inputs).difference(vals_for_current.keys())

#Step 3...K : try to get an acceptable rate. This step might be skiped if we got an acceptable rate already
Expand All @@ -82,7 +84,7 @@ def __next__(self):
next_val = max(filter(lambda x : x < target,left_to_try))
else:
#Step K... n : we do a binary search between the maximum acceptable rate and the minimal rate observed
max_acceptable = max(acceptable_rates)
max_acceptable = -1 if self.all else max(acceptable_rates)
#Consider we tried 100->95 (max_r=95), 90->90 (acceptable) we have to try values between 90..95
left_to_try_over_acceptable = list(filter(lambda x: x > max_acceptable, left_to_try))
if len(left_to_try_over_acceptable) == 0:
Expand All @@ -91,7 +93,10 @@ def __next__(self):
self.passed += len(self.input_values) - len(vals_for_current)
return self.__next__()
#Binary search
next_val = left_to_try_over_acceptable[int(len(left_to_try_over_acceptable) / 2)]
if self.all:
next_val=max(left_to_try_over_acceptable)
else:
next_val = left_to_try_over_acceptable[int(len(left_to_try_over_acceptable) / 2)]


copy = self.current.copy()
Expand Down
6 changes: 5 additions & 1 deletion npf/sections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ def expand(self, results, method=None, overriden=set()):
return RandomVariableExpander(self.vlist)
elif method.lower().startswith("zlt"):
params = method[4:-1].split(",")
return ZLTVariableExpander(self.vlist, overriden=overriden, results=results, input=params[0], output=params[1])
return ZLTVariableExpander(self.vlist, overriden=overriden, results=results, input=params[0], output=params[1], margin=1.01 if len(params) == 2 else float(params[2]))
elif method.lower().startswith("allzlt"):
params = method[7:-1].split(",")
return ZLTVariableExpander(self.vlist, overriden=overriden, results=results, input=params[0], output=params[1], margin=1.01 if len(params) == 2 else float(params[2]), all=True)

else:
return FullVariableExpander(self.vlist, overriden)

Expand Down

0 comments on commit ff5f889

Please sign in to comment.