From c381884750b72eba4a621eaab4e84a53216d47e5 Mon Sep 17 00:00:00 2001 From: Tom Barbette Date: Tue, 19 Nov 2024 14:47:03 +0100 Subject: [PATCH] Fix ZLT corner case --- .github/workflows/ci.yml | 2 +- integration/test_unittest.py | 23 +++++++++++++---------- npf/expdesign/zltexp.py | 9 ++------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71e0255..7006b6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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') }} diff --git a/integration/test_unittest.py b/integration/test_unittest.py index 6947746..aa08653 100644 --- a/integration/test_unittest.py +++ b/integration/test_unittest.py @@ -204,10 +204,10 @@ 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 @@ -215,12 +215,13 @@ def _test_allzlt(monotonic): 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 @@ -234,4 +235,6 @@ def _test_allzlt(monotonic): def test_allzlt(): _test_allzlt(monotonic=True) - _test_allzlt(monotonic=False) \ No newline at end of file + _test_allzlt(monotonic=False) + _test_allzlt(monotonic=True, all=False) + _test_allzlt(monotonic=False, all=False) \ No newline at end of file diff --git a/npf/expdesign/zltexp.py b/npf/expdesign/zltexp.py index ddb6cc1..4df5bba 100644 --- a/npf/expdesign/zltexp.py +++ b/npf/expdesign/zltexp.py @@ -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 @@ -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]