Skip to content

Commit

Permalink
Add timeout ability to gen_* functions (facebook#1562)
Browse files Browse the repository at this point in the history
Summary:
X-link: pytorch/botorch#1562

Exposes the ability to pass a `timeout_sec` kwarg to `gen_candidates_scipy` and `gen_candidates_torch` that allows to stop the optimization after running for more than `timeout_sec` seconds.

Reviewed By: esantorella

Differential Revision: D42024857

fbshipit-source-id: 0d4d96a7f17161993775a777b8b148fdcb149017
  • Loading branch information
Balandat authored and facebook-github-bot committed Dec 30, 2022
1 parent c6c67d8 commit 51de25e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ax/utils/testing/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from typing import Callable, Generator
from unittest import mock

from botorch.generation.gen import minimize_with_timeout

from botorch.optim.initializers import (
gen_batch_initial_conditions,
gen_one_shot_kg_initial_conditions,
)
from scipy.optimize import minimize


@contextmanager
Expand All @@ -29,7 +30,7 @@ def one_iteration_minimize(*args, **kwargs):
kwargs["options"] = {}

kwargs["options"]["maxiter"] = 1
return minimize(*args, **kwargs)
return minimize_with_timeout(*args, **kwargs)

# pyre-fixme[3]: Return type must be annotated.
# pyre-fixme[2]: Parameter must be annotated.
Expand All @@ -50,7 +51,7 @@ def minimal_gen_os_ics(*args, **kwargs):
with ExitStack() as es:
mock_generation = es.enter_context(
mock.patch(
"botorch.generation.gen.minimize",
"botorch.generation.gen.minimize_with_timeout",
wraps=one_iteration_minimize,
)
)
Expand Down

0 comments on commit 51de25e

Please sign in to comment.