@@ -64,19 +64,18 @@ def getOptimalObjective(self):
6464
6565# A subclass of BOAlgorithmBase implementing a full Bayesian Optimization workflow
6666class BOAlgorithm (BOAlgorithmBase ):
67- def __init__ (self , gpsurrogate , xtrain , ytrain ,
67+ def __init__ (self , prob : Problem , gpsurrogate : GaussianProcess , xtrain , ytrain ,
6868 user_grad = None ,
69- user_constraints = None ,
7069 options = None ):
7170 super ().__init__ ()
7271
7372 assert isinstance (gpsurrogate , GaussianProcess )
7473
7574 self .setTrainingData (xtrain , ytrain )
75+ self .prob = prob
7676 self .gpsurrogate = gpsurrogate
7777 self .bounds = self .gpsurrogate .get_bounds ()
7878 self .fun_grad = None
79- self .constraints = None
8079
8180 if options and 'bo_maxiter' in options :
8281 self .bo_maxiter = options ['bo_maxiter' ]
@@ -101,16 +100,13 @@ def __init__(self, gpsurrogate, xtrain, ytrain,
101100 opt_solver = "SLSQP"
102101 self .set_method (opt_solver )
103102
104- if user_constraints :
105- self .constraints = user_constraints
106-
107103 if user_grad :
108104 self .fun_grad = user_grad
109105
110106
111107 # Method to set up a callback function to minimize the acquisition function
112108 def _setup_acqf_minimizer_callback (self ):
113- self .acqf_minimizer_callback = lambda fun , x0 : minimizer (fun , x0 , self .opt_solver , self .bounds , self .constraints , self .solver_options )
109+ self .acqf_minimizer_callback = lambda fun , x0 : minimizer (fun , x0 , self .opt_solver , self .bounds , self .prob . constraints , self .solver_options )
114110
115111 # Method to train the GP model
116112 def _train_surrogate (self , x_train , y_train ):
@@ -164,8 +160,7 @@ def set_options(self, solver_options):
164160 self .solver_options = solver_options
165161
166162 # Method to perform Bayesian optimization
167- def optimize (self , prob :Problem ):
168- self .prob = prob
163+ def optimize (self ):
169164 x_train = self .xtrain
170165 y_train = self .ytrain
171166
@@ -184,7 +179,7 @@ def optimize(self, prob:Problem):
184179 x_new = self ._find_best_point (x_train , y_train )
185180
186181 # Evaluate the new sample point
187- y_new = prob .evaluate (np .atleast_2d (x_new ))
182+ y_new = self . prob .evaluate (np .atleast_2d (x_new ))
188183
189184 # Update training set
190185 x_train = np .vstack ([x_train , x_new ])
@@ -229,8 +224,8 @@ def minimizer(fun, x0, method, bounds, constraints, solver_options):
229224 ipopt_prob = IpoptProb (fun ['obj' ], fun ['grad' ], constraints , bounds , solver_options )
230225 sol , info = ipopt_prob .solve (x0 )
231226
232- status = info .get ('status' , - 1 )
233- msg = info .get ('status_msg' , - 1 )
227+ status = info .get ('status' , - 999 )
228+ msg = info .get ('status_msg' , b'unknown error' )
234229 if status == 0 :
235230 # ipopt returns 0 as success
236231 success = True
0 commit comments