Skip to content

Commit eeef310

Browse files
bodonoclaude
andauthored
Status at the limit: SCS_INDETERMINATE when the iterate gives no estimate (#565)
When SCS stops at max_iters or time_limit_secs at an iterate with tau = 0 (project_cones clips it at zero) and b'y >= 0, c'x >= 0, the iterate is an estimate of neither a solution, which needs tau > 0, nor a certificate, which needs b'y < 0 or c'x < 0. set_unfinished returned SCS_FAILED there, printed "ERROR: could not determine problem status.", left the raw iterate in x, y, s, never wrote pobj, dobj, gap, res_pri and res_dual, and appended " (inaccurate - reached max_iters)" to whatever info->status held (past the end of the field when the caller had not zeroed ScsInfo, as scs-matlab does not). It now returns SCS_INDETERMINATE (-3, no longer deprecated), status "indeterminate (inaccurate - reached max_iters)" (or time_limit_secs), with x, y, s and the objective and residual fields NaN. An iterate that is not finite (NaN or Inf in x, y, s, tau or kappa) is tested first and returns SCS_FAILED, status "failure" with no suffix, the same NaN fields; before, such an iterate could come back as "solved (inaccurate)" (tau is fixed at 1 in iteration 0) or as an inaccurate certificate. Every branch now writes the status before the suffix is appended. All tests are exact, so the status is a function of the last iterate alone; the iterates and the other branches are unchanged. No new setting, field or exit code; the existing all_finite is reused. Tests (box LP min 2x, -2 <= x <= 2): test_indeterminate_at_limit (max_iters 2 with a 0x7f-filled ScsInfo; max_iters 3, the default, and a warm-started re-solve as the other side) and test_nonfinite_at_limit (a warm start at half the largest scs_float, max_iters 1 and 2). Docs: exit flags (the -3 and -4 rows, a section on the status at the limit), settings, info, warm start, termination and help. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 29d96a8 commit eeef310

10 files changed

Lines changed: 406 additions & 18 deletions

File tree

‎docs/src/algorithm/index.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,12 @@ SCS will return one of the two above certificates, whichever one it finds
192192
first. However, in that case the interpretation of infeasibility in one space
193193
being equivalent to unboundedness in the dual space does not hold.
194194

195+
Iteration and time limits
196+
-------------------------
197+
198+
If none of these criteria hold within :code:`max_iters` iterations or
199+
:code:`time_limit_secs` (see :ref:`settings <settings>`), SCS stops and returns
200+
a best guess from its last iterate with an inaccurate status, or
201+
:code:`SCS_INDETERMINATE` when that iterate gives no estimate of a solution or
202+
of a certificate; see :ref:`exit flags <exit_flags_limit>`.
203+

‎docs/src/algorithm/warm_start.rst‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ by setting the warm-start :ref:`setting <settings>` to :code:`True` when calling
4141
y, s` members of the :ref:`ScsSolution` struct, where those members correspond
4242
to the guess of the solution in the :ref:`standard form <optimality>`. SCS will
4343
initialize the solver at those points and then overwrite the :ref:`ScsSolution`
44-
struct members with the real solution at termination.
44+
struct members with the real solution at termination. NaN entries of the guess
45+
are read as zero, so a warm start from a solution that SCS returned as NaN
46+
(after :code:`SCS_INDETERMINATE`, for example, see :ref:`exit flags
47+
<exit_flags_limit>`) starts from zero, as a cold start does; the
48+
:code:`scale` and the per-row multipliers still carry over as described
49+
above.
4550

4651
The settings that only the solve reads, such as the tolerances,
4752
:code:`max_iters` and :code:`time_limit_secs`, can also be changed between

‎docs/src/api/exit_flags.rst‎

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ in the :code:`include/scs.h` file.
2727
* - Primal infeasible / Dual unbounded (to desired tolerance)
2828
- -2
2929
- :code:`SCS_INFEASIBLE`
30-
* - Indeterminate (numerical errors when recovering solution) DEPRECATED
30+
* - Indeterminate: reached :code:`max_iters` or :code:`time_limit_secs`
31+
at an iterate that gives no estimate of a solution or of a
32+
certificate; x, y and s are NaN (see :ref:`below <exit_flags_limit>`)
3133
- -3
3234
- :code:`SCS_INDETERMINATE`
33-
* - Failed: a data input error, or an internal error such as a failed
35+
* - Failed: a data input error, an internal error such as a failed
3436
linear solve (the printed message says which; an internal error asks
35-
you to open an issue)
37+
you to open an issue), or an iterate that is not finite (NaN or Inf)
38+
at :code:`max_iters` or :code:`time_limit_secs`
3639
- -4
3740
- :code:`SCS_FAILED`
3841
* - Interrupted (received SIGINT)
@@ -45,3 +48,61 @@ in the :code:`include/scs.h` file.
4548
- -7
4649
- :code:`SCS_INFEASIBLE_INACCURATE`
4750

51+
52+
.. _exit_flags_limit:
53+
54+
At max_iters or time_limit_secs
55+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
57+
When SCS stops at :code:`max_iters` or :code:`time_limit_secs` before its
58+
:ref:`termination criteria <termination>` hold, it reports what the last
59+
iterate supports. SCS works with a homogeneous iterate :math:`(x, y, s, \tau,
60+
\kappa)`: a solution estimate is :math:`(x, y, s) / \tau`, which needs
61+
:math:`\tau > 0`, and a certificate estimate is :math:`y / (-b^\top y)` or
62+
:math:`(x, s) / (-c^\top x)`, which needs :math:`b^\top y < 0` or
63+
:math:`c^\top x < 0`. The tests below are exact comparisons, taken in this
64+
order, so the status depends only on the last iterate:
65+
66+
.. list-table::
67+
:widths: 40 15 45
68+
:header-rows: 1
69+
70+
* - Last iterate
71+
- Exit flag
72+
- Returned
73+
* - Not finite (a NaN or an infinite entry, for example after an
74+
overflow)
75+
- -4 (:code:`SCS_FAILED`)
76+
- x, y, s and the info fields listed for -3 NaN; status
77+
:code:`failure`
78+
* - :math:`\kappa > \tau` and :math:`b^\top y < 0` or :math:`c^\top x
79+
< 0`
80+
- -7 or -6
81+
- The infeasibility certificate :math:`y / (-b^\top y)` (x and s NaN),
82+
or the unboundedness certificate :math:`(x, s) / (-c^\top x)` (y NaN)
83+
* - :math:`\tau > 0`
84+
- 2
85+
- The solution estimate :math:`(x, y, s) / \tau` and its objective and
86+
residuals
87+
* - Otherwise: :math:`\tau = 0` and :math:`b^\top y \geq 0`,
88+
:math:`c^\top x \geq 0`
89+
- -3 (:code:`SCS_INDETERMINATE`)
90+
- x, y, s NaN, and :code:`pobj`, :code:`dobj`, :code:`gap`,
91+
:code:`res_pri`, :code:`res_dual`, :code:`res_infeas`,
92+
:code:`res_unbdd_a`, :code:`res_unbdd_p` and :code:`comp_slack` NaN
93+
94+
Each status except :code:`failure` ends in :code:`(inaccurate - reached
95+
max_iters)` or :code:`(inaccurate - reached time_limit_secs)`, for example
96+
:code:`indeterminate (inaccurate - reached max_iters)`.
97+
98+
The estimates returned with 2, -6 and -7 do not meet the tolerances. A
99+
certificate estimate rests on the sign of :math:`b^\top y` or :math:`c^\top
100+
x` at the last iterate alone, which on a run whose iterates diverged can
101+
change from one iteration to the next.
102+
103+
SCS returns :code:`SCS_INDETERMINATE` when the cone projection has set
104+
:math:`\tau` to zero and neither :math:`b^\top y` nor :math:`c^\top x` is
105+
negative. This happens in the first few iterations and on runs whose iterates
106+
diverged. As for an inaccurate status, more iterations or more time can help
107+
(see :ref:`help_indeterminate`). A warm start from the NaN solution starts
108+
from zero, as a cold start does (see :ref:`warm_start`).

‎docs/src/api/info.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ the following fields.
8383
- :code:`scs_float`
8484
- Total time (milliseconds) spent in the :ref:`acceleration routine <acceleration>`
8585

86+
When SCS returns :code:`SCS_INDETERMINATE`, or stops at :code:`max_iters` or
87+
:code:`time_limit_secs` with an iterate that is not finite (see :ref:`exit
88+
flags <exit_flags_limit>`), :code:`pobj`, :code:`dobj`, :code:`res_pri`,
89+
:code:`res_dual`, :code:`gap`, :code:`res_infeas`, :code:`res_unbdd_a`,
90+
:code:`res_unbdd_p` and :code:`comp_slack` are NaN, as are x, y and s.
91+
8692
Anderson acceleration statistics
8793
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8894

‎docs/src/api/settings.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ They are set in the :ref:`ScsSettings <ScsSettings>` struct.
4242
- 1e-6 (1e-2 in single precision builds)
4343
* - :code:`max_iters`
4444
- :code:`scs_int`
45-
- Maximum number of iterations to run.
45+
- 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>`.
4646
- :math:`\mathbf{N}`
4747
- 1e5
4848
* - :code:`eps_abs`
@@ -67,7 +67,7 @@ They are set in the :ref:`ScsSettings <ScsSettings>` struct.
6767
- 1.5
6868
* - :code:`time_limit_secs`
6969
- :code:`scs_float`
70-
- 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`.
70+
- 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`.
7171
- :math:`[0, \infty)`
7272
- 0
7373
* - :code:`verbose`
@@ -224,8 +224,8 @@ How to check it worked
224224
^^^^^^^^^^^^^^^^^^^^^^
225225

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

231231
What it does not do

‎docs/src/help/index.rst‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ residuals exceed the requested tolerances. Try:
3636
* **Try adaptive scaling**: set :code:`adaptive_scale=1` (the default). This
3737
automatically tunes the internal :code:`scale` parameter during the solve.
3838

39+
.. _help_indeterminate:
40+
41+
SCS returns ``indeterminate``
42+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43+
44+
The status :code:`indeterminate (inaccurate - reached max_iters)` (exit flag
45+
:code:`SCS_INDETERMINATE`, -3) means SCS ran out of iterations (or hit the
46+
time limit) at an iterate that gives no estimate of a solution or of a
47+
certificate, so x, y and s are NaN (see :ref:`exit_flags_limit`). It happens
48+
in the first few iterations, so with a very small :code:`max_iters` or time
49+
limit, and on runs whose iterates diverged. Try the steps above for
50+
``solved_inaccurate``, starting with a larger :code:`max_iters` or time
51+
limit.
52+
3953
SCS returns ``infeasible`` or ``unbounded`` unexpectedly
4054
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4155

‎include/scs.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ typedef struct SCS_WORK ScsWork;
3333
#define SCS_INFEASIBLE_INACCURATE (-7)
3434
#define SCS_UNBOUNDED_INACCURATE (-6)
3535
#define SCS_SIGINT (-5)
36-
#define SCS_FAILED (-4)
37-
#define SCS_INDETERMINATE (-3)
38-
#define SCS_INFEASIBLE (-2) /* primal infeasible, dual unbounded */
39-
#define SCS_UNBOUNDED (-1) /* primal unbounded, dual infeasible */
40-
#define SCS_UNFINISHED (0) /* never returned, used as placeholder */
36+
#define SCS_FAILED (-4) /* data/internal error, or iterate not finite */
37+
#define SCS_INDETERMINATE (-3) /* limit reached, no estimate: x, y, s NaN */
38+
#define SCS_INFEASIBLE (-2) /* primal infeasible, dual unbounded */
39+
#define SCS_UNBOUNDED (-1) /* primal unbounded, dual infeasible */
40+
#define SCS_UNFINISHED (0) /* never returned, used as placeholder */
4141
#define SCS_SOLVED (1)
4242
#define SCS_SOLVED_INACCURATE (2)
4343

‎src/scs.c‎

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static void update_dual_vars(ScsWork *w);
144144
static scs_int project_cones(ScsWork *w, const ScsCone *k, scs_int iter);
145145
static void finalize(ScsWork *w, ScsSolution *sol, ScsInfo *info,
146146
scs_int iter);
147+
static scs_int all_finite(const scs_float *x, scs_int len);
147148
static void set_diag_r(ScsWork *w);
148149
static ScsWork *init_work(const ScsData *d, const ScsCone *k,
149150
const ScsSettings *stgs);
@@ -970,8 +971,63 @@ static void set_unbounded(const ScsWork *w, ScsSolution *sol, ScsInfo *info) {
970971
info->status_val = SCS_UNBOUNDED;
971972
}
972973

973-
/* not yet converged, take best guess */
974+
/* No estimate of a solution or of a certificate: x, y, s and every objective
975+
* and residual field are NaN. NaN rather than the last iterate, which is a
976+
* ray with no meaning of its own and can look like a plausible solution. The
977+
* cost: a warm start from this solution starts from zero, as a cold start
978+
* does (warm_start_vars reads NaN as 0); the scale and the per-row
979+
* multipliers still carry over. */
980+
static void set_no_estimate(const ScsWork *w, ScsSolution *sol,
981+
ScsInfo *info) {
982+
SCS(scale_array)(sol->x, NAN, w->d->n);
983+
SCS(scale_array)(sol->y, NAN, w->d->m);
984+
SCS(scale_array)(sol->s, NAN, w->d->m);
985+
info->gap = NAN;
986+
info->res_pri = NAN;
987+
info->res_dual = NAN;
988+
info->pobj = NAN;
989+
info->dobj = NAN;
990+
info->res_infeas = NAN;
991+
info->res_unbdd_a = NAN;
992+
info->res_unbdd_p = NAN;
993+
info->comp_slack = NAN;
994+
}
995+
996+
/* Reached max_iters or time_limit_secs: report what the last iterate
997+
* (x, y, s, tau, kappa) supports, tested in this order.
998+
* - Not finite (a NaN or an infinite entry: the iterate overflowed, or a
999+
* linear solve or BLAS call returned one): SCS_FAILED, status "failure",
1000+
* x, y, s NaN. Tested first because such an iterate passes the tests
1001+
* below: project_cones sets tau = MAX(NaN, 0) = 0, so it would read as no
1002+
* estimate, and with tau > 0 (always at iteration 0) as an inaccurate
1003+
* solution.
1004+
* - kappa > tau with b'y < 0 or c'x < 0: the inaccurate certificate,
1005+
* y / -b'y or (x, s) / -c'x.
1006+
* - tau > 0: the inaccurate solution (x, y, s) / tau.
1007+
* - Otherwise tau = 0 (project_cones clips it at zero) and b'y >= 0 and
1008+
* c'x >= 0: a solution needs tau > 0 and a certificate needs b'y < 0 or
1009+
* c'x < 0, so the iterate is an estimate of neither, and no threshold or
1010+
* older iterate is used to make one. SCS_INDETERMINATE, x, y, s NaN
1011+
* (set_no_estimate). This case also takes tau = kappa = 0, which needs the
1012+
* unclipped tau to be exactly zero and has not been seen.
1013+
* Every test is exact, so the status is a function of the last iterate alone,
1014+
* and the iterates are not changed. Measured on master 4ccf2380 (2026-11-25),
1015+
* the indeterminate case comes from two regimes: the first iterations (on
1016+
* one-variable LPs with 4 rows, 5,480 of 4.7M runs, all at max_iters 2 or 3)
1017+
* and runs whose iterates diverged (netlib beaconfd with CG at eps 1e-4: 19
1018+
* of 500 starts at 700 iterations; in the one start examined, iterates of
1019+
* size 1e69 to 1e71). Before SCS 3.4.0 it returned SCS_FAILED, the raw
1020+
* iterate, and a status of only " (inaccurate - reached max_iters)". */
9741021
static void set_unfinished(const ScsWork *w, ScsSolution *sol, ScsInfo *info) {
1022+
if (!isfinite(w->r_orig->tau) || !isfinite(w->r_orig->kap) ||
1023+
!all_finite(sol->x, w->d->n) || !all_finite(sol->y, w->d->m) ||
1024+
!all_finite(sol->s, w->d->m)) {
1025+
set_no_estimate(w, sol, info);
1026+
strcpy(info->status, "failure");
1027+
info->status_val = SCS_FAILED;
1028+
scs_printf("Failure:the iterate is not finite (NaN or Inf)\n");
1029+
return; /* "failure" takes no "(inaccurate - ...)" suffix */
1030+
}
9751031
if (w->r_orig->kap > w->r_orig->tau &&
9761032
(w->r_orig->bty_tau < 0 || w->r_orig->ctx_tau < 0)) {
9771033
if (w->r_orig->bty_tau < 0 &&
@@ -986,10 +1042,12 @@ static void set_unfinished(const ScsWork *w, ScsSolution *sol, ScsInfo *info) {
9861042
set_solved(w, sol, info);
9871043
info->status_val = SCS_SOLVED_INACCURATE;
9881044
} else {
989-
scs_printf("ERROR: could not determine problem status.\n");
990-
info->status_val = SCS_FAILED;
1045+
set_no_estimate(w, sol, info);
1046+
strcpy(info->status, "indeterminate");
1047+
info->status_val = SCS_INDETERMINATE;
9911048
}
992-
/* Append inaccurate to the status string */
1049+
/* Append inaccurate to the status string. Every branch above starts it with
1050+
* strcpy, so this never appends to what the caller left in info->status. */
9931051
if (w->time_limit_reached) {
9941052
strcat(info->status, " (inaccurate - reached time_limit_secs)");
9951053
} else if (info->iter >= w->stgs->max_iters) {

0 commit comments

Comments
 (0)