Skip to content

Commit

Permalink
Add the "m" suffix to zlt to have non-monotonic mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarbette committed Nov 21, 2024
1 parent 0b7dd3c commit eff74a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
28 changes: 16 additions & 12 deletions npf/expdesign/zltexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ def need_run_for(self, next_val):
return copy

def ensure_monotonic(self, max_r, vals_for_current):

if not self.monotonic and max_r < max(self.executable_values):
if not self.monotonic and \
(max_r is not None and max_r < max(self.executable_values) or (max_r is None)):
# If the function is not monotonic, we now have to try rates between the max acceptable and the first dropping rate
after_max = next(iter(filter(lambda x : x > max_r, self.executable_values)))
if max_r is not None:
after_max = next(iter(filter(lambda x : x > max_r, self.executable_values)))
else:
after_max = min(self.executable_values)

if after_max not in vals_for_current:
return self.need_run_for(after_max)

Expand Down Expand Up @@ -121,27 +125,27 @@ def __next__(self):
#If we're lucky, the max rate is doable

if len(acceptable_rates) == 1 and not self.all:
return self.ensure_monotonic(max(acceptable_rates), vals_for_current)
return self.ensure_monotonic(max(acceptable_rates), vals_for_current)


#Step 2 : go for the rate below the output of the max input
maybe_achievable_inputs = list(filter(lambda x : x <= max_r, self.executable_values))
if len(maybe_achievable_inputs) == 0:
print(f"WARNING: No achievable for {self.input}! Tried {max_r} and it did not work.")
self.current = None
return self.__next__()
return self.ensure_monotonic(None, vals_for_current)
else:
next_val = max(maybe_achievable_inputs)
else:

maybe_achievable_inputs = list(filter(lambda x : x <= max_r*self.margin, self.executable_values))
left_to_try = set(maybe_achievable_inputs).difference(vals_for_current.keys())
if len(left_to_try) == 0:
#There's no more points to try, we could never find a ZLT
self.current = None
return self.__next__()


if len(left_to_try) == 0: #No more values left to try
if len(acceptable_rates) > 0: #Nothing left to try but we have a ZLT, should try the next value in non-monotonic
return self.ensure_monotonic(max(acceptable_rates), vals_for_current)
else:
#We could never find a zlt, and there's nothing left to try... no value can handle the input
self.validate_run()
return self.__next__()

#Step 3...K : try to get an acceptable rate. This step might be skipped if we got an acceptable rate already
if not acceptable_rates:
Expand Down
3 changes: 2 additions & 1 deletion npf/tests/sections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ def expand(self, results=None, method="full", overriden=set()):
else:
all_lower = False
perc = method.lower()[2] == 'p'
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=all_lower, perc=perc)
monotonic = method.lower()[-1] == 'm'
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=all_lower, perc=perc, monotonic=monotonic)
elif "minacceptable" in method.lower():
return MinAcceptableVariableExpander(self.vlist, overriden=overriden, results=results, input=params[0], output=params[1], margin=1.01 if len(params) == 2 else float(params[2]))

Expand Down

0 comments on commit eff74a5

Please sign in to comment.