from dlibcube2 import dlib_cube from evolopycube2 import make_evolopy from nevergradcube2 import NEVERGRAD2_OPTIMIZERS from nloptcube2 import nlopt_neldermead_cube from notwacube2 import make_birect, make_mercury, make_soo from randomcube2 import another_random_cube, quasirandom_cube from scipycube2 import ( make_shgo, scipy_basinhopping_cube, scipy_bfgs_2j_cube, scipy_bfgs_3j_cube, scipy_cg_2j_cube, scipy_cg_3j_cube, scipy_cobyla_cube, scipy_direct_cube, scipy_direct_l_cube, # scipy_dogleg_cube, scipy_lbfgsb_2j_cube, scipy_lbfgsb_3j_cube, scipy_neldermead_cube, # scipy_newtoncg_cube, scipy_powell_cube, scipy_slsqp_2j_cube, scipy_slsqp_3j_cube, scipy_tnc_2j_cube, scipy_tnc_3j_cube, scipy_trustconstr_2j_cube, scipy_trustconstr_3j_cube, # scipy_trustexact_2j_cube, # scipy_trustexact_3j_cube, # scipy_trustkrylov_cube, # scipy_trustncg_cube, ) import tinytweaks as tt BASELINE_OPTIMIZERS = [ another_random_cube, nlopt_neldermead_cube, quasirandom_cube, ] SHGO_OPTIMIZERS = [ make_shgo(method="cobyla"), make_shgo(method="slsqp"), make_shgo(method="cobyla", mei=True), make_shgo(method="slsqp", mei=True), ] NOTWA_OPTIMIZERS = [ make_birect(deepness=38, longest=True, pruning=False), make_mercury(13, isigma=tt.S3), make_mercury(29, isigma=tt.S3), make_soo(deepness=23, K=4), make_soo(deepness=35, K=3), make_soo(deepness=53, K=2), ] EVOLOPY_OPTIMIZERS = [ make_evolopy(name, popsize) for name in "BAT CS DE FFA GA GWO HHO JAYA MFO MVO PSO SCA SSA WOA".split() for popsize in (None, 5, 10, 15) ] 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, evolopy=EVOLOPY_OPTIMIZERS, negative=PREVIOUSLY_NEGATIVE, positive=PREVIOUSLY_POSITIVE, shgo=SHGO_OPTIMIZERS, whitelisted=WHITELISTED_OPTIMIZERS, )