Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi trust regions #773

Merged
merged 41 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
905dc14
multiTR with notebook
May 18, 2023
5c27203
notebook
May 18, 2023
e46150d
multi local step TREGO
Jun 2, 2023
ceadabe
Merge branch 'develop' into victor/trustregions
hstojic Jun 21, 2023
990b6cd
merged latest develop
hstojic Jun 30, 2023
ebe27f4
Refactor multi trust region implementation
khurram-ghani Jun 2, 2023
3ff37fe
Merge remote-tracking branch 'origin/develop' into khurram/trustregions
khurram-ghani Jul 26, 2023
683eacc
Fix formatting in notebook & remove orig TR changes
khurram-ghani Jul 26, 2023
809153c
Remove redundant new assert
khurram-ghani Jul 26, 2023
b6ee392
Undo earlier logging change
khurram-ghani Jul 26, 2023
fcc16e2
Workaround isort & black clash
khurram-ghani Jul 26, 2023
9f21527
Keep old ver of mypy happy
khurram-ghani Jul 26, 2023
1762d82
Fix typo in slicing
khurram-ghani Jul 26, 2023
535dbb1
Add new collection space tests
khurram-ghani Jul 27, 2023
5b97508
Merge branch 'develop' into khurram/trustregions
khurram-ghani Jul 31, 2023
c4ce7ab
Address feedback plus other small changes
khurram-ghani Aug 2, 2023
20b5687
Merge remote-tracking branch 'origin/develop' into khurram/trustregions
khurram-ghani Aug 2, 2023
0c38efb
Add TrustRegionBox/UpdateableSearchSpace unittests
khurram-ghani Aug 2, 2023
309ef09
Address feedback for space changes
khurram-ghani Aug 3, 2023
d58306e
Some updates to rule/utils from feedback
khurram-ghani Aug 4, 2023
c2abf11
Create subspaces outside the rule
khurram-ghani Aug 7, 2023
12c8f1f
Fix func to work with old tensorflow
khurram-ghani Aug 7, 2023
3c725bd
Add rule and optimizer unit tests
khurram-ghani Aug 7, 2023
be06c63
Add integ test
khurram-ghani Aug 8, 2023
a313bf8
Merge branch 'develop' into khurram/trustregions
khurram-ghani Aug 8, 2023
0706656
Add shape-checking/docstring for mask func
khurram-ghani Aug 8, 2023
9def562
Add check_shapes, update docstrings & add tag test
khurram-ghani Aug 8, 2023
0973630
Remove notebook, to be added in separate PR
khurram-ghani Aug 8, 2023
01f370b
Add deepcopy test
khurram-ghani Aug 8, 2023
dad0936
Merge remote-tracking branch 'origin/develop' into khurram/trustregions
khurram-ghani Aug 9, 2023
66b4aa4
Check TR copy is deep
khurram-ghani Aug 9, 2023
9bb6a80
Improve TR box and test slightly
khurram-ghani Aug 10, 2023
4924557
Address Uri's latest comments
khurram-ghani Aug 21, 2023
f0e125d
Move get_value_for_tag to more general utils/misc
khurram-ghani Aug 21, 2023
3daa81f
Remove redundant [] checks
khurram-ghani Aug 21, 2023
0b19246
Add fixture for default search space type
khurram-ghani Aug 21, 2023
044f07c
Add test for optim multiple boxes as a batch
khurram-ghani Aug 22, 2023
8ca39e9
Rename classes and expand some docstrings
khurram-ghani Aug 22, 2023
ef62eeb
Choose longer class name
khurram-ghani Aug 24, 2023
5634c85
Merge branch 'develop' into khurram/trustregions
khurram-ghani Aug 25, 2023
8f17839
Rename updatable class name
khurram-ghani Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/integration/test_bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
AsynchronousOptimization,
AsynchronousRuleState,
BatchHypervolumeSharpeRatioIndicator,
BatchTrustRegionBox,
DiscreteThompsonSampling,
EfficientGlobalOptimization,
SingleObjectiveTrustRegionBox,
TrustRegion,
)
from trieste.acquisition.sampler import ThompsonSamplerFromTrajectory
Expand Down Expand Up @@ -197,6 +199,17 @@ def GPR_OPTIMIZER_PARAMS() -> Tuple[str, List[ParameterSet]]:
TURBO(ScaledBranin.search_space, rule=DiscreteThompsonSampling(500, 3)),
id="Turbo",
),
pytest.param(
10,
BatchTrustRegionBox(
[SingleObjectiveTrustRegionBox(ScaledBranin.search_space) for _ in range(3)],
EfficientGlobalOptimization(
ParallelContinuousThompsonSampling(),
num_query_points=3,
),
),
id="BatchTrustRegionBox",
),
pytest.param(15, DiscreteThompsonSampling(500, 5), id="DiscreteThompsonSampling"),
pytest.param(
15,
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/acquisition/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
DiscreteSearchSpace,
LinearConstraint,
SearchSpace,
TaggedMultiSearchSpace,
TaggedProductSearchSpace,
)
from trieste.types import TensorType
Expand Down Expand Up @@ -203,6 +204,40 @@ def test_optimize_continuous_raises_with_invalid_vectorized_batch_size(batch_siz
generate_continuous_optimizer()(search_space, (acq_fn, batch_size))


def test_optimize_continuous_raises_with_mismatch_multi_search_space() -> None:
khurram-ghani marked this conversation as resolved.
Show resolved Hide resolved
space_A = Box([-1], [2])
space_B = Box([3], [4])
multi_space = TaggedMultiSearchSpace(spaces=[space_A, space_B])
acq_fn = _quadratic_sum([1.0])
with pytest.raises(TF_DEBUGGING_ERROR_TYPES, match="The batch shape of initial samples 2 must"):
generate_continuous_optimizer()(multi_space, acq_fn)


def test_optimize_continuous_finds_points_in_multi_search_space_boxes() -> None:
# Test with non-overlapping grid of 2D boxes. Optimize them as a batch and check that each
# point is only in the corresponding box.
boxes = [Box([x, y], [x + 0.7, y + 0.7]) for x in range(-2, 2) for y in range(-2, 2)]
multi_space = TaggedMultiSearchSpace(spaces=boxes)
batch_size = len(boxes)

def target_function(x: TensorType) -> TensorType: # [N, V, D] -> [N, V]
individual_func = [_quadratic_sum([1.0])(x[:, i : i + 1, :]) for i in range(batch_size)]
return tf.concat(individual_func, axis=-1) # vectorize by repeating same function

optimizer = generate_continuous_optimizer()
optimizer = batchify_vectorize(optimizer, batch_size)
max_points = optimizer(multi_space, target_function)

# Ensure order of points is the same as the order of boxes and that each point is only in the
# corresponding box.
for i, point in enumerate(max_points):
for j, box in enumerate(boxes):
if i == j:
assert point in box
else:
assert point not in box


@pytest.mark.parametrize("num_optimization_runs", [1, 10])
@pytest.mark.parametrize("num_initial_samples", [1000, 5000])
def test_optimize_continuous_correctly_uses_init_params(
Expand Down
Loading