@@ -92,12 +92,12 @@ def able_to_do_restart(self):
9292
9393
9494class Controller (object ):
95- def __init__ (self , objfun , x0 , args , f0 , f0_nsamples , xl , xu , npt , rhobeg , rhoend , nf , nx , maxfun , params , scaling_changes ):
95+ def __init__ (self , objfun , x0 , args , f0 , f0_nsamples , xl , xu , npt , rhobeg , rhoend , nf , nx , maxfun , params , scaling_changes , do_logging = True ):
9696 self .objfun = objfun
9797 self .maxfun = maxfun
9898 self .args = args
9999 self .model = Model (npt , x0 , f0 , xl , xu , f0_nsamples , abs_tol = params ("model.abs_tol" ),
100- precondition = params ("interpolation.precondition" ))
100+ precondition = params ("interpolation.precondition" ), do_logging = do_logging )
101101 self .nf = nf
102102 self .nx = nx
103103 self .rhobeg = rhobeg
@@ -121,6 +121,7 @@ def __init__(self, objfun, x0, args, f0, f0_nsamples, xl, xu, npt, rhobeg, rhoen
121121 self .total_unsuccessful_restarts = 0
122122 self .last_run_fopt = f0
123123 self .scaling_changes = scaling_changes
124+ self .do_logging = do_logging
124125
125126 def n (self ):
126127 return self .model .n ()
@@ -129,7 +130,8 @@ def npt(self):
129130 return self .model .npt ()
130131
131132 def initialise_coordinate_directions (self , number_of_samples , num_directions , params ):
132- logging .debug ("Initialising with coordinate directions" )
133+ if self .do_logging :
134+ logging .debug ("Initialising with coordinate directions" )
133135 # self.model already has x0 evaluated, so only need to initialise the other points
134136 # num_directions = params("growing.ndirs_initial")
135137 assert self .model .num_pts <= (self .n () + 1 ) * (self .n () + 2 ) // 2 , "prelim: must have npt <= (n+1)(n+2)/2"
@@ -202,7 +204,8 @@ def initialise_coordinate_directions(self, number_of_samples, num_directions, pa
202204 return None # return & continue
203205
204206 def initialise_random_directions (self , number_of_samples , num_directions , params ):
205- logging .debug ("Initialising with random orthogonal directions" )
207+ if self .do_logging :
208+ logging .debug ("Initialising with random orthogonal directions" )
206209 # self.model already has x0 evaluated, so only need to initialise the other points
207210 # num_directions = params("growing.ndirs_initial")
208211 assert 1 <= num_directions < self .model .num_pts , "Initialisation: must have 1 <= ndirs_initial < npt"
@@ -270,7 +273,8 @@ def trust_region_step(self):
270273 return d , gopt , H , gnew , crvmin
271274
272275 def geometry_step (self , knew , adelt , number_of_samples , params ):
273- logging .debug ("Running geometry-fixing step" )
276+ if self .do_logging :
277+ logging .debug ("Running geometry-fixing step" )
274278 try :
275279 c , g , H = self .model .lagrange_polynomial (knew ) # based at xopt
276280 # Solve problem: bounds are sl <= xnew <= su, and ||xnew-xopt|| <= adelt
@@ -344,7 +348,8 @@ def evaluate_objective(self, x, number_of_samples, params):
344348 incremented_nx = True
345349 f_list [i ] = eval_objective (self .objfun , remove_scaling (x , self .scaling_changes ), self .args , eval_num = self .nf , pt_num = self .nx ,
346350 full_x_thresh = params ("logging.n_to_print_whole_x_vector" ),
347- check_for_overflow = params ("general.check_objfun_for_overflow" ))
351+ check_for_overflow = params ("general.check_objfun_for_overflow" ),
352+ verbose = self .do_logging )
348353 num_samples_run += 1
349354
350355 # Check if the average value was below our threshold
@@ -453,11 +458,13 @@ def terminate_from_slow_iterations(self, current_iter, params):
453458 # Update counter of number of slow iterations
454459 if this_iter_slow :
455460 self .num_slow_iters += 1
456- logging .info ("Slow iteration (%g consecutive so far, max allowed %g)"
461+ if self .do_logging :
462+ logging .info ("Slow iteration (%g consecutive so far, max allowed %g)"
457463 % (self .num_slow_iters , params ("slow.max_slow_iters" )))
458464 else :
459465 self .num_slow_iters = 0
460- logging .debug ("Non-slow iteration" )
466+ if self .do_logging :
467+ logging .debug ("Non-slow iteration" )
461468 return this_iter_slow , self .num_slow_iters >= params ("slow.max_slow_iters" )
462469
463470 def soft_restart (self , number_of_samples , nruns_so_far , params , x_in_abs_coords_to_save = None , f_to_save = None ,
@@ -491,7 +498,8 @@ def soft_restart(self, number_of_samples, nruns_so_far, params, x_in_abs_coords_
491498 self .model .save_point (self .model .xopt (abs_coordinates = True ), self .model .fopt (),
492499 self .model .nsamples [self .model .kopt ], x_in_abs_coords = True )
493500
494- logging .info ("Soft restart [currently, f = %g after %g function evals]" % (self .model .fopt (), self .nf ))
501+ if self .do_logging :
502+ logging .info ("Soft restart [currently, f = %g after %g function evals]" % (self .model .fopt (), self .nf ))
495503 # Resetting method: reset delta and rho, then move the closest 'num_steps' points to xk to improve geometry
496504 # Note: closest points because we are suddenly increasing delta & rho, so we want to encourage spreading out points
497505 self .delta = self .rhobeg
0 commit comments