feat(design): coupled FactorConstraint for build_grid (#103)#106
Merged
Conversation
Add FactorConstraint dataclass that wraps a predicate over candidate configs and plumb a constraints= kwarg through build_grid for full factorial, LHS, and Sobol/Halton QMC. - Full factorial filters the Cartesian product directly. - LHS / QMC use rejection sampling with doubling oversample (cap 64x) and warn when the realized feasibility ratio drops below 10%. - Raises ValueError if the budget is exhausted before n_samples feasible configs are collected. Distinct from protocols.Constraint (output feasibility, post-sim); FactorConstraint is design-time so QMC budgets are not wasted on configs that will be filtered after evaluation. Tests cover deterministic seeding, full-factorial filtering, the all-rejected edge case, the low-feasibility warning, and the budget-exhausted error path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #103.
Summary
Adds
FactorConstraintfor design-time coupled-factor constraints (e.g. "ifmethod == 'elbo_only'thenpatience <= 2") and plumbs aconstraints=kwarg throughbuild_gridforfull,lhs,sobol, andhalton.This is distinct from the existing
protocols.Constraint, which filters trials after simulation based on observables.FactorConstraintfilters candidate configs before evaluation so QMC budget isn't wasted on points that would be discarded post-hoc.Behavior
UserWarningwhen realized feasibility ratio < 10% (QMC space-filling is degraded by rejection).ValueErrorif the budget is exhausted beforen_samplesfeasible configs are collected.constraintsdefaults toNoneand existing call sites are unchanged.Example
Tests
8 new tests in
tests/test_design.pycovering:ValueErrorCI
just ciclean: lint, mypy strict, 275 tests pass,design.pyat 100% line coverage.Follow-ups