From 2860ffdc3b24e32380fab613a108705aa129680c Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Thu, 4 May 2023 15:02:08 -0700 Subject: [PATCH] add automatically-generated lists of optimizers --- notwacube.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/notwacube.py b/notwacube.py index 0ad8544..aadc69f 100644 --- a/notwacube.py +++ b/notwacube.py @@ -7,6 +7,82 @@ BASELINE_OPTIMIZERS = [ quasirandom_cube, ] + +def collect_everything(): + G = globals().values() + λ = lambda G: [ + g for g in G if callable(g) and getattr(g, "__name__", "").endswith("_cube") + ] + _seen = {} + for thing in sum((λ(g) for g in G if type(g) is list), λ(G)): + key = thing.__name__ + if key in _seen and _seen[key] is not thing: + pass # print(f"Ignored: seen twice: {key}", file=sys.stderr) + _seen[key] = thing + # return list(_seen.values()) + return [v for k, v in sorted(_seen.items(), key=lambda t: t[0])] + + +FUCKING_EVERYTHING = collect_everything() + +try: + from previous import PREVIOUSLY_POSITIVE, PREVIOUSLY_NEGATIVE +except ModuleNotFoundError: + PREVIOUSLY_POSITIVE, PREVIOUSLY_NEGATIVE = [], [] +else: + g = {v.__name__: v for v in FUCKING_EVERYTHING} # globals() + + def refind(stuff): + _temp = [] + for opt in stuff: + _old_len = len(_temp) + if opt in g: + _temp.append(g[opt]) + elif opt.startswith("ng_") or opt.startswith("ngx_"): + if opt.startswith("ng_"): + ngx = "ngx_" + opt.removeprefix("ng_") + else: + ngx = "ng_" + opt.removeprefix("ngx_") # whatever + if ngx in g: + _temp.append(g[ngx]) + else: + for ng_opt in NEVERGRAD2_OPTIMIZERS: + if ng_opt.__name__ == opt or ng_opt.__name__ == ngx: + _temp.append(ng_opt) + if len(_temp) == _old_len: + # FIXME: this text is not necessarily for PREVIOUSLY_POSITIVE! + print( + f"Ignored: failed to find {opt} for PREVIOUSLY_POSITIVE", + file=sys.stderr, + ) + return _temp + + PREVIOUSLY_POSITIVE = refind(PREVIOUSLY_POSITIVE) + PREVIOUSLY_NEGATIVE = refind(PREVIOUSLY_NEGATIVE) + del g + + for opt in (another_random_cube, quasirandom_cube): + if opt not in PREVIOUSLY_POSITIVE: + PREVIOUSLY_POSITIVE.append(opt) + for opt in (another_random_cube, quasirandom_cube): + if opt not in PREVIOUSLY_NEGATIVE: + PREVIOUSLY_NEGATIVE.append(opt) + +try: + from elo_blacklist import blacklisted +except ModuleNotFoundError: + WHITELISTED_OPTIMIZERS = FUCKING_EVERYTHING.copy() +else: + WHITELISTED_OPTIMIZERS = [ + opt + for opt in FUCKING_EVERYTHING + if opt.__name__.removesuffix("_cube") not in blacklisted + ] + book_of_optimizers = dict( baseline=BASELINE_OPTIMIZERS, + everything=FUCKING_EVERYTHING, + negative=PREVIOUSLY_NEGATIVE, + positive=PREVIOUSLY_POSITIVE, + whitelisted=WHITELISTED_OPTIMIZERS, )