-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Add declarative constraints to ParameterSpace so users can express feasibility regions beyond independent per-dimension bounds. Constraints are structural metadata — validated at construction time, inspectable by optimizers, and consistent with how every other GDS model handles invariants.
Motivation
Real parameter spaces often have cross-parameter dependencies: budgets that must sum to a limit, ratios that must stay positive, physical laws that couple variables. Currently, the only option is post-hoc filtering, which wastes evaluations and breaks optimizer assumptions.
Design
Follows the Pydantic @model_validator pattern used throughout GDS:
class Constraint(BaseModel, ABC):
"""Base class for parameter space constraints."""
@abstractmethod
def is_feasible(self, point: ParamPoint) -> bool: ...
class LinearConstraint(Constraint):
"""a₁x₁ + a₂x₂ + ... ≤ b"""
coefficients: dict[str, float]
bound: float
class FunctionalConstraint(Constraint):
"""Arbitrary feasibility predicate."""
fn: Callable[[ParamPoint], bool]ParameterSpace integration
ParameterSpace(
params={
"budget_a": Continuous(min_val=0, max_val=100),
"budget_b": Continuous(min_val=0, max_val=100),
},
constraints=[
LinearConstraint(coefficients={"budget_a": 1, "budget_b": 1}, bound=100),
],
)Optimizer behavior
GridSearchOptimizer: filter infeasible points from gridRandomSearchOptimizer: rejection sampling (with max retry limit)BayesianOptimizer: constrained acquisition function or rejection samplingParameterSpace.is_feasible(point)— public method all optimizers can call
Acceptance criteria
-
ConstraintABC withis_feasible() -
LinearConstraintandFunctionalConstraintimplementations -
ParameterSpace.constraintsfield (default empty) -
ParameterSpace.is_feasible(point)checks all constraints - Grid and random optimizers respect constraints
- Validation: constraint param names must be subset of space param names
- Tests with >90% coverage on new code
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request