PymooOptimizer¶
- class PymooOptimizer(method, population_size=50, **kwargs)[source]¶
Bases:
OptimizerOptimizer wrapper for pymoo optimization algorithms and CMA-ES.
Supports population-based optimization methods from the pymoo library (DE) and the cma library (CMAES).
Initialize a pymoo-based optimizer.
- Parameters:
method (
PymooMethod) – The optimization algorithm to use (CMAES or DE).population_size (
int) – Size of the population for the algorithm. Defaults to 50.**kwargs – Additional algorithm-specific parameters passed to pymoo/cma.
Attributes Summary
Get the number of parameter sets (population size) used by this optimizer.
Methods Summary
Get optimizer configuration for checkpoint reconstruction.
load_state(checkpoint_dir)Load the optimizer's internal state from a checkpoint directory.
optimize(cost_fn[, initial_params, callback_fn])Run the optimization algorithm.
reset()Reset the optimizer's internal state.
save_state(checkpoint_dir)Save the optimizer's internal state to a checkpoint directory.
Attributes Documentation
- n_param_sets¶
Get the number of parameter sets (population size) used by this optimizer.
- Returns:
Population size for the optimization algorithm.
- Return type:
Methods Documentation
- classmethod load_state(checkpoint_dir)[source]¶
Load the optimizer’s internal state from a checkpoint directory.
Creates a new PymooOptimizer instance with the state restored from the checkpoint.
- Parameters:
checkpoint_dir (
Path|str) – Directory path where the optimizer state is saved.- Returns:
A new optimizer instance with restored state.
- Return type:
- Raises:
FileNotFoundError – If the checkpoint file does not exist.
- optimize(cost_fn, initial_params=None, callback_fn=None, **kwargs)[source]¶
Run the optimization algorithm.
- Parameters:
cost_fn (
Callable[[ndarray[tuple[Any,...],dtype[double]]],float|ndarray[tuple[Any,...],dtype[double]]]) – Function to minimize. Should accept a 2D array of parameter sets and return an array of cost values.initial_params (
ndarray[tuple[Any,...],dtype[double]] |None) – Initial parameter values as a 2D array of shape (n_param_sets, n_params). Should be None when resuming from a checkpoint.callback_fn (
Callable|None) – Function called after each iteration with an OptimizeResult object. Defaults to None.**kwargs –
Additional keyword arguments:
max_iterations (int): Total desired number of iterations. When resuming from a checkpoint, this represents the total iterations desired across all runs. The optimizer will automatically calculate and run only the remaining iterations needed. Defaults to 5.
rng (np.random.Generator): Random number generator.
- Returns:
Optimization result with final parameters and cost value.
- Return type:
OptimizeResult