Skip to content

Extend projection to nonlinear inequality constraints#3316

Open
MrzvskK wants to merge 1 commit into
meta-pytorch:mainfrom
MrzvskK:3280-nonlinear-inequality-projection
Open

Extend projection to nonlinear inequality constraints#3316
MrzvskK wants to merge 1 commit into
meta-pytorch:mainfrom
MrzvskK:3280-nonlinear-inequality-projection

Conversation

@MrzvskK
Copy link
Copy Markdown

@MrzvskK MrzvskK commented Jun 4, 2026

Motivation

Related to #3280.

gen_candidates_scipy already supports nonlinear_inequality_constraints via make_scipy_nonlinear_inequality_constraints, but project_to_feasible_space_via_slsqp only handled linear constraints. After optimization, _optimize_acqf_batch checks feasibility (including nonlinear inequalities) but previously skipped projection whenever nonlinear constraints were present, so slightly infeasible candidates could remain infeasible or trigger errors.

This PR extends projection to nonlinear inequality constraints using the same SciPy path as gen_candidates_scipy, as suggested in the #3280 discussion.

Changes:

botorch/optim/parameter_constraints.py

  • Add nonlinear_inequality_constraints argument to project_to_feasible_space_via_slsqp.
  • Build SciPy constraints with make_scipy_nonlinear_inequality_constraints (same helper as gen_candidates_scipy).
  • Add _get_f_np_wrapper_for_projection so projection can evaluate constraint values/Jacobians without importing gen.py (avoids circular imports).
  • Add validate_feasibility: bool = True to make_scipy_nonlinear_inequality_constraints (default unchanged). Projection passes validate_feasibility=False because repair starts from infeasible points; IC validation behavior is unchanged.
  • Normalize shapeX with _validate_linear_constraints_shape_input for consistent (b, q, d) handling.

botorch/optim/optimize.py

  • Remove the guard that skipped projection when nonlinear_inequality_constraints is not None.
  • Pass nonlinear_inequality_constraints into project_to_feasible_space_via_slsqp for infeasible batches.

Tests

  • test_project_to_feasible_space_via_slsqp_nonlinear: unit disk + half-plane; slightly infeasible point projected to feasibility; linear + nonlinear combo.
  • Update test_optimize_acqf_projection_applied_with_nonlinear_constraints to expect projection is applied and linear constraints are repaired.

Have you read the Contributing Guidelines on pull requests?

Yes. First BoTorch contribution — happy to adjust based on review.

Test Plan

  • pytest test/optim/test_parameter_constraints.py::TestProjectToFeasibleSpace::test_project_to_feasible_space_via_slsqp_nonlinear -v
    Unit disk + half-plane; slightly infeasible point projected to feasibility; linear + nonlinear combo.

  • pytest test/optim/test_parameter_constraints.py test/optim/test_optimize.py -v
    Broader regression (75 passed locally).

  • test_optimize_acqf_projection_applied_with_nonlinear_constraints: projection runs when nonlinear constraints are present; linear inequalities repaired.

  • Compared pytest warnings with/without this diff on the above test files: 117 warnings, unchanged (no new warnings from these changes; existing RuntimeWarnings from retry/IC mocks, etc.).

Notes for reviewers

  • Convention unchanged: nonlinear inequalities are callable(x) >= 0, with the same (callable, is_intrapoint) tuple format as optimize_acqf.
  • Projection objective remains minimum-distance (½‖x - x₀‖²) with SLSQP, consistent with existing linear repair.

Related PRs

N/A


/cc @esantorella @jduerholt FYI for the discussion in #3280

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Jun 4, 2026

Hi @MrzvskK!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Jun 4, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jun 4, 2026
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Jun 4, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant