Skip to content

Commit

Permalink
Loopifying conditional kwarg processing in _optimize_acqf_batch (#1923
Browse files Browse the repository at this point in the history
)

Summary:
Pull Request resolved: #1923

Small code simplification, pattern could be reused elsewhere for `kwarg` processing, particularly where a number of fields have to be check.

Reviewed By: esantorella

Differential Revision: D47297929

fbshipit-source-id: 07574fef862b9e0b06d0f66b1004738e9dcd061f
  • Loading branch information
SebastianAment authored and facebook-github-bot committed Jul 10, 2023
1 parent eb1768c commit 1d077c9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions botorch/optim/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,13 @@ def _optimize_batch_candidates() -> Tuple[Tensor, Tensor, List[Warning]]:

# only add parameter constraints to gen_kwargs if they are specified
# to avoid unnecessary warnings in _filter_kwargs
if opt_inputs.inequality_constraints is not None:
gen_kwargs["inequality_constraints"] = opt_inputs.inequality_constraints
if opt_inputs.equality_constraints is not None:
gen_kwargs["equality_constraints"] = opt_inputs.equality_constraints
if opt_inputs.nonlinear_inequality_constraints is not None:
gen_kwargs[
"nonlinear_inequality_constraints"
] = opt_inputs.nonlinear_inequality_constraints
for constraint_name in [
"inequality_constraints",
"equality_constraints",
"nonlinear_inequality_constraints",
]:
if (constraint := getattr(opt_inputs, constraint_name)) is not None:
gen_kwargs[constraint_name] = constraint

filtered_gen_kwargs = _filter_kwargs(opt_inputs.gen_candidates, **gen_kwargs)

Expand Down

0 comments on commit 1d077c9

Please sign in to comment.