bonni.optimize_ipopt#
- bonni.optimize_ipopt(fn, x0, bounds, max_fn_eval=None, max_iterations=None, save_path=None, tol=1e-08, direction='minimize', bound_contract_ratio=0.001)[source]#
Optimize a black-box function using the Interior Point Optimizer (IPOPT).
This function acts as a convenient wrapper around cyipopt, managing the interface between the objective function (which must provide gradients) and the solver. It handles bound constraints, optimization direction, and recording of the optimization history.
- Parameters:
fn (
Callable[[ndarray],tuple[ndarray,ndarray]]) – The objective function to optimize. It must accept an input array of shape (num_dims,) and return a tuple (y, g), where y is the scalar objective value and g represents gradients of shape (num_dims,).x0 (
ndarray) – The initial starting point for the optimization. Must have shape (num_dims,).bounds (
ndarray) – A 2D array of shape (num_dims, 2) specifying the (lower, upper) search space boundaries for each of the num_dims input dimensions.max_fn_eval (
int|None) – The maximum number of allowed function evaluations. Note that IPOPT performs line searches, so one iteration results in multiple function evaluations. Defaults to None.max_iterations (
int|None) – The maximum number of solver iterations. Defaults to None.save_path (
Path|str|None) – Directory path to save the results of function evaluation as an npz-file. Defaults to None.tol (
float) – The tolerance for convergence. Defaults to 1e-8.direction (
Literal['maximize','minimize']) – The optimization goal. Defaults to “minimize”.bound_contract_ratio (
float) – A small epsilon value used to contract the provided bounds slightly (bounds +/- eps * bound_range). This prevents the interior point method from starting or evaluating exactly on the boundary, which can cause numerical issues. Defaults to 1e-3.
- Returns:
- A tuple containing the full history of:
xs: Input parameters (shape (N, D)).
ys: Objective values (shape (N,)).
gs: Gradients (shape (N, D)).
- Return type:
tuple[ndarray,ndarray,ndarray]