quri_parts.algo.optimizer.interface module#

quri_parts.algo.optimizer.interface.Params: typing_extensions.TypeAlias = 'npt.NDArray[np.float_]'#

Represents a parameter vector subject to optimization. (A gradient vector is also represented as Params.)


Cost function for optimization.

alias of Callable[[npt.NDArray[np.float_]], float]


Gradient function for optimization.

alias of Callable[[npt.NDArray[np.float_]], npt.NDArray[np.float_]]

class quri_parts.algo.optimizer.interface.OptimizerStatus(value)#

Bases: Enum

Status of optimization.


No error, not converged yet.


The optimization failed and cannot be continued.


The optimization converged.

class quri_parts.algo.optimizer.interface.OptimizerState(params: npt.NDArray[np.float_], cost: float = 0.0, status: OptimizerStatus = OptimizerStatus.SUCCESS, niter: int = 0, funcalls: int = 0, gradcalls: int = 0)#

Bases: object

An immutable (frozen) dataclass representing an optimizer state.

params: npt.NDArray[np.float_]#

Current parameter values.

cost: float = 0.0#

Current value of the cost function.

status: OptimizerStatus = 1#

Optimization status.

niter: int = 0#

Number of iterations.

funcalls: int = 0#

Number of cost function calls.

gradcalls: int = 0#

Number of gradient function calls.

property n_params: int#

Number of parameters.

class quri_parts.algo.optimizer.interface.Optimizer(*args, **kwargs)#

Bases: Protocol

A protocol class for optimizers.

abstract get_init_state(init_params: npt.NDArray[np.float_]) OptimizerState#

Returns an initial state for optimization.

abstract step(state: OptimizerState, cost_function: Callable[[npt.NDArray[np.float_]], float], grad_function: Callable[[npt.NDArray[np.float_]], npt.NDArray[np.float_]] | None = None) OptimizerState#

Run a single optimization step and returns a new state.