Skip to content

Commit

Permalink
Gracefully handle TRS error in geometry steps for #23
Browse files Browse the repository at this point in the history
  • Loading branch information
lindonroberts committed Nov 10, 2021
1 parent ff95fd3 commit 7a87380
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pybobyqa/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,18 @@ def geometry_step(self, knew, adelt, number_of_samples, params):
module_logger.debug("Running geometry-fixing step")
try:
c, g, H = self.model.lagrange_polynomial(knew) # based at xopt
# Solve problem: bounds are sl <= xnew <= su, and ||xnew-xopt|| <= adelt
xnew = trsbox_geometry(self.model.xopt(), c, g, H, self.model.sl, self.model.su, adelt)
except LA.LinAlgError:
exit_info = ExitInformation(EXIT_LINALG_ERROR, "Singular matrix encountered in geometry step")
return exit_info # didn't fix geometry - return & quit

# Solve problem: bounds are sl <= xnew <= su, and ||xnew-xopt|| <= adelt
try:
xnew = trsbox_geometry(self.model.xopt(), c, g, H, self.model.sl, self.model.su, adelt)
except ValueError:
# A ValueError may be raised if gopt or H have nan/inf values (issue #23)
# Ideally this should be picked up earlier in self.model.lagrange_polynomial(...)
exit_info = ExitInformation(EXIT_LINALG_ERROR, "Error when calculating geometry-improving step")
return exit_info # didn't fix geometry - return & quit

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

0 comments on commit 7a87380

Please sign in to comment.