Skip to content

Commit 7a87380

Browse files
committed
Gracefully handle TRS error in geometry steps for #23
1 parent ff95fd3 commit 7a87380

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pybobyqa/controller.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,18 @@ def geometry_step(self, knew, adelt, number_of_samples, params):
287287
module_logger.debug("Running geometry-fixing step")
288288
try:
289289
c, g, H = self.model.lagrange_polynomial(knew) # based at xopt
290-
# Solve problem: bounds are sl <= xnew <= su, and ||xnew-xopt|| <= adelt
291-
xnew = trsbox_geometry(self.model.xopt(), c, g, H, self.model.sl, self.model.su, adelt)
292290
except LA.LinAlgError:
293291
exit_info = ExitInformation(EXIT_LINALG_ERROR, "Singular matrix encountered in geometry step")
294292
return exit_info # didn't fix geometry - return & quit
293+
294+
# Solve problem: bounds are sl <= xnew <= su, and ||xnew-xopt|| <= adelt
295+
try:
296+
xnew = trsbox_geometry(self.model.xopt(), c, g, H, self.model.sl, self.model.su, adelt)
297+
except ValueError:
298+
# A ValueError may be raised if gopt or H have nan/inf values (issue #23)
299+
# Ideally this should be picked up earlier in self.model.lagrange_polynomial(...)
300+
exit_info = ExitInformation(EXIT_LINALG_ERROR, "Error when calculating geometry-improving step")
301+
return exit_info # didn't fix geometry - return & quit
295302

296303
gopt, H = self.model.build_full_model() # save here, to calculate predicted value from geometry step
297304
fopt = self.model.fopt() # again, evaluate now, before model.change_point()

0 commit comments

Comments
 (0)