Skip to content

feat(gds-psuu): parameter space constraints #113

@rororowyourboat

Description

@rororowyourboat

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 grid
  • RandomSearchOptimizer: rejection sampling (with max retry limit)
  • BayesianOptimizer: constrained acquisition function or rejection sampling
  • ParameterSpace.is_feasible(point) — public method all optimizers can call

Acceptance criteria

  • Constraint ABC with is_feasible()
  • LinearConstraint and FunctionalConstraint implementations
  • ParameterSpace.constraints field (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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions