Skip to content

Support equality constraints in service layer string parsing (#5174)#5174

Closed
sdaulton wants to merge 2 commits intofacebook:mainfrom
sdaulton:export-D100256487
Closed

Support equality constraints in service layer string parsing (#5174)#5174
sdaulton wants to merge 2 commits intofacebook:mainfrom
sdaulton:export-D100256487

Conversation

@sdaulton
Copy link
Copy Markdown
Contributor

@sdaulton sdaulton commented Apr 17, 2026

Summary:

Add support for parsing equality constraint strings (e.g. "x1 + x2 == 3")
in constraint_from_str. This extends the existing <=/>= parsing to also
accept == as a comparison operator.

  • Add _process_equality_constraint function (analogous to _process_linear_constraint)
    that constructs ParameterConstraint(equality=...).
  • Detect == in constraint_from_str and route to the new function.
  • Reject equality order constraints ("x1 == x2") with a clear error message.
  • Update INVALID_CONSTRAINT_ERROR_MSG to document == support.

Reviewed By: bletham

Differential Revision: D100256487

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

meta-codesync Bot commented Apr 17, 2026

@sdaulton has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100256487.

sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@meta-codesync meta-codesync Bot changed the title Support equality constraints in service layer string parsing Support equality constraints in service layer string parsing (#5174) Apr 17, 2026
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@sdaulton sdaulton force-pushed the export-D100256487 branch from d01e1f8 to c6e6eb9 Compare April 17, 2026 20:08
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:
Pull Request resolved: facebook#5174

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@sdaulton sdaulton force-pushed the export-D100256487 branch from c6e6eb9 to 40ac657 Compare April 17, 2026 20:11
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@sdaulton sdaulton force-pushed the export-D100256487 branch from 40ac657 to 7e1628d Compare April 17, 2026 20:37
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:
Pull Request resolved: facebook#5174

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@sdaulton sdaulton force-pushed the export-D100256487 branch from 7e1628d to 4e8fe60 Compare April 17, 2026 20:41
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 97.77778% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.41%. Comparing base (104693c) to head (e715983).

Files with missing lines Patch % Lines
ax/utils/common/sympy.py 76.92% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #5174    +/-   ##
========================================
  Coverage   96.41%   96.41%            
========================================
  Files         618      619     +1     
  Lines       68882    69008   +126     
========================================
+ Hits        66410    66532   +122     
- Misses       2472     2476     +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 17, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
Summary:
Add support for linear equality constraints (`w^T x == b`) alongside
existing inequality constraints (`w^T x <= b`) in Ax's
`ParameterConstraint` class. This is the first diff in a stack that
threads equality constraints all the way down to BoTorch's
`optimize_acqf`.

Changes:
- Add `extract_coefficient_dict_from_equality` to `ax/utils/common/sympy.py`
  for parsing `"expr == bound"` strings (SymPy can't parse `==` directly
  since Python evaluates it as a boolean).
- Extend `ParameterConstraint.__init__` to accept `equality=` kwarg
  alongside existing `inequality=` kwarg. Exactly one must be provided.
- Add `is_equality` property.
- Update `check()` to use `|w^T x - b| <= tol` for equality constraints.
- Update `__repr__`, `clone()`, `clone_with_transformed_parameters()`.
- Add comprehensive tests for equality constraints.

Differential Revision: D100256486
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 20, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 20, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@sdaulton sdaulton force-pushed the export-D100256487 branch from 4e8fe60 to 95f65ba Compare April 20, 2026 16:42
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 20, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@sdaulton sdaulton force-pushed the export-D100256487 branch from 95f65ba to a934285 Compare April 20, 2026 16:42
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 20, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 20, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@sdaulton sdaulton force-pushed the export-D100256487 branch from a934285 to 6e6ff78 Compare April 20, 2026 16:44
…k#5174)

Summary:
Pull Request resolved: facebook#5174

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@sdaulton sdaulton force-pushed the export-D100256487 branch from 6e6ff78 to e715983 Compare April 20, 2026 16:47
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 20, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
sdaulton added a commit to sdaulton/Ax-1 that referenced this pull request Apr 20, 2026
…k#5174)

Summary:

Add support for parsing equality constraint strings (e.g. `"x1 + x2 == 3"`)
in `constraint_from_str`. This extends the existing `<=`/`>=` parsing to also
accept `==` as a comparison operator.

- Add `_process_equality_constraint` function (analogous to `_process_linear_constraint`)
  that constructs `ParameterConstraint(equality=...)`.
- Detect `==` in `constraint_from_str` and route to the new function.
- Reject equality order constraints (`"x1 == x2"`) with a clear error message.
- Update `INVALID_CONSTRAINT_ERROR_MSG` to document `==` support.

Reviewed By: bletham

Differential Revision: D100256487
@meta-codesync meta-codesync Bot closed this in 3975e45 Apr 20, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Apr 20, 2026

This pull request has been merged in 3975e45.

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. fb-exported Merged meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants