from dlibcube2 import dlib_cube from nloptcube2 import nlopt_neldermead_cube from randomcube2 import another_random_cube, quasirandom_cube BASELINE_OPTIMIZERS = [ another_random_cube, nlopt_neldermead_cube, 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, )