Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/src/algorithm/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,12 @@ SCS will return one of the two above certificates, whichever one it finds
first. However, in that case the interpretation of infeasibility in one space
being equivalent to unboundedness in the dual space does not hold.

Iteration and time limits
-------------------------

If none of these criteria hold within :code:`max_iters` iterations or
:code:`time_limit_secs` (see :ref:`settings <settings>`), SCS stops and returns
a best guess from its last iterate with an inaccurate status, or
:code:`SCS_INDETERMINATE` when that iterate gives no estimate of a solution or
of a certificate; see :ref:`exit flags <exit_flags_limit>`.

7 changes: 6 additions & 1 deletion docs/src/algorithm/warm_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ by setting the warm-start :ref:`setting <settings>` to :code:`True` when calling
y, s` members of the :ref:`ScsSolution` struct, where those members correspond
to the guess of the solution in the :ref:`standard form <optimality>`. SCS will
initialize the solver at those points and then overwrite the :ref:`ScsSolution`
struct members with the real solution at termination.
struct members with the real solution at termination. NaN entries of the guess
are read as zero, so a warm start from a solution that SCS returned as NaN
(after :code:`SCS_INDETERMINATE`, for example, see :ref:`exit flags
<exit_flags_limit>`) starts from zero, as a cold start does; the
:code:`scale` and the per-row multipliers still carry over as described
above.

The settings that only the solve reads, such as the tolerances,
:code:`max_iters` and :code:`time_limit_secs`, can also be changed between
Expand Down
67 changes: 64 additions & 3 deletions docs/src/api/exit_flags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ in the :code:`include/scs.h` file.
* - Primal infeasible / Dual unbounded (to desired tolerance)
- -2
- :code:`SCS_INFEASIBLE`
* - Indeterminate (numerical errors when recovering solution) DEPRECATED
* - Indeterminate: reached :code:`max_iters` or :code:`time_limit_secs`
at an iterate that gives no estimate of a solution or of a
certificate; x, y and s are NaN (see :ref:`below <exit_flags_limit>`)
- -3
- :code:`SCS_INDETERMINATE`
* - Failed: a data input error, or an internal error such as a failed
* - Failed: a data input error, an internal error such as a failed
linear solve (the printed message says which; an internal error asks
you to open an issue)
you to open an issue), or an iterate that is not finite (NaN or Inf)
at :code:`max_iters` or :code:`time_limit_secs`
- -4
- :code:`SCS_FAILED`
* - Interrupted (received SIGINT)
Expand All @@ -45,3 +48,61 @@ in the :code:`include/scs.h` file.
- -7
- :code:`SCS_INFEASIBLE_INACCURATE`


.. _exit_flags_limit:

At max_iters or time_limit_secs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When SCS stops at :code:`max_iters` or :code:`time_limit_secs` before its
:ref:`termination criteria <termination>` hold, it reports what the last
iterate supports. SCS works with a homogeneous iterate :math:`(x, y, s, \tau,
\kappa)`: a solution estimate is :math:`(x, y, s) / \tau`, which needs
:math:`\tau > 0`, and a certificate estimate is :math:`y / (-b^\top y)` or
:math:`(x, s) / (-c^\top x)`, which needs :math:`b^\top y < 0` or
:math:`c^\top x < 0`. The tests below are exact comparisons, taken in this
order, so the status depends only on the last iterate:

.. list-table::
:widths: 40 15 45
:header-rows: 1

* - Last iterate
- Exit flag
- Returned
* - Not finite (a NaN or an infinite entry, for example after an
overflow)
- -4 (:code:`SCS_FAILED`)
- x, y, s and the info fields listed for -3 NaN; status
:code:`failure`
* - :math:`\kappa > \tau` and :math:`b^\top y < 0` or :math:`c^\top x
< 0`
- -7 or -6
- The infeasibility certificate :math:`y / (-b^\top y)` (x and s NaN),
or the unboundedness certificate :math:`(x, s) / (-c^\top x)` (y NaN)
* - :math:`\tau > 0`
- 2
- The solution estimate :math:`(x, y, s) / \tau` and its objective and
residuals
* - Otherwise: :math:`\tau = 0` and :math:`b^\top y \geq 0`,
:math:`c^\top x \geq 0`
- -3 (:code:`SCS_INDETERMINATE`)
- x, y, s NaN, and :code:`pobj`, :code:`dobj`, :code:`gap`,
:code:`res_pri`, :code:`res_dual`, :code:`res_infeas`,
:code:`res_unbdd_a`, :code:`res_unbdd_p` and :code:`comp_slack` NaN

Each status except :code:`failure` ends in :code:`(inaccurate - reached
max_iters)` or :code:`(inaccurate - reached time_limit_secs)`, for example
:code:`indeterminate (inaccurate - reached max_iters)`.

The estimates returned with 2, -6 and -7 do not meet the tolerances. A
certificate estimate rests on the sign of :math:`b^\top y` or :math:`c^\top
x` at the last iterate alone, which on a run whose iterates diverged can
change from one iteration to the next.

SCS returns :code:`SCS_INDETERMINATE` when the cone projection has set
:math:`\tau` to zero and neither :math:`b^\top y` nor :math:`c^\top x` is
negative. This happens in the first few iterations and on runs whose iterates
diverged. As for an inaccurate status, more iterations or more time can help
(see :ref:`help_indeterminate`). A warm start from the NaN solution starts
from zero, as a cold start does (see :ref:`warm_start`).
6 changes: 6 additions & 0 deletions docs/src/api/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ the following fields.
- :code:`scs_float`
- Total time (milliseconds) spent in the :ref:`acceleration routine <acceleration>`

When SCS returns :code:`SCS_INDETERMINATE`, or stops at :code:`max_iters` or
:code:`time_limit_secs` with an iterate that is not finite (see :ref:`exit
flags <exit_flags_limit>`), :code:`pobj`, :code:`dobj`, :code:`res_pri`,
:code:`res_dual`, :code:`gap`, :code:`res_infeas`, :code:`res_unbdd_a`,
:code:`res_unbdd_p` and :code:`comp_slack` are NaN, as are x, y and s.

Anderson acceleration statistics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
8 changes: 4 additions & 4 deletions docs/src/api/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ They are set in the :ref:`ScsSettings <ScsSettings>` struct.
- 1e-6 (1e-2 in single precision builds)
* - :code:`max_iters`
- :code:`scs_int`
- Maximum number of iterations to run.
- Maximum number of iterations to run. When it is reached SCS returns its best guess with an inaccurate status, or :code:`SCS_INDETERMINATE` when the last iterate gives none, see :ref:`exit flags <exit_flags_limit>`.
- :math:`\mathbf{N}`
- 1e5
* - :code:`eps_abs`
Expand All @@ -67,7 +67,7 @@ They are set in the :ref:`ScsSettings <ScsSettings>` struct.
- 1.5
* - :code:`time_limit_secs`
- :code:`scs_float`
- Time limit for the solve in seconds (can be fractional). :code:`0` is interpreted as no limit. The clock starts when :code:`scs_solve` is called, so the setup time (e.g., the initial factorization) is not counted, although the time column of the printed output does include it. The limit is only tested when convergence is checked, every 25 iterations (:code:`CONVERGED_INTERVAL` in :code:`include/glbopts.h`), so a solve can overrun it by up to 25 iterations. When the limit is reached SCS returns its best guess with an inaccurate status, see :ref:`exit flags <exit_flags>`. It has no effect if SCS is compiled with the :code:`NO_TIMER` :ref:`compile flag <compile_flags>`. It can be changed after setup, for example to give the solve what is left of a total time budget, see :ref:`update_settings`.
- Time limit for the solve in seconds (can be fractional). :code:`0` is interpreted as no limit. The clock starts when :code:`scs_solve` is called, so the setup time (e.g., the initial factorization) is not counted, although the time column of the printed output does include it. The limit is only tested when convergence is checked, every 25 iterations (:code:`CONVERGED_INTERVAL` in :code:`include/glbopts.h`), so a solve can overrun it by up to 25 iterations. When the limit is reached SCS returns its best guess with an inaccurate status, or :code:`SCS_INDETERMINATE` when the last iterate gives none, see :ref:`exit flags <exit_flags_limit>`. It has no effect if SCS is compiled with the :code:`NO_TIMER` :ref:`compile flag <compile_flags>`. It can be changed after setup, for example to give the solve what is left of a total time budget, see :ref:`update_settings`.
- :math:`[0, \infty)`
- 0
* - :code:`verbose`
Expand Down Expand Up @@ -224,8 +224,8 @@ How to check it worked
^^^^^^^^^^^^^^^^^^^^^^

A solve stopped by the time limit returns an inaccurate :ref:`exit flag
<exit_flags>` and its status ends in :code:`(inaccurate - reached
time_limit_secs)`. With :code:`verbose` on, :code:`scs_update_settings`
<exit_flags_limit>`, or :code:`SCS_INDETERMINATE`, and its status ends in
:code:`(inaccurate - reached time_limit_secs)`. With :code:`verbose` on, :code:`scs_update_settings`
prints the values now in force, starting :code:`settings updated:`.

What it does not do
Expand Down
14 changes: 14 additions & 0 deletions docs/src/help/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ residuals exceed the requested tolerances. Try:
* **Try adaptive scaling**: set :code:`adaptive_scale=1` (the default). This
automatically tunes the internal :code:`scale` parameter during the solve.

.. _help_indeterminate:

SCS returns ``indeterminate``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The status :code:`indeterminate (inaccurate - reached max_iters)` (exit flag
:code:`SCS_INDETERMINATE`, -3) means SCS ran out of iterations (or hit the
time limit) at an iterate that gives no estimate of a solution or of a
certificate, so x, y and s are NaN (see :ref:`exit_flags_limit`). It happens
in the first few iterations, so with a very small :code:`max_iters` or time
limit, and on runs whose iterates diverged. Try the steps above for
``solved_inaccurate``, starting with a larger :code:`max_iters` or time
limit.

SCS returns ``infeasible`` or ``unbounded`` unexpectedly
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
10 changes: 5 additions & 5 deletions include/scs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ typedef struct SCS_WORK ScsWork;
#define SCS_INFEASIBLE_INACCURATE (-7)
#define SCS_UNBOUNDED_INACCURATE (-6)
#define SCS_SIGINT (-5)
#define SCS_FAILED (-4)
#define SCS_INDETERMINATE (-3)
#define SCS_INFEASIBLE (-2) /* primal infeasible, dual unbounded */
#define SCS_UNBOUNDED (-1) /* primal unbounded, dual infeasible */
#define SCS_UNFINISHED (0) /* never returned, used as placeholder */
#define SCS_FAILED (-4) /* data/internal error, or iterate not finite */
#define SCS_INDETERMINATE (-3) /* limit reached, no estimate: x, y, s NaN */
#define SCS_INFEASIBLE (-2) /* primal infeasible, dual unbounded */
#define SCS_UNBOUNDED (-1) /* primal unbounded, dual infeasible */
#define SCS_UNFINISHED (0) /* never returned, used as placeholder */
#define SCS_SOLVED (1)
#define SCS_SOLVED_INACCURATE (2)

Expand Down
66 changes: 62 additions & 4 deletions src/scs.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ static void update_dual_vars(ScsWork *w);
static scs_int project_cones(ScsWork *w, const ScsCone *k, scs_int iter);
static void finalize(ScsWork *w, ScsSolution *sol, ScsInfo *info,
scs_int iter);
static scs_int all_finite(const scs_float *x, scs_int len);
static void set_diag_r(ScsWork *w);
static ScsWork *init_work(const ScsData *d, const ScsCone *k,
const ScsSettings *stgs);
Expand Down Expand Up @@ -970,8 +971,63 @@ static void set_unbounded(const ScsWork *w, ScsSolution *sol, ScsInfo *info) {
info->status_val = SCS_UNBOUNDED;
}

/* not yet converged, take best guess */
/* No estimate of a solution or of a certificate: x, y, s and every objective
* and residual field are NaN. NaN rather than the last iterate, which is a
* ray with no meaning of its own and can look like a plausible solution. The
* cost: a warm start from this solution starts from zero, as a cold start
* does (warm_start_vars reads NaN as 0); the scale and the per-row
* multipliers still carry over. */
static void set_no_estimate(const ScsWork *w, ScsSolution *sol,
ScsInfo *info) {
SCS(scale_array)(sol->x, NAN, w->d->n);
SCS(scale_array)(sol->y, NAN, w->d->m);
SCS(scale_array)(sol->s, NAN, w->d->m);
info->gap = NAN;
info->res_pri = NAN;
info->res_dual = NAN;
info->pobj = NAN;
info->dobj = NAN;
info->res_infeas = NAN;
info->res_unbdd_a = NAN;
info->res_unbdd_p = NAN;
info->comp_slack = NAN;
}

/* Reached max_iters or time_limit_secs: report what the last iterate
* (x, y, s, tau, kappa) supports, tested in this order.
* - Not finite (a NaN or an infinite entry: the iterate overflowed, or a
* linear solve or BLAS call returned one): SCS_FAILED, status "failure",
* x, y, s NaN. Tested first because such an iterate passes the tests
* below: project_cones sets tau = MAX(NaN, 0) = 0, so it would read as no
* estimate, and with tau > 0 (always at iteration 0) as an inaccurate
* solution.
* - kappa > tau with b'y < 0 or c'x < 0: the inaccurate certificate,
* y / -b'y or (x, s) / -c'x.
* - tau > 0: the inaccurate solution (x, y, s) / tau.
* - Otherwise tau = 0 (project_cones clips it at zero) and b'y >= 0 and
* c'x >= 0: a solution needs tau > 0 and a certificate needs b'y < 0 or
* c'x < 0, so the iterate is an estimate of neither, and no threshold or
* older iterate is used to make one. SCS_INDETERMINATE, x, y, s NaN
* (set_no_estimate). This case also takes tau = kappa = 0, which needs the
* unclipped tau to be exactly zero and has not been seen.
* Every test is exact, so the status is a function of the last iterate alone,
* and the iterates are not changed. Measured on master 4ccf2380 (2026-11-25),
* the indeterminate case comes from two regimes: the first iterations (on
* one-variable LPs with 4 rows, 5,480 of 4.7M runs, all at max_iters 2 or 3)
* and runs whose iterates diverged (netlib beaconfd with CG at eps 1e-4: 19
* of 500 starts at 700 iterations; in the one start examined, iterates of
* size 1e69 to 1e71). Before SCS 3.4.0 it returned SCS_FAILED, the raw
* iterate, and a status of only " (inaccurate - reached max_iters)". */
static void set_unfinished(const ScsWork *w, ScsSolution *sol, ScsInfo *info) {
if (!isfinite(w->r_orig->tau) || !isfinite(w->r_orig->kap) ||
!all_finite(sol->x, w->d->n) || !all_finite(sol->y, w->d->m) ||
!all_finite(sol->s, w->d->m)) {
set_no_estimate(w, sol, info);
strcpy(info->status, "failure");
info->status_val = SCS_FAILED;
scs_printf("Failure:the iterate is not finite (NaN or Inf)\n");
return; /* "failure" takes no "(inaccurate - ...)" suffix */
}
if (w->r_orig->kap > w->r_orig->tau &&
(w->r_orig->bty_tau < 0 || w->r_orig->ctx_tau < 0)) {
if (w->r_orig->bty_tau < 0 &&
Expand All @@ -986,10 +1042,12 @@ static void set_unfinished(const ScsWork *w, ScsSolution *sol, ScsInfo *info) {
set_solved(w, sol, info);
info->status_val = SCS_SOLVED_INACCURATE;
} else {
scs_printf("ERROR: could not determine problem status.\n");
info->status_val = SCS_FAILED;
set_no_estimate(w, sol, info);
strcpy(info->status, "indeterminate");
info->status_val = SCS_INDETERMINATE;
}
/* Append inaccurate to the status string */
/* Append inaccurate to the status string. Every branch above starts it with
* strcpy, so this never appends to what the caller left in info->status. */
if (w->time_limit_reached) {
strcat(info->status, " (inaccurate - reached time_limit_secs)");
} else if (info->iter >= w->stgs->max_iters) {
Expand Down
Loading
Loading