nemos.solvers._optimistix_solvers.OptimistixAdapter#

class nemos.solvers._optimistix_solvers.OptimistixAdapter(unregularized_loss, regularizer, regularizer_strength, has_aux, init_params=None, tol=0.0001, rtol=0.0, maxiter=None, **solver_init_kwargs)[source]#

Bases: SolverAdapter

Base class for adapters wrapping Optimistix minimizers.

Subclasses must define the _solver_cls class attribute. The _solver attribute is assumed to exist after construction, so if a subclass is overwriting __init__, these must be created.

Note that for backward compatibility the atol parameter used in Optimistix is referred to as tol in NeMoS.

The maxiter default is taken from DEFAULT_MAXITER, which subclasses may override to set solver-specific defaults.

Attributes

Parameters:
  • unregularized_loss (Callable)

  • regularizer (Regularizer)

  • regularizer_strength (float | None)

  • has_aux (bool)

  • init_params (Params | None)

  • tol (float)

  • rtol (float)

  • maxiter (int | None)

__init__(unregularized_loss, regularizer, regularizer_strength, has_aux, init_params=None, tol=0.0001, rtol=0.0, maxiter=None, **solver_init_kwargs)[source]#

Create the solver.

Parameters:
  • unregularized_loss (Callable) – Unregularized loss function. Currently BaseRegressor.compute_loss.

  • regularizer (Regularizer) – Regularizer object used to create the penalized loss or get the proximal operator from.

  • regularizer_strength (float | None) – Regularizer strength.

  • has_aux (bool) – Whether unregularized_loss returns auxiliary variables. If False, the loss function is expected to return a single scalar. If True, the loss is expected to return a tuple of length 2 with a scalar and auxiliary variables.

  • init_params (Any | None) – Initial model parameters. Passed to the regularizer’s get_proximal_operator or penalized_loss.

  • **solver_init_kwargs – Keyword arguments modifying the solver’s behavior.

  • tol (float)

  • rtol (float)

  • maxiter (int | None)

Methods

__init__(unregularized_loss, regularizer, ...)

Create the solver.

adjust_solver_init_kwargs(solver_init_kwargs)

Optionally adjust the parameters (e.g. derive from self.config) for instantiating the wrapped solver.

get_accepted_arguments()

Set of accepted argument names, extended with the wrapped solver's arguments.

init_state(init_params, *args)

Initialize the solver state.

run(init_params, *args)

Run a full optimization process until a stopping criterion is reached.

update(params, state, *args)

Perform a single step/update of the optimization process.

DEFAULT_MAXITER: ClassVar[int] = 10000#
__getattr__(name)#

Try getting undefined attributes from the underlying solver.

Parameters:

name (str)

classmethod __init_subclass__(**kw)#

Generate the docstring including accepted arguments and the wrapped solver’s documentation.

adjust_solver_init_kwargs(solver_init_kwargs)[source]#

Optionally adjust the parameters (e.g. derive from self.config) for instantiating the wrapped solver.

Parameters:

solver_init_kwargs (dict[str, Any]) – Original keyword arguments that would be passed to _solver_cls.__init__.

Return type:

dict[str, Any]

Returns:

  • dict with argument names of _solver_cls.__init__ as keys and

  • their corresponding values as values.

  • Default implementation just returns solver_init_kwargs.

classmethod get_accepted_arguments()[source]#

Set of accepted argument names, extended with the wrapped solver’s arguments.

Return type:

set[str]

init_state(init_params, *args)[source]#

Initialize the solver state.

Used by BaseRegressor.initialize_state

Return type:

OptimistixAdapterState

Parameters:
  • init_params (Any)

  • args (Any)

property maxiter: int#
run(init_params, *args)[source]#

Run a full optimization process until a stopping criterion is reached.

Used by BaseRegressor.fit.

Return type:

tuple[Any, OptimistixAdapterState, TypeVar(Aux)]

Parameters:
  • init_params (Any)

  • args (Any)

update(params, state, *args)[source]#

Perform a single step/update of the optimization process.

Used by BaseRegressor.update.

Return type:

tuple[Any, OptimistixAdapterState, TypeVar(Aux)]

Parameters:
  • params (Any)

  • state (OptimistixAdapterState)

  • args (Any)