pyxu.opt.stop#

class MaxIter(n)[source]#

Bases: StoppingCriterion

Stop iterative solver after a fixed number of iterations.

Note

If you want to add a grace period to a solver, i.e. for it to do at least N iterations before stopping based on the value of another criteria, you can AND MaxIter with the other criteria.

sc = MaxIter(n=5) & AbsError(eps=0.1)
# If N_iter < 5  -> never stop.
# If N_iter >= 5 -> stop if AbsError() decides to.
Parameters:

n (Integral)

__init__(n)[source]#
Parameters:

n (Integer) – Max number of iterations allowed.

class ManualStop[source]#

Bases: StoppingCriterion

Continue-forever criterion.

This class is useful when calling fit() with mode=MANUAL/ASYNC to defer the stopping decision to an explicit call by the user, i.e.:

  • mode=MANUAL: user must stop calling next(solver.steps());

  • mode=ASYNC: user must call stop().

__init__()#
class MaxDuration(t)[source]#

Bases: StoppingCriterion

Stop iterative solver after a specified duration has elapsed.

Parameters:

t (timedelta)

__init__(t)[source]#
Parameters:

t (timedelta) – Max runtime allowed.

class Memorize(var)[source]#

Bases: StoppingCriterion

Memorize a variable. (Special StoppingCriterion mostly useful for tracking objective functions in Solver.)

Parameters:

var (str | Collection[str])

__init__(var)[source]#
Parameters:

var (VarName) – Variable in pyxu.abc.Solver._mstate to query. Must be a scalar or NDArray (1D).

class AbsError(eps, var='x', rank=1, f=None, norm=2, satisfy_all=True)[source]#

Bases: StoppingCriterion

Stop iterative solver after absolute norm of a variable (or function thereof) reaches threshold.

Parameters:
__init__(eps, var='x', rank=1, f=None, norm=2, satisfy_all=True)[source]#
Parameters:
  • eps (Real) – Positive threshold.

  • var (VarName) – Variable in pyxu.abc.Solver._mstate to query. Must hold an NDArray.

  • rank (Integer) – Array rank K of monitored variable after applying f. (See below.)

  • f (Callable) –

    Optional function to pre-apply to _mstate[var] before applying the norm. Defaults to the identity function. The callable should have the same semantics as apply():

    (…, M1,…,MD) -> (…, N1,…,NK)

  • norm (Integer, Real) – Ln norm to use >= 0. (Default: L2.)

  • satisfy_all (bool) – If True (default) and _mstate[var] is multi-dimensional, stop if all evaluation points lie below threshold.

class RelError(eps, var='x', rank=1, f=None, norm=2, satisfy_all=True)[source]#

Bases: StoppingCriterion

Stop iterative solver after relative norm change of a variable (or function thereof) reaches threshold.

Parameters:
__init__(eps, var='x', rank=1, f=None, norm=2, satisfy_all=True)[source]#
Parameters:
  • eps (Real) – Positive threshold.

  • var (VarName) – Variable in pyxu.abc.Solver._mstate to query. Must hold an NDArray

  • rank (Integer) – Array rank K of monitored variable after applying f. (See below.)

  • f (Callable) –

    Optional function to pre-apply to _mstate[var] before applying the norm. Defaults to the identity function. The callable should have the same semantics as apply():

    (…, M1,…,MD) -> (…, N1,…,NK)

  • norm (Integer, Real) – Ln norm to use >= 0. (Default: L2.)

  • satisfy_all (bool) – If True (default) and _mstate[var] is multi-dimensional, stop if all evaluation points lie below threshold.