GridSearchOptimizer

class GridSearchOptimizer(param_grid=None, *, param_ranges=None, grid_points=20)[source]

Bases: Optimizer

Exhaustive grid search optimizer.

Evaluates all parameter combinations on a user-supplied grid in a single iteration and returns the best-performing parameters. Designed for low-dimensional parameter spaces like CE-QAOA (gamma, beta).

Initialize a grid search optimizer.

Provide either param_grid directly or param_ranges + grid_points to auto-generate the grid.

Parameters:
  • param_grid (ndarray[tuple[Any, ...], dtype[double]] | None) – Explicit 2D array of shape (n_points, n_params) where each row is a parameter combination to evaluate.

  • param_ranges (list[tuple[float, float]] | None) – List of (low, high) tuples, one per parameter. Used with grid_points to generate a Cartesian-product grid.

  • grid_points (int) – Number of grid points per parameter dimension. Only used with param_ranges. Defaults to 20.

Raises:

ValueError – If neither param_grid nor param_ranges is provided, or if param_grid is not 2D.

Attributes Summary

n_param_sets

Number of parameter sets (grid size).

Methods Summary

get_config()

Get optimizer configuration.

load_state(checkpoint_dir)

Load grid search state from checkpoint.

optimize(cost_fn[, initial_params, callback_fn])

Evaluate all grid points and return the best parameters.

reset()

Reset optimizer state.

save_state(checkpoint_dir)

Save grid search state (grid + results).

Attributes Documentation

n_param_sets

Number of parameter sets (grid size).

Methods Documentation

get_config()[source]

Get optimizer configuration.

Return type:

dict[str, Any]

classmethod load_state(checkpoint_dir)[source]

Load grid search state from checkpoint.

Return type:

GridSearchOptimizer

optimize(cost_fn, initial_params=None, callback_fn=None, **kwargs)[source]

Evaluate all grid points and return the best parameters.

The initial_params argument is ignored in favor of the grid. The optimizer always runs for exactly 1 iteration regardless of max_iterations.

Parameters:
Return type:

OptimizeResult

Returns:

OptimizeResult with the best parameters.

reset()[source]

Reset optimizer state.

Return type:

None

save_state(checkpoint_dir)[source]

Save grid search state (grid + results).

Return type:

None