ModOpt icon indicating copy to clipboard operation
ModOpt copied to clipboard

[BUG] error in error message when unknown strategy for FISTA

Open mathurinm opened this issue 2 years ago • 0 comments

System setup With the develop branch

Describe the bug Passing an unknown restart strategy to ForwardBackward does not say it is unknown, but raises a lower level error.

File ~/workspace/ModOpt/modopt/opt/algorithms/forward_backward.py:106, in FISTA.__init__(self, restart_strategy, min_beta, s_greedy, xi_restart, a_cd, p_lazy, q_lazy, r_lazy, **kwargs)
    102 else:
    103     message = 'Restarting strategy must be one of {0}.'
    104     raise ValueError(
    105         message.format(
--> 106             ', '.join(self._restarting_strategies),
    107         ),
    108     )
    109 self._t_now = 1.0
    110 self._t_prev = 1.0

TypeError: sequence item 6: expected str instance, NoneType found

To Reproduce

import numpy as np

from modopt.opt.algorithms import ForwardBackward
from modopt.opt.proximity import SparseThreshold
from modopt.opt.linear import Identity
from modopt.opt.gradient import GradBasic


X = np.random.randn(10, 20)
y = np.random.randn(10)

lmbd = 0.5 * np.max(np.abs(X.T @ y))

restart_strategy = "nonexistentstrategy"
min_beta = None
s_greedy = None
p_lazy = 1 / 30
q_lazy = 1 / 10


def op(w):
    return X @ w


fb = ForwardBackward(
    x=np.zeros(X.shape[1]),
    grad=GradBasic(
        input_data=y, op=op,
        trans_op=lambda res: X.T@res,
        input_data_writeable=True,
    ),
    prox=SparseThreshold(Identity(), lmbd),
    beta_param=1.0,
    min_beta=min_beta,
    metric_call_period=None,
    restart_strategy=restart_strategy,
    xi_restart=0.96,
    s_greedy=s_greedy,
    p_lazy=p_lazy,
    q_lazy=q_lazy,
    auto_iterate=False,
    progress=False,
    cost=None,
)

mathurinm avatar Mar 31 '22 14:03 mathurinm