Skip to content

Commit 3b65e18

Browse files
committed
Handle ValueError from TRS solver (fixed #14)
1 parent 2de1d4e commit 3b65e18

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pybobyqa/controller.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,15 @@ def initialise_random_directions(self, number_of_samples, num_directions, params
269269
def trust_region_step(self):
270270
# Build model for full least squares objectives
271271
gopt, H = self.model.build_full_model()
272-
d, gnew, crvmin = trsbox(self.model.xopt(), gopt, H, self.model.sl, self.model.su, self.delta)
272+
try:
273+
d, gnew, crvmin = trsbox(self.model.xopt(), gopt, H, self.model.sl, self.model.su, self.delta)
274+
except ValueError:
275+
# A ValueError may be raised if gopt or H have nan/inf values (issue #14)
276+
# Although this should be picked up earlier, in this situation just return a zero
277+
# trust-region step, which leads to a safety step being called in the main algorithm.
278+
d = np.zeros(gopt.shape)
279+
gnew = gopt.copy()
280+
crvmin = 0.0 # this usually represents 'step on trust-region boundary' but seems to be a sensible default for errors
273281
return d, gopt, H, gnew, crvmin
274282

275283
def geometry_step(self, knew, adelt, number_of_samples, params):

0 commit comments

Comments
 (0)