SearchSpace¶
Manages the variable space for Bayesian optimization, including real, integer, and categorical variables.
Class Reference¶
alchemist_core.data.search_space.SearchSpace()
¶
Class for storing and managing the search space in a consistent way across backends. Provides methods for conversions to different formats required by different backends.
add_variable(name, var_type, **kwargs)
¶
Add a variable to the search space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variable name |
required |
var_type
|
str
|
"real", "integer", or "categorical" |
required |
**kwargs
|
Additional parameters (min, max, values) |
{}
|
from_dict(data)
¶
Load search space from a list of dictionaries (used with JSON/CSV loading).
from_skopt(dimensions)
¶
Load search space from skopt dimensions.
to_dict()
¶
Convert search space to a list of dictionaries.
to_skopt()
¶
Get skopt dimensions for scikit-learn.
to_ax_space()
¶
Convert to Ax parameter format.
to_botorch_bounds()
¶
Create bounds in BoTorch format.
get_variable_names()
¶
Get list of all variable names.
get_categorical_variables()
¶
Get list of categorical variable names.
get_integer_variables()
¶
Get list of integer variable names.
save_to_json(filepath)
¶
Save search space to a JSON file.
load_from_json(filepath)
¶
Load search space from a JSON file.
from_json(filepath)
classmethod
¶
Class method to create a SearchSpace from a JSON file.
add_constraint(constraint_type, coefficients, rhs, name=None)
¶
Add linear input constraint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint_type
|
str
|
'inequality' (sum(coeff_i * x_i) <= rhs) or 'equality' (sum(coeff_i * x_i) == rhs) |
required |
coefficients
|
Dict[str, float]
|
{variable_name: coefficient} mapping |
required |
rhs
|
float
|
right-hand side value |
required |
name
|
Optional[str]
|
optional human-readable name |
None
|
get_constraints()
¶
Return list of constraint dicts.
to_botorch_constraints(feature_names)
¶
Convert to BoTorch format for optimize_acqf.
Each constraint is a tuple (indices_tensor, coefficients_tensor, rhs_float). BoTorch convention: inequality means sum(coeff_i * x_i) - rhs <= 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_names
|
List[str]
|
ordered list of feature column names matching model input |
required |
Returns:
| Type | Description |
|---|---|
Optional[List]
|
(inequality_constraints, equality_constraints) — each is a list of tuples |
Optional[List]
|
or None if no constraints of that type exist. |
See Also¶
- OptimizationSession - Uses SearchSpace for variable management