Skip to content

Commit

Permalink
KeyboardInterrupt tests
Browse files Browse the repository at this point in the history
KeyboardInterrupt tests now cover both scipy optimization and tf
optimization.
  • Loading branch information
jameshensman committed Mar 29, 2016
1 parent 3e4ed1b commit 5bdd8ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GPflow/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _optimize_np(self, method='L-BFGS-B', callback=None, max_iters=1000, **kw):
tol=None, # TODO: tol??
callback=callback,
options=options)
except (KeyboardInterrupt): # pragma: no cover
except (KeyboardInterrupt):
print("Caught KeyboardInterrupt, setting model with most recent state.")
self.set_state(obj._previous_x)
return None
Expand Down
10 changes: 9 additions & 1 deletion testing/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,22 @@ def setUp(self):
Z = np.random.randn(100, 3)
self.m = GPflow.sgpr.SGPR(X, Y, Z=Z, kern=GPflow.kernels.RBF(3))

def test(self):
def test_optimize_np(self):
x0 = self.m.get_free_state()
self.m._compile()
self.m._objective = KeyboardRaiser(15, self.m._objective)
self.m.optimize(display=0, max_iters=10000, ftol=0, gtol=0)
x1 = self.m.get_free_state()
self.failIf(np.allclose(x0, x1))

def test_optimize_tf(self):
x0 = self.m.get_free_state()
callback = KeyboardRaiser(5, lambda x: None)
o = tf.train.AdamOptimizer()
self.m.optimize(o, max_iters=15, callback=callback)
x1 = self.m.get_free_state()
self.failIf(np.allclose(x0, x1))


if __name__ == "__main__":
unittest.main()
Expand Down

0 comments on commit 5bdd8ef

Please sign in to comment.