Skip to content

Commit

Permalink
Handle case where the PF set is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
roussel-ryan committed Sep 19, 2024
1 parent b001267 commit 90c42b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions xopt/generators/bayesian/bayesian_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,21 @@ def get_pareto_front(self):
(self.torch_reference_point.unsqueeze(0), objective_data)
)
var_data = torch.vstack(
(torch.zeros_like(variable_data[0]).unsqueeze(0), variable_data)
(
torch.full_like(variable_data[0], float("Nan")).unsqueeze(0),
variable_data,
)
)
non_dominated = is_non_dominated(obj_data)

weights = set_botorch_weights(self.vocs).to(**self._tkwargs)

# note need to undo weights for real number output
return var_data[non_dominated], obj_data[non_dominated] / weights
# only return values if non nan values exist
if torch.all(torch.isnan(var_data[non_dominated])):
return None, None
else:
return var_data[non_dominated], obj_data[non_dominated] / weights


def formatted_base_docstring():
Expand Down
6 changes: 6 additions & 0 deletions xopt/generators/bayesian/mobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def _get_initial_conditions(self, n_candidates=1) -> Union[Tensor, None]:
num_restarts = self.numerical_optimizer.n_restarts

pf_locations, _ = self.get_pareto_front()

# if there is no pareto front just return None to revert back to
# default behavior
if pf_locations is None:
return None

initial_points = torch.clone(pf_locations)

# add the q dimension
Expand Down
9 changes: 9 additions & 0 deletions xopt/tests/generators/bayesian/test_mobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ def test_initial_conditions(self):
assert len(initial_points) == 1
gen.generate(1)

# try with no points on the pareto front
gen.reference_point = {"y1": 0.0, "y2": 0.0}
gen.numerical_optimizer.n_restarts = 20

initial_points = gen._get_initial_conditions()
assert initial_points is None
gen.generate(1)

def test_log_mobo(self):
evaluator = Evaluator(function=evaluate_TNK)
reference_point = tnk_reference_point
Expand All @@ -175,6 +183,7 @@ def test_log_mobo(self):
dump = ele.model_dump()
generator = MOBOGenerator(vocs=tnk_vocs, **dump)
X = Xopt(generator=generator, evaluator=evaluator, vocs=tnk_vocs)
X.generator.numerical_optimizer.max_iter = 1
X.random_evaluate(3)
X.step()

Expand Down

0 comments on commit 90c42b3

Please sign in to comment.