Skip to content

Support discrete constraints in the Client API - #5295

Open
saitcakmak wants to merge 3 commits into
facebook:mainfrom
saitcakmak:export-D122426291
Open

saitcakmak wants to merge 3 commits into
facebook:mainfrom
saitcakmak:export-D122426291

Conversation

@saitcakmak

Copy link
Copy Markdown
Contributor

Summary:
Problem:
The lower stack layers add discrete-aware random generation and adapter wiring, but public Client usage also needs equality parsing and end-to-end proof that generated parameters remain valid after the full transform round trip.

What changed:
Recognize == expressions when constructing Client parameter constraints. Add public Client coverage for constrained irregular choices, constrained integer ranges, mixed discrete/continuous equalities, fixed discrete parameters, JSON snapshot and restore, large integer ranges, exact trial counts, and explicit random-search dispatch.

Stack structure:

  1. D113627036 -- generator mechanics and direct generator tests.
  2. D122426289 -- Sobol and Uniform adapter wiring and the high-cardinality escape hatch.
  3. D122426291 -- this public API and end-to-end validation layer.
  4. D122426292 -- internal BOPE candidate-generation integration.

End-to-end evidence:
These tests execute Client.configure_experiment -> GenerationStrategy(random_search) -> registry transforms -> RandomAdapter -> SobolGenerator without mocking candidate generation. They verify that returned choices belong to the declared set, integer ranges return integers, linear and equality constraints hold after inverse transforms, fixed values survive generation, restored clients continue generating valid trials, large integer ranges do not require enumeration, and the selected generator key is Sobol.

A three-seed local benchmark improved constrained Client validity from [0.734, 0.656, 0.672] to [1.0, 1.0, 1.0] and mixed-equality validity from [0.0, 0.0, 0.0] to [1.0, 1.0, 1.0].

Differential Revision: D122426291

Summary:

Problem:
Random generation encoded ordered numeric choices as integer indices while retaining parameter constraints in value space. Constraint checks could therefore accept candidates that became invalid after transforming back, especially for irregularly spaced values.

What changed:
This foundation teaches RandomGenerator to sample every discrete dimension uniformly by rank, decode the original value before feasibility and deduplication checks, and project polytope samples onto supported choices. It also handles pure-discrete and mixed discrete/continuous equalities, including correctly shaped equality right-hand sides.

Stack structure:
1. D113627036 -- generator mechanics and direct generator tests.
2. D122426289 -- wires the behavior into Sobol and Uniform adapters and safely relaxes integer ranges with more than 1000 values.
3. D122426291 -- public Client parsing and end-to-end coverage.
4. D122426292 -- internal BOPE candidate-generation integration.

End-to-end evidence:
The public end-to-end tests intentionally live in D122426291 because they require both this generator foundation and the adapter wiring in D122426289. They execute Client.configure_experiment -> GenerationStrategy(random_search) -> registry transforms -> RandomAdapter -> SobolGenerator without mocking candidate generation. Coverage verifies constrained irregular choices, constrained integer ranges, fixed discrete parameters, JSON snapshot and restore, mixed discrete/continuous equality, large integer ranges, exact trial counts, and the Sobol generator key.

A three-seed local benchmark on the complete stack improved valid constrained Client candidates from a 0.688 mean to 1.0 and valid mixed-equality candidates from 0.0 to 1.0.

Differential Revision: D113627036
Summary:

Problem:
The generator support in D113627036 is not user-visible until Sobol and Uniform adapters preserve numeric choices. Applying discrete transforms indiscriminately would also eagerly materialize very large integer ranges.

What changed:
Introduce a dedicated random-adapter transform chain. Numeric choices and integer ranges with at most 1000 values remain discrete, while larger integer ranges use IntToFloat. Sobol and Uniform share the configuration without aliasing the MBM transform list.

Stack structure:
1. D113627036 -- generator mechanics and direct generator tests.
2. D122426289 -- this adapter wiring and high-cardinality escape hatch.
3. D122426291 -- public Client parsing and end-to-end coverage.
4. D122426292 -- internal BOPE candidate-generation integration.

End-to-end evidence:
This diff verifies registry construction and generation-strategy dispatch locally. The public end-to-end tests are in D122426291, where Client.get_next_trials traverses this registry configuration into RandomAdapter and SobolGenerator. Those tests assert actual supported choice values, integer types, satisfied constraints, exact trial counts, and the Sobol generator key. The complete-stack benchmark raises constrained Client validity from a 0.688 mean to 1.0.

Differential Revision: D122426289
Summary:
Problem:
The lower stack layers add discrete-aware random generation and adapter wiring, but public Client usage also needs equality parsing and end-to-end proof that generated parameters remain valid after the full transform round trip.

What changed:
Recognize == expressions when constructing Client parameter constraints. Add public Client coverage for constrained irregular choices, constrained integer ranges, mixed discrete/continuous equalities, fixed discrete parameters, JSON snapshot and restore, large integer ranges, exact trial counts, and explicit random-search dispatch.

Stack structure:
1. D113627036 -- generator mechanics and direct generator tests.
2. D122426289 -- Sobol and Uniform adapter wiring and the high-cardinality escape hatch.
3. D122426291 -- this public API and end-to-end validation layer.
4. D122426292 -- internal BOPE candidate-generation integration.

End-to-end evidence:
These tests execute Client.configure_experiment -> GenerationStrategy(random_search) -> registry transforms -> RandomAdapter -> SobolGenerator without mocking candidate generation. They verify that returned choices belong to the declared set, integer ranges return integers, linear and equality constraints hold after inverse transforms, fixed values survive generation, restored clients continue generating valid trials, large integer ranges do not require enumeration, and the selected generator key is Sobol.

A three-seed local benchmark improved constrained Client validity from [0.734, 0.656, 0.672] to [1.0, 1.0, 1.0] and mixed-equality validity from [0.0, 0.0, 0.0] to [1.0, 1.0, 1.0].

Differential Revision: D122426291
@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 29, 2026
@meta-codesync

meta-codesync Bot commented Sep 29, 2026

Copy link
Copy Markdown

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

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.04142% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.59%. Comparing base (60b14eb) to head (8495d04).

Files with missing lines Patch % Lines
ax/generators/random/base.py 91.52% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #5295    +/-   ##
========================================
  Coverage   96.59%   96.59%            
========================================
  Files         621      621            
  Lines       70952    71110   +158     
========================================
+ Hits        68536    68691   +155     
- Misses       2416     2419     +3     

☔ View full report in Codecov by Harness.
📢 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.

This branch has not been deployed

No deployments
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants