def test_multiretry(num_retries = min(256, 8*mp.cpu_count()), keep = 0.7, optimizer = de2_cma(1500), logger = logger(), repeat = 10): seqs = Tandem(0).seqs n = len(seqs) problems = [Tandem(i) for i in range(n)] ids = [str(seqs[i]) for i in range(n)] t0 = time.perf_counter() for _ in range(repeat): # check all variants problem_stats = multiretry.minimize(problems, ids, num_retries, keep, optimizer, logger) ps = problem_stats[0] # for _ in range(10): # # improve the best variant using only one node # fval = ray.get(ps.retry.remote(optimizer)) # logger.info("improve best variant " + ray.get(ps.name.remote()) # + ' ' + str(ray.get(ps.id.remote())) # + ' ' + str(ray.get(ps.value.remote())) # + ' time = ' + str(dtime(t0))) # if fval < -1490: # break # optimize best variant starting from scratch using all nodes logger.info("improve best variant " + ray.get(ps.name.remote()) + ' ' + str(ray.get(ps.id.remote())) + ' ' + str(ray.get(ps.value.remote())) + ' time = ' + str(dtime(t0))) problem = problems[ray.get(ps.index.remote())] _rayoptimizer(optimizer, problem, 1, max_time = 1200, log = logger)
def getFunctionDetails(a): # [name, lb, ub, dim] param = { "F1": ["F1",-100,100,30], "F2" : ["F2",-10,10,30], "F3" : ["F3",-100,100,30], "F4" : ["F4",[30,20,10] ,[120,80,60],3] "F5" : ["F5",-30,30,30], "F6" : ["F6",-100,100,30], "F7" : ["F7",-1.28,1.28,30], "F8" : ["F8",-500,500,30], "F9" : ["F9",-5.12,5.12,30], "F10" : ["F10",-32,32,30], "F11" : ["F11",-600,600,30] , "F12" : ["F12",-50,50,30], "F13" : ["F13",-50,50,30], "F14" : ["F14",-65.536,65.536,2], "F15" : ["F15",-5,5,4], "F16" : ["F16",-5,5,2], "F17" : ["F17",-5,15,2], "F18" : ["F18",-2,2,2] , "F19" : ["F19",0,1,3], "F20" : ["F20",0,1,6], "F21" : ["F21",0,10,4], "F22" : ["F22",0,10,4], "F23" : ["F23",0,10,4], "Ca1" : ["Ca1",Cassini1().bounds.lb,Cassini1().bounds.ub,len(Cassini1().bounds.lb)], "Ca2" : ["Ca2",Cassini2().bounds.lb,Cassini2().bounds.ub,len(Cassini2().bounds.lb)], "Gt1" : ["Gt1",Gtoc1().bounds.lb,Gtoc1().bounds.ub,len(Gtoc1().bounds.lb)], "Mes" : ["Mes",Messenger().bounds.lb,Messenger().bounds.ub,len(Messenger().bounds.lb)], "Mef" : ["Mef",MessFull().bounds.lb,MessFull().bounds.ub,len(MessFull().bounds.lb)], "Sag" : ["Sag",Sagas().bounds.lb,Sagas().bounds.ub,len(Sagas().bounds.lb)], "Tan" : ["Tan",Tandem(5).bounds.lb,Tandem(5).bounds.ub,len(Tandem(5).bounds.lb)], "Ros" : ["Ros",Rosetta().bounds.lb,Rosetta().bounds.ub,len(Rosetta().bounds.lb)], }
def test_multiretry(num_retries = 512, keep = 0.7, optimizer = de_cma(1500), logger = logger(), repeat = 50): seqs = Tandem(0).seqs n = len(seqs) problems = [Tandem(i) for i in range(n)] ids = [str(seqs[i]) for i in range(n)] for _ in range(100): problem_stats = multiretry.minimize(problems, ids, num_retries, keep, optimizer, logger) ps = problem_stats[0] for _ in range(repeat): logger.info("problem " + ps.prob.name + ' ' + str(ps.id)) ps.retry(optimizer)
def test_coordinated_retry(): numRuns = 10 min_evals = 1500 algo = de_cma_pyg(min_evals) #algo = pyg_de_cma(min_evals) #algo = de_pyg_cma(min_evals) fac = 1.005 _test_optimizer(algo, Gtoc1(), num_retries=10000, num=numRuns, value_limit=-300000.0, stop_val=-1581950 / fac) _test_optimizer(algo, Cassini1(), num_retries=4000, num=numRuns, value_limit=20.0, stop_val=4.9307 * fac) _test_optimizer(algo, Cassini2(), num_retries=6000, num=numRuns, value_limit=20.0, stop_val=8.383 * fac) _test_optimizer(algo, Messenger(), num_retries=8000, num=numRuns, value_limit=20.0, stop_val=8.63 * fac) _test_optimizer(algo, Rosetta(), num_retries=4000, num=numRuns, value_limit=20.0, stop_val=1.3433 * fac) _test_optimizer(algo, Sagas(), num_retries=4000, num=numRuns, value_limit=100.0, stop_val=18.187 * fac) _test_optimizer(algo, Tandem(5), num_retries=20000, num=numRuns, value_limit=-300.0, stop_val=-1500.6 / fac) _test_optimizer(algo, MessFull(), num_retries=50000, num=numRuns, value_limit=12.0, stop_val=1.959 * fac)
def main(): numRuns = 100 min_evals = 1500 _test_optimizer(de_cma(min_evals), Gtoc1(), num_retries=10000, num=numRuns, value_limit=-300000.0, stop_val=-1581949) _test_optimizer(de_cma(min_evals), Cassini1(), num_retries=4000, num=numRuns, value_limit=20.0, stop_val=4.93075) _test_optimizer(de_cma(min_evals), Cassini2(), num_retries=6000, num=numRuns, value_limit=20.0, stop_val=8.38305) _test_optimizer(de_cma(min_evals), Messenger(), num_retries=8000, num=numRuns, value_limit=20.0, stop_val=8.62995) _test_optimizer(de_cma(min_evals), Rosetta(), num_retries=4000, num=numRuns, value_limit=20.0, stop_val=1.34335) _test_optimizer(de_cma(min_evals), Sagas(), num_retries=4000, num=numRuns, value_limit=100.0, stop_val=18.188) _test_optimizer(de_cma(min_evals), Tandem(5), num_retries=20000, num=numRuns, value_limit=-300.0, stop_val=-1500) _test_optimizer(de_cma(min_evals), MessFull(), num_retries=50000, num=numRuns, value_limit=12.0, stop_val=1.960)
def test_archipelago(): max_evals = 500000 popsize = 32 gen = int(max_evals / popsize + 1) algo = pg.algorithm(pg.de1220(gen=gen)) fac = 1.005 _test_archipelago(algo, Cassini1(), num=400, stop_val=4.9307 * fac) _test_archipelago(algo, Cassini2(), num=600, stop_val=8.383 * fac) _test_archipelago(algo, Gtoc1(), num=1000, stop_val=-1581950 / fac) _test_archipelago(algo, Messenger(), num=800, stop_val=8.63 * fac) _test_archipelago(algo, Rosetta(), num=400, stop_val=1.3433 * fac) _test_archipelago(algo, Sagas(), num=400, stop_val=18.187 * fac) _test_archipelago(algo, Tandem(5), num=2000, stop_val=-1500.6 / fac) _test_archipelago(algo, MessFull(), num=5000, stop_val=1.959 * fac)
class tandem_mo: def __init__(self, constrained=False): self.base = Tandem(5, constrained=constrained) self.bounds = self.base.bounds self.weight_bounds = Bounds([1, 0], [1, 0]) # ignore 2nd objective self.name = self.base.name def fun(self, x): final_mass = self.base.fun(np.array(x)) # original objective (-kg) mission_time = sum(x[4:8]) # mission time (days) y = np.empty(2) y[0] = final_mass y[1] = mission_time return y
def Tan(x): return Tandem(5).fun(x)
# Examples for fcmaes multinode coordinated retry from https://www.esa.int/gsp/ACT/projects/gtop/ import ray from fcmaes.astro import MessFull, Messenger, Cassini2, Rosetta, Gtoc1, Cassini1, Tandem, Sagas, Cassini1minlp from fcmaes.optimizer import logger, de_cma, de2_cma, da_cma, Cma_cpp, De_cpp, Da_cpp, Hh_cpp, Dual_annealing, Differential_evolution, GCLDE_cpp, LCLDE_cpp, LDe_cpp, Sequence from fcmaesray.rayretry import minimize min_evals = 1500 max_nodes = 100 problems = [ Cassini1(), Cassini2(), Rosetta(), Tandem(5), Messenger(), Gtoc1(), MessFull(), Sagas(), Cassini1minlp() ] algos = [ de2_cma(min_evals), de_cma(min_evals), da_cma(min_evals), Cma_cpp(min_evals), De_cpp(min_evals), Hh_cpp(min_evals), Da_cpp(min_evals), Dual_annealing(min_evals),
# Copyright (c) Dietmar Wolz. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory. import math from fcmaes.astro import MessFull, Messenger, Gtoc1, Cassini1, Cassini2, Rosetta, Tandem, Sagas from fcmaes.optimizer import logger, de_cma, da_cma, Cma_cpp, De_cpp, Da_cpp, Dual_annealing, Differential_evolution from fcmaes.retry import minimize problems = [Cassini1(), Cassini2(), Rosetta(), Tandem(5), Messenger(), Gtoc1(), MessFull(), Sagas()] max_evals = 50000 algos = [de_cma(max_evals), da_cma(max_evals), Cma_cpp(max_evals), De_cpp(max_evals), Da_cpp(max_evals), Dual_annealing(max_evals), Differential_evolution(max_evals)] def test_all(num_retries = 10000, num = 10): for problem in problems: for algo in algos: _test_optimizer(algo, problem, num_retries, num) def _test_optimizer(opt, problem, num_retries = 32, num = 10): log = logger() log.info(problem.name + ' ' + opt.name) for _ in range(num): ret = minimize(problem.fun, problem.bounds, math.inf, num_retries, log, optimizer=opt) def main(): test_all()
def __init__(self, constrained=False): self.base = Tandem(5, constrained=constrained) self.bounds = self.base.bounds self.weight_bounds = Bounds([1, 0], [1, 0]) # ignore 2nd objective self.name = self.base.name