From 6a7eb01ebd2d1698f7f3cc179456481370470172 Mon Sep 17 00:00:00 2001 From: Elizabeth Santorella Date: Tue, 25 Jul 2023 18:23:50 -0400 Subject: [PATCH 1/4] Added debug statements --- botorch/optim/core.py | 6 +++++- test/optim/test_core.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/botorch/optim/core.py b/botorch/optim/core.py index 97afdb59f1..64c4612dae 100644 --- a/botorch/optim/core.py +++ b/botorch/optim/core.py @@ -98,9 +98,11 @@ def scipy_minimize( call_counter = count(1) # callbacks are typically made at the end of each iter def wrapped_callback(x: ndarray): + fval = float(wrapped_closure(x)[0]) + print(f"{fval=}") result = OptimizationResult( step=next(call_counter), - fval=float(wrapped_closure(x)[0]), + fval=fval, status=OptimizationStatus.RUNNING, runtime=monotonic() - start_time, ) @@ -116,6 +118,8 @@ def wrapped_callback(x: ndarray): callback=wrapped_callback, timeout_sec=timeout_sec, ) + print(f"{raw=}") + print(f"{raw.message=}") # Post-processing and outcome handling wrapped_closure.state = asarray(raw.x) # set parameter state to optimal values diff --git a/test/optim/test_core.py b/test/optim/test_core.py index c9734ba40c..7ec173b4db 100644 --- a/test/optim/test_core.py +++ b/test/optim/test_core.py @@ -83,6 +83,8 @@ def test_timeout(self): # adding a small delay here to combat some timing issues on windows closure = partial(norm_squared, x, delay=1e-3) result = scipy_minimize(closure, {"x": x}, timeout_sec=1e-4) + print(f"{result=}") + print(f"{result.message=}") self.assertEqual(result.status, OptimizationStatus.STOPPED) self.assertTrue("Optimization timed out after" in result.message) From dc57c176d142546b7ae7b52404f04e13858dc2ff Mon Sep 17 00:00:00 2001 From: Elizabeth Santorella Date: Tue, 25 Jul 2023 18:51:53 -0400 Subject: [PATCH 2/4] print more --- botorch/optim/utils/timeout.py | 1 + 1 file changed, 1 insertion(+) diff --git a/botorch/optim/utils/timeout.py b/botorch/optim/utils/timeout.py index 474d0d52c4..faffcbba83 100644 --- a/botorch/optim/utils/timeout.py +++ b/botorch/optim/utils/timeout.py @@ -46,6 +46,7 @@ def minimize_with_timeout( def timeout_callback(xk: np.ndarray) -> bool: runtime = time.monotonic() - start_time + print(f"{runtime=}") callback_data["num_iterations"] += 1 if runtime > timeout_sec: raise OptimizationTimeoutError(current_x=xk, runtime=runtime) From 5ce0fc32f18c3cd119192883baaf4390fb7022ce Mon Sep 17 00:00:00 2001 From: Elizabeth Santorella Date: Tue, 25 Jul 2023 19:07:52 -0400 Subject: [PATCH 3/4] Try longer delay --- test/optim/test_core.py | 2 +- test/optim/utils/test_timeout.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/optim/test_core.py b/test/optim/test_core.py index 7ec173b4db..d4c13b7f18 100644 --- a/test/optim/test_core.py +++ b/test/optim/test_core.py @@ -81,7 +81,7 @@ def test_basic(self): def test_timeout(self): x = Parameter(torch.tensor(1.0)) # adding a small delay here to combat some timing issues on windows - closure = partial(norm_squared, x, delay=1e-3) + closure = partial(norm_squared, x, delay=1e-2) result = scipy_minimize(closure, {"x": x}, timeout_sec=1e-4) print(f"{result=}") print(f"{result.message=}") diff --git a/test/optim/utils/test_timeout.py b/test/optim/utils/test_timeout.py index 8a8a1b7aec..725bb4329d 100644 --- a/test/optim/utils/test_timeout.py +++ b/test/optim/utils/test_timeout.py @@ -41,7 +41,7 @@ def f_and_g(x: np.ndarray, sleep_sec: float = 0.0): self.assertEqual(res.nit, 2) # quadratic approx. is exact with self.subTest("test w/ binding timeout"): - res = minimize_with_timeout(**base_kwargs, args=(1e-3,), timeout_sec=1e-4) + res = minimize_with_timeout(**base_kwargs, args=(1e-2,), timeout_sec=1e-4) self.assertFalse(res.success) self.assertEqual(res.nit, 1) # only one call to the callback is made From 2d72246dce8b245c0c76e4807337affd3f893a65 Mon Sep 17 00:00:00 2001 From: Elizabeth Santorella Date: Wed, 26 Jul 2023 15:20:18 -0400 Subject: [PATCH 4/4] remove print statements --- botorch/optim/core.py | 6 +----- botorch/optim/utils/timeout.py | 1 - test/optim/test_core.py | 2 -- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/botorch/optim/core.py b/botorch/optim/core.py index 64c4612dae..97afdb59f1 100644 --- a/botorch/optim/core.py +++ b/botorch/optim/core.py @@ -98,11 +98,9 @@ def scipy_minimize( call_counter = count(1) # callbacks are typically made at the end of each iter def wrapped_callback(x: ndarray): - fval = float(wrapped_closure(x)[0]) - print(f"{fval=}") result = OptimizationResult( step=next(call_counter), - fval=fval, + fval=float(wrapped_closure(x)[0]), status=OptimizationStatus.RUNNING, runtime=monotonic() - start_time, ) @@ -118,8 +116,6 @@ def wrapped_callback(x: ndarray): callback=wrapped_callback, timeout_sec=timeout_sec, ) - print(f"{raw=}") - print(f"{raw.message=}") # Post-processing and outcome handling wrapped_closure.state = asarray(raw.x) # set parameter state to optimal values diff --git a/botorch/optim/utils/timeout.py b/botorch/optim/utils/timeout.py index faffcbba83..474d0d52c4 100644 --- a/botorch/optim/utils/timeout.py +++ b/botorch/optim/utils/timeout.py @@ -46,7 +46,6 @@ def minimize_with_timeout( def timeout_callback(xk: np.ndarray) -> bool: runtime = time.monotonic() - start_time - print(f"{runtime=}") callback_data["num_iterations"] += 1 if runtime > timeout_sec: raise OptimizationTimeoutError(current_x=xk, runtime=runtime) diff --git a/test/optim/test_core.py b/test/optim/test_core.py index d4c13b7f18..2dcdfa5b61 100644 --- a/test/optim/test_core.py +++ b/test/optim/test_core.py @@ -83,8 +83,6 @@ def test_timeout(self): # adding a small delay here to combat some timing issues on windows closure = partial(norm_squared, x, delay=1e-2) result = scipy_minimize(closure, {"x": x}, timeout_sec=1e-4) - print(f"{result=}") - print(f"{result.message=}") self.assertEqual(result.status, OptimizationStatus.STOPPED) self.assertTrue("Optimization timed out after" in result.message)