baybe.searchspace.utils.parameter_cartesian_prod_pandas_constrained

baybe.searchspace.utils.parameter_cartesian_prod_pandas_constrained(parameters: Sequence[DiscreteParameter], constraints: Sequence[DiscreteConstraint], initial_df: DataFrame | None = None)[source]

Build a Cartesian product of parameters with incremental constraint filtering.

Instead of creating the full Cartesian product and then filtering, this function cross-merges parameters one by one, applying constraint filters as early as possible. This significantly reduces memory usage and construction time for highly constrained spaces.

Parameters are ordered so that constrained parameters come first, enabling constraints to fire early when the intermediate dataframe is still small.

Parameters:
  • parameters (Sequence[DiscreteParameter]) – The discrete parameters to combine.

  • constraints (Sequence[DiscreteConstraint]) – The discrete constraints to apply.

  • initial_df (Optional[DataFrame]) – An optional starting dataframe. When provided, the given parameters are cross-merged into it (its columns count as already available for constraint evaluation).

Return type:

DataFrame

Returns:

A dataframe containing all valid parameter combinations.