Skip to content

Commit

Permalink
Fix ZLT corner case
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarbette committed Nov 19, 2024
1 parent 6fda702 commit c381884
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.13
- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ hashFiles('setup.py') }}
Expand Down
23 changes: 13 additions & 10 deletions integration/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,24 @@ def test_zlt():
logger.error(run)


def _test_allzlt(monotonic):
vlist = {'RATE' : RangeVariable("RATE",1,10,log=False)}
def _test_allzlt(monotonic,all=True):
vlist = {'RATE' : RangeVariable("RATE",1,10,log=False)} #From 1 to 10 included
results = OrderedDict()
zlt = ZLTVariableExpander(vlist, results, {}, "RATE", "PPS", 1.01,all=True,monotonic=monotonic)
zlt = ZLTVariableExpander(vlist, results, {}, "RATE", "PPS", 1.01, all=all, monotonic=monotonic)
it = iter(zlt)
run = next(it)
assert run["RATE"] == 10
results[Run({'RATE' : 10})] = {'PPS':[3.0]}
run = next(it)
assert run["RATE"] == 3
results[Run({'RATE' : 3})] = {'PPS':[3]}
run = next(it)
assert run["RATE"] == 2
results[Run({'RATE' : 2})] = {'PPS':[2]}
run = next(it)
assert run["RATE"] == 1
results[Run({'RATE' : 1})] = {'PPS':[1]}
if all:
run = next(it)
assert run["RATE"] == 2
results[Run({'RATE' : 2})] = {'PPS':[2]}
run = next(it)
assert run["RATE"] == 1
results[Run({'RATE' : 1})] = {'PPS':[1]}
if not monotonic:
run = next(it)
assert run["RATE"] == 4
Expand All @@ -234,4 +235,6 @@ def _test_allzlt(monotonic):

def test_allzlt():
_test_allzlt(monotonic=True)
_test_allzlt(monotonic=False)
_test_allzlt(monotonic=False)
_test_allzlt(monotonic=True, all=False)
_test_allzlt(monotonic=False, all=False)
9 changes: 2 additions & 7 deletions npf/expdesign/zltexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def strlen(self):
approx = int(len(self.expanded) * ceil(log2(len(self.input_values)) if (self.n_it <= 1) else self.n_tot_done/(self.n_it - 1)))
max = len(self.expanded) * len(self.input_values)
return f"~{approx}(max {max})"

class ZLTVariableExpander(OptVariableExpander):

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

self.output = output
self.perc = perc
self.monotonic = monotonic
Expand Down Expand Up @@ -127,15 +127,10 @@ def __next__(self):

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__()



#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:
if left_to_try and not acceptable_rates:
#Try the rate below the min already tried rate - its drop count. For instance if we tried 70 last run but got 67 of throughput, try the rate below 64
min_input = min(vals_for_current.keys())
min_output = vals_for_current[min_input]
Expand Down

0 comments on commit c381884

Please sign in to comment.