qpots.function
- class qpots.function.Function(name: str | None = None, dim: int = 2, nobj: int = 2, custom_func: Callable[[Tensor], Tensor] | None = None, bounds: Tensor | None = None, cons: Callable[[Tensor], Tensor] | None = None, device: device | str | None = None, dtype: dtype | None = None)[source]
Bases:
objectInterface for multi-objective test functions.
This class provides an abstraction over BoTorch test functions and allows for user-defined objective functions. It supports retrieving function bounds and constraints when available.
- __init__(name: str | None = None, dim: int = 2, nobj: int = 2, custom_func: Callable[[Tensor], Tensor] | None = None, bounds: Tensor | None = None, cons: Callable[[Tensor], Tensor] | None = None, device: device | str | None = None, dtype: dtype | None = None)[source]
Initialize a test function for multi-objective optimization.
- Parameters:
name (str, optional) – Name of the predefined test function (case-insensitive). If None, a custom function must be provided.
dim (int) – Dimensionality of the input space. Defaults to 2.
nobj (int) – Number of objectives for the test function. Defaults to 2.
custom_func (Callable, optional) – A user-defined function that takes a tensor X as input and returns an output tensor. If provided, name is ignored.
bounds (Tensor, optional) – A tensor specifying the lower and upper bounds for the function. Required if using a custom function.
cons (Callable, optional) – A constraint function that maps inputs to constraint values.
device (torch.device or str, optional) – Device used for generated bounds and evaluations. Defaults to the qPOTS runtime device.
dtype (torch.dtype, optional) – Floating-point precision used for generated bounds and evaluations. Defaults to
qpots.config.DEFAULT_DTYPE.
- Raises:
ValueError – If a custom function is provided but bounds is not specified. If an unknown function name is provided.
- _evaluate_constraints(X: Tensor) Tensor[source]
Evaluate BoTorch constraint slack values on the runtime device/dtype.
- _initialize_function()[source]
Initialize a predefined BoTorch test function.
This method sets up the corresponding function, bounds, and constraints based on the selected function name.
- Raises:
ValueError – If the specified function name is not recognized.
- evaluate(X: Tensor) Tensor[source]
Evaluate the test function or custom function on input X.
- Parameters:
X (Tensor) – A tensor of shape (n, dim), where n is the number of points and dim is the input dimension.
- Returns:
A tensor of shape (n, nobj) containing the function outputs.
- Return type:
Tensor