diff --git a/tests/topfarm/test_drivers.py b/tests/topfarm/test_drivers.py index ae3b5210a5d5b5da54253788710e46b1a2405cd4..39faec7ad32a72137e6f1db21140b9b5dd447643 100644 --- a/tests/topfarm/test_drivers.py +++ b/tests/topfarm/test_drivers.py @@ -1,16 +1,9 @@ -''' -Created on 17. maj 2018 - -@author: mmpe -''' from topfarm import TopFarm - import numpy as np import pytest -from topfarm.cost_models.dummy import DummyCost, DummyCostPlotComp +from topfarm.cost_models.dummy import DummyCost from topfarm.plotting import NoPlot -from topfarm.easy_drivers import EasyScipyOptimizeDriver,\ - EasyPyOptSparseSLSQP, EasyPyOptSparseIPOPT +from topfarm.easy_drivers import EasyScipyOptimizeDriver, EasyPyOptSparseIPOPT initial = [[6, 0], [6, -8], [1, 1]] # initial turbine layouts @@ -22,7 +15,8 @@ desired = [[3, -3], [7, -7], [4, -3]] # desired turbine layouts @pytest.fixture def topfarm_generator(): def _topfarm_obj(driver): - #plot_comp = DummyCostPlotComp(desired) + # from topfarm.cost_models.dummy import DummyCostPlotComp + # plot_comp = DummyCostPlotComp(desired) plot_comp = NoPlot() return TopFarm(initial, DummyCost(desired), 2, plot_comp=plot_comp, boundary=boundary, driver=driver) return _topfarm_obj @@ -32,12 +26,10 @@ def topfarm_generator(): (EasyScipyOptimizeDriver(tol=1e-3), 1e-2), (EasyScipyOptimizeDriver(maxiter=13), 1e-1), (EasyScipyOptimizeDriver(optimizer='COBYLA', tol=1e-3, disp=False), 1e-2), - (EasyPyOptSparseSLSQP(), 1e-4), (EasyPyOptSparseIPOPT(), 1e-4), - #(EasySimpleGADriver(), 1e-4) ][:]) def test_optimizers(driver, tol, topfarm_generator): - if driver.__class__.__name__=="PyOptSparseMissingDriver": + if driver.__class__.__name__ == "PyOptSparseMissingDriver": pytest.xfail("reason") tf = topfarm_generator(driver) tf.evaluate() @@ -49,4 +41,3 @@ def test_optimizers(driver, tol, topfarm_generator): assert sum((tb_pos[2] - tb_pos[0])**2) > 2**2 - tol # check min spacing assert tb_pos[1][0] < 6 + tol # check within border np.testing.assert_array_almost_equal(tb_pos, optimal, -int(np.log10(tol))) - #print (tb_pos - optimal) diff --git a/topfarm/_topfarm.py b/topfarm/_topfarm.py index c145ea4a4708405150ffea551f61bb33dabb9c0f..1e0e75d8450f5188751db4628a61ec1c956fdefe 100644 --- a/topfarm/_topfarm.py +++ b/topfarm/_topfarm.py @@ -43,7 +43,7 @@ class TopFarm(object): indeps.add_output('boundary', self.boundary_comp.vertices, units='m') prob.model.add_subsystem('cost_comp', cost_comp, promotes=['*']) prob.driver = driver - + prob.model.add_design_var('turbineX', **design_var_kwargs) prob.model.add_design_var('turbineY', **design_var_kwargs) prob.model.add_objective('cost') diff --git a/topfarm/easy_drivers.py b/topfarm/easy_drivers.py index 4d61f43af774be0402a44783c8f3b190c3094704..339d244daa71452f4d602dc3cf628b9f3aba40f7 100644 --- a/topfarm/easy_drivers.py +++ b/topfarm/easy_drivers.py @@ -46,60 +46,3 @@ except ModuleNotFoundError: EasyPyOptSparseSLSQP = PyOptSparseMissingDriver EasyPyOptSparseIPOPT = PyOptSparseMissingDriver - - -# class EasySimpleGADriver(SimpleGADriver): -# def __init__(self, elitism=True, max_gen=100): -# """Simple Genetic Algorithm Driver with argument -# -# Parameters -# ---------- -# bits : dict -# Number of bits of resolution. Default is an empty dict, where every unspecified variable is assumed to be integer, and the number of bits is calculated automatically. If you have a continuous var, you should set a bits value as a key in this dictionary. -# NotImplemented -# debug_print : list -# List of what type of Driver variables to print at each iteration. Valid items in list are 'desvars', 'ln_cons', 'nl_cons', 'objs', 'totals' -# NotImplemented -# elitism : bool -# If True, replace worst performing point with best from previous generation each iteration. -# max_gen : int -# Number of generations before termination. -# pop_size : -# Number of points in the GA. Set to 0 and it will be computed as four times the number of bits. -# NotImplemented -# procs_per_model : int -# Number of processors to give each model under MPI. -# NotImplemented -# run_parallel : bool -# Set to True to execute the points in a generation in parallel. -# NotImplemented -# """ -# SimpleGADriver.__init__(self) -# self.options.update({'elitism': elitism, 'max_gen': max_gen}) - -# -# class COBYLADriverWrapper(CONMINdriver): -# # CONMIN-specific Settings -# self.driver.itmax = 30 -# self.driver.fdch = 0.00001 -# self.driver.fdchm = 0.000001 -# self.driver.ctlmin = 0.01 -# self.driver.delfun = 0.001 -# -# # NEWSUMT-specific Settings -# #self.driver.itmax = 10 -# -# # COBYLA-specific Settings -# #self.driver.rhobeg = 1.0 -# #self.driver.rhoend = 1.0e-4 -# #self.driver.maxfun = 1000 -# -# # SLSQP-specific Settings -# #self.driver.accuracy = 1.0e-6 -# #self.driver.maxiter = 50 -# -# # Genetic-specific Settings -# #self.driver.population_size = 90 -# #self.driver.crossover_rate = 0.9 -# #self.driver.mutation_rate = 0.02 -# #self.selection_method = 'rank'