ScipyOptimizer¶
- class ScipyOptimizer(method)[source]¶
Bases:
OptimizerOptimizer wrapper for scipy.optimize methods.
Supports gradient-free and gradient-based optimization algorithms from scipy, including Nelder-Mead simplex, COBYLA, and L-BFGS-B.
Initialize a scipy-based optimizer.
- Parameters:
method (
ScipyMethod) – The optimization algorithm to use.
Attributes Summary
Get the number of parameter sets 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 scipy 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 used by this optimizer.
- Returns:
Always returns 1, as scipy optimizers use single-point optimization.
- Return type:
Methods Documentation
- get_config()[source]¶
Get optimizer configuration for checkpoint reconstruction.
- Raises:
NotImplementedError – ScipyOptimizer does not support checkpointing.
- Return type:
- classmethod load_state(checkpoint_dir)[source]¶
Load the optimizer’s internal state from a checkpoint directory.
Scipy optimizers do not support loading state as they cannot save state.
- Parameters:
checkpoint_dir (
Path|str) – Directory path where the optimizer state would be loaded from.- Raises:
NotImplementedError – Always raised, as scipy optimizers cannot load state.
- Return type:
- optimize(cost_fn, initial_params=None, callback_fn=None, **kwargs)[source]¶
Run the scipy optimization algorithm.
- Parameters:
cost_fn (
Callable[[ndarray[tuple[Any,...],dtype[double]]],float]) – Function to minimize. Should accept a 1D array of parameters and return a scalar cost value.initial_params (
ndarray[tuple[Any,...],dtype[double]] |None) – Initial parameter values as a 1D or 2D array. If 2D with shape (1, n_params), it will be squeezed to 1D.callback_fn (
Callable[[OptimizeResult],Any] |None) – Function called after each iteration with an OptimizeResult object. Defaults to None.**kwargs –
Additional keyword arguments:
max_iterations (int, optional): Total desired number of iterations. Defaults to None (no limit for some methods).
jac (Callable): Gradient function (only used for L-BFGS-B).
- Returns:
Optimization result with final parameters and cost value.
- Return type:
- reset()[source]¶
Reset the optimizer’s internal state.
ScipyOptimizer does not maintain internal state between optimization runs, so this method is a no-op.
- Return type:
- save_state(checkpoint_dir)[source]¶
Save the optimizer’s internal state to a checkpoint directory.
Scipy optimizers do not support saving state mid-minimization as scipy.optimize does not provide access to the internal optimizer state.
- Parameters:
checkpoint_dir (
Path|str) – Directory path where the optimizer state would be saved.- Raises:
NotImplementedError – Always raised, as scipy optimizers cannot save state.
- Return type: