gptune / GPTune

Other
67 stars 19 forks source link

Issue when adjusting working script #20

Closed awil5504 closed 9 months ago

awil5504 commented 9 months ago

Hi,

I have been using GPTune to get algorithm parameters in an ocean model with great results. I recently did a tuning run where my objective function is

def objectives(point): nodes = point['nodes'] cores = point['cores']

maxiter = point['itmax']

scale_fet = point['scale_fet']
scale_o2 = point['scale_o2']
scale_alk = point['scale_alk']
scale_dic = point['scale_dic']

params = [nodes,cores,maxiter,scale_fet,scale_o2,scale_alk,scale_dic]

############################################################
# Call mitgcm bling function here using driver, within driver use mpirun in Lite Mode 
err, co2_flux = mitgcm_driver_lite(params)
############################################################

dic = err[0]
alk = err[1]
no3 = err[3]
# WHAT TO RETURN? CO2 FLUX?
return [dic, alk, no3, co2_flux]

For this run my output space was defined by OS = Space([dic, alk, no3, co2_flux])

After the good results with this run, I attempted to do another run where the only objective is the co2 flux (this is all that would be available in practice). I updated the output space to be

OS = Space([co2_flux])

and tried to run again, but ran into the following error at the point when GPTune switches from sampling to search phase:

Traceback (most recent call last): File "/data/eart-tmm/sedm6691/GPTUNE_LITE/GPTune/examples/Bling/Bling_lite_test.py", line 207, in main() File "/data/eart-tmm/sedm6691/GPTUNE_LITE/GPTune/examples/Bling/Bling_lite_test.py", line 169, in main (data, modeler, stats) = gptune.MLA(NS=nrun, NS1=int(NS/2), NI=NI, Tgiven=giventask) File "/data/eart-tmm/sedm6691/GPTUNELITE/GPTune/GPTune/gptune.py", line 1459, in MLA return self.MLA(NS, NS1, NI, Tgiven, T_sampleflag=[True]*NI, function_evaluations=None, source_function_evaluations=None, models_transfer=None,mfs=mfs) File "/data/eart-tmm/sedm6691/GPTUNELITE/GPTune/GPTune/gptune.py", line 781, in MLA tmpO = self.computer.evaluate_objective(self.problem, self.data.I, tmpP, self.data.D, self.historydb, options = kwargs, is_pilot=is_pilot) File "/data/eart-tmm/sedm6691/GPTUNE_LITE/GPTune/examples/Bling/computer.py", line 109, in evaluate_objective tmp = np.array(O2).reshape((len(O2), problem.DO)) ValueError: cannot reshape array of size 20 into shape (5,1)

Is there an issue with my workflow? i.e. is it okay for gptune that I return more things from the objectives function than I use in my output space?

awil5504 commented 9 months ago

As an update, if I return only co2 flux from the objectives function I get the following error, also after the sampling phase:

Iteration: 0 [HistoryDB] Found a history database file loaded function evaluations: 3 modeler: Model_GPy_LCM M:
Name : GP regression Objective : -1.5594832744491418 Number of Parameters : 6 Number of Optimization Parameters : 6 Updates : True Parameters: GP_regression. | value | constraints | priors GPy_GP.variance | 29.05064796902512 | +ve |
GPy_GP.lengthscale | (4,) | +ve |
Gaussian_noise.variance | 9.99184969189735e-06 | 1e-10,1e-05 |
searcher: SearchPyMoo algorithm: nsga2 Traceback (most recent call last): File "/data/eart-tmm/sedm6691/GPTUNE_LITE/GPTune/examples/Bling/Bling_lite_test.py", line 207, in main() File "/data/eart-tmm/sedm6691/GPTUNE_LITE/GPTune/examples/Bling/Bling_lite_test.py", line 169, in main (data, modeler, stats) = gptune.MLA(NS=nrun, NS1=int(NS/2), NI=NI, Tgiven=giventask) File "/data/eart-tmm/sedm6691/GPTUNELITE/GPTune/GPTune/gptune.py", line 1459, in MLA return self.MLA(NS, NS1, NI, Tgiven, T_sampleflag=[True]*NI, function_evaluations=None, source_function_evaluations=None, models_transfer=None,mfs=mfs) File "/data/eart-tmm/sedm6691/GPTUNELITE/GPTune/GPTune/gptune.py", line 965, in MLA res = searcher.search_multitask(data = self.data, models = modelers, tids=tids, **kwargs) File "/data/eart-tmm/sedm6691/GPTUNE_LITE/GPTune/GPTune/search.py", line 93, in search_multitask res = list(map(fun, tids)) File "/data/eart-tmm/sedm6691/GPTUNE_LITE/GPTune/GPTune/search.py", line 594, in search raise Exception(f'Unknown optimization algorithm "{kwargs["search_algo"]}"') Exception: Unknown optimization algorithm "nsga2"

liuyangzhuan commented 9 months ago

When you change OS = Space([dic, alk, no3, co2_flux]) to OS = Space([co2_flux])

you changed the problem for multi-objective tuning to single objective tuning and nsga2 cannot be used anymore. You need to change it to options["search_algo"]='pso' other possible options would be https://github.com/gptune/GPTune/blob/870f1e8d130351cb4d619b11ad039e416526e48b/GPTune/options.py#L79 https://github.com/gptune/GPTune/blob/870f1e8d130351cb4d619b11ad039e416526e48b/GPTune/options.py#L84

awil5504 commented 9 months ago

Ahh understood, I'll try that! Thank you!