scs 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/ext/scs/extconf.rb +3 -9
  4. data/lib/scs/version.rb +1 -1
  5. data/vendor/scs/CITATION.cff +2 -2
  6. data/vendor/scs/CMakeLists.txt +138 -10
  7. data/vendor/scs/CONTRIBUTING.md +21 -2
  8. data/vendor/scs/Makefile +4 -3
  9. data/vendor/scs/README.md +25 -14
  10. data/vendor/scs/include/cones.h +27 -9
  11. data/vendor/scs/include/glbopts.h +25 -5
  12. data/vendor/scs/include/scs.h +10 -8
  13. data/vendor/scs/include/scs_work.h +2 -1
  14. data/vendor/scs/linsys/cudss/direct/private.c +50 -2
  15. data/vendor/scs/linsys/gpu/indirect/private.c +17 -4
  16. data/vendor/scs/linsys/mkl/direct/private.c +1 -1
  17. data/vendor/scs/scs.mk +43 -2
  18. data/vendor/scs/src/aa.c +27 -7
  19. data/vendor/scs/src/cones.c +851 -163
  20. data/vendor/scs/src/linalg.c +16 -3
  21. data/vendor/scs/src/scs.c +91 -46
  22. data/vendor/scs/src/spectral_cones/logdeterminant/logdet_cone.c +15 -14
  23. data/vendor/scs/src/spectral_cones/nuclear/ell1_cone.c +1 -4
  24. data/vendor/scs/src/spectral_cones/sum-largest/sum_largest_eval_cone.c +11 -9
  25. data/vendor/scs/test/minunit.h +27 -3
  26. data/vendor/scs/test/mkl_psd_guard.c +282 -0
  27. data/vendor/scs/test/problem_utils.h +123 -22
  28. data/vendor/scs/test/problems/complex_PSD.h +2 -1
  29. data/vendor/scs/test/problems/degenerate.h +10 -3
  30. data/vendor/scs/test/problems/dense_qp.h +2 -1
  31. data/vendor/scs/test/problems/hs21_tiny_qp.h +7 -3
  32. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +5 -2
  33. data/vendor/scs/test/problems/issue_140 +0 -0
  34. data/vendor/scs/test/problems/issue_140.h +19 -0
  35. data/vendor/scs/test/problems/issue_220 +0 -0
  36. data/vendor/scs/test/problems/issue_220.h +37 -0
  37. data/vendor/scs/test/problems/issue_499.h +79 -0
  38. data/vendor/scs/test/problems/lp_update.h +5 -5
  39. data/vendor/scs/test/problems/qafiro_tiny_qp.h +25 -5
  40. data/vendor/scs/test/problems/rob_gauss_cov_est.h +24 -4
  41. data/vendor/scs/test/problems/sd_and_complex_sd.h +2 -1
  42. data/vendor/scs/test/problems/small_lp.h +2 -1
  43. data/vendor/scs/test/problems/small_qp.h +7 -0
  44. data/vendor/scs/test/problems/test_box_cone.h +2 -1
  45. data/vendor/scs/test/problems/test_dual_exp_cone.h +2 -1
  46. data/vendor/scs/test/problems/test_mixed_cones.h +2 -1
  47. data/vendor/scs/test/problems/test_non_psd_p.h +76 -0
  48. data/vendor/scs/test/problems/test_normalize_roundtrip.h +14 -12
  49. data/vendor/scs/test/problems/test_power_cone.h +139 -5
  50. data/vendor/scs/test/problems/test_prob_from_data_file.h +14 -4
  51. data/vendor/scs/test/problems/test_psd_metric.h +11 -7
  52. data/vendor/scs/test/problems/test_psd_n1.h +2 -1
  53. data/vendor/scs/test/problems/test_psd_parallel.h +383 -0
  54. data/vendor/scs/test/problems/test_psd_scale_updates.h +186 -0
  55. data/vendor/scs/test/problems/test_soc_sizes.h +10 -5
  56. data/vendor/scs/test/problems/test_solver_options.h +10 -3
  57. data/vendor/scs/test/problems/test_zero_cone.h +2 -1
  58. data/vendor/scs/test/run_from_file.c +8 -0
  59. data/vendor/scs/test/run_tests.c +84 -19
  60. data/vendor/scs/test/spectral_cones_problems/exp_design.h +1 -0
  61. data/vendor/scs/test/spectral_cones_problems/several_logdet_cones.h +1 -0
  62. data/vendor/scs/test/spectral_cones_problems/test_spectral_metric_updates.h +163 -0
  63. metadata +12 -3
  64. data/vendor/scs/CLAUDE.md +0 -115
@@ -0,0 +1,282 @@
1
+ #ifndef _GNU_SOURCE
2
+ #define _GNU_SOURCE /* RTLD_DEEPBIND */
3
+ #endif
4
+
5
+ #include "scs.h"
6
+
7
+ #include <dlfcn.h>
8
+ #include <math.h>
9
+ #include <stdio.h>
10
+ #include <stdlib.h>
11
+ #include <string.h>
12
+
13
+ /* Checks, with a real MKL, the guard of the parallel PSD projection: each of
14
+ * its threads sets MKL's thread-local thread count to one
15
+ * (MKL_Set_Num_Threads_Local, in src/cones.c), so that MKL starts no threads
16
+ * of its own in the threads of SCS. Built and run only by
17
+ * .github/workflows/build_openmp_mkl.yml, which has the checks.
18
+ *
19
+ * This program loads an SCS library the way wrappers do: it links neither
20
+ * SCS, MKL nor an OpenMP runtime, and opens the library given as its argument
21
+ * with a local scope. It solves an SDP with four PSD blocks and prints what
22
+ * the workflow needs: the result, the number of threads of the process, and
23
+ * the OpenMP runtimes and MKL threading layers that are loaded. With
24
+ * MKL_VERBOSE=1 in the environment, MKL itself prints each of its calls with
25
+ * the number of threads that the call was allowed.
26
+ *
27
+ * The OpenMP runtime of MKL depends on what is loaded when MKL starts:
28
+ * - By default SCS is loaded first, and libgomp with it. MKL then takes its
29
+ * GNU threading layer, on that same libgomp (seen with oneMKL 2026), and
30
+ * sees the parallel region of SCS.
31
+ * - With MKL_PSD_GUARD_MKL_FIRST=<path of libmkl_rt> in the environment, MKL
32
+ * is loaded and started first. No OpenMP runtime is loaded yet, so it takes
33
+ * its Intel threading layer, on libiomp5. SCS is then loaded with deep
34
+ * binding, as Julia loads libraries, which keeps its regions on libgomp.
35
+ * MKL cannot see them: this is the case that the guard is for.
36
+ *
37
+ * usage: mkl_psd_guard <SCS shared library> [iterations]
38
+ * With a number of iterations the run stops there, for the checks that need
39
+ * only a few projections; without, the solve must succeed.
40
+ *
41
+ * The problem is: minimize x subject to I - x * M_k >= 0 (PSD) for each block
42
+ * k, with M_k = I - (1 + a_k) v_k v_k' for a unit vector v_k. M_k has the
43
+ * eigenvalues 1 and -a_k, so the constraints are -1 / a_k <= x <= 1. The
44
+ * largest a_k is 1, so the solution is x = -1.
45
+ */
46
+
47
+ #define PSD_N 200
48
+ #define PSD_BLOCKS 4
49
+ #define PSD_LEN (PSD_N * (PSD_N + 1) / 2)
50
+
51
+ typedef ScsWork *(*init_fn)(const ScsData *, const ScsCone *,
52
+ const ScsSettings *);
53
+ typedef scs_int (*solve_fn)(ScsWork *, ScsSolution *, ScsInfo *, scs_int);
54
+ typedef void (*finish_fn)(ScsWork *);
55
+ typedef void (*defaults_fn)(ScsSettings *);
56
+ typedef int (*mkl_set_local_fn)(int);
57
+ typedef int (*mkl_get_max_fn)(void);
58
+
59
+ /* uniform in (-1, 1), from a linear congruential generator */
60
+ static double next_rand(unsigned long *state) {
61
+ *state = (*state * 1103515245UL + 12345UL) & 0x7fffffffUL;
62
+ return 2. * ((double)*state + 0.5) / 2147483648. - 1.;
63
+ }
64
+
65
+ /* Number of threads of this process, or -1 where /proc does not give it */
66
+ static int os_threads(void) {
67
+ char line[256];
68
+ int n = -1;
69
+ FILE *f = fopen("/proc/self/status", "r");
70
+ if (!f) {
71
+ return -1;
72
+ }
73
+ while (fgets(line, sizeof(line), f)) {
74
+ if (sscanf(line, "Threads: %d", &n) == 1) {
75
+ break;
76
+ }
77
+ }
78
+ fclose(f);
79
+ return n;
80
+ }
81
+
82
+ /* Print the OpenMP runtimes and MKL threading layers loaded in this process */
83
+ static void print_runtimes(void) {
84
+ static const char *const names[] = {
85
+ "libgomp", "libiomp", "libomp.",
86
+ "libmkl_intel_thr", "libmkl_gnu_thr", "libmkl_sequential",
87
+ "libmkl_tbb_thread", "libtbb",
88
+ };
89
+ char line[1024], seen[16][256], *path;
90
+ int n_seen = 0, n_names = (int)(sizeof(names) / sizeof(names[0])), i;
91
+ FILE *f = fopen("/proc/self/maps", "r");
92
+ if (!f) {
93
+ return;
94
+ }
95
+ printf("mkl_psd_guard: loaded");
96
+ while (n_seen < 16 && fgets(line, sizeof(line), f)) {
97
+ path = strchr(line, '/');
98
+ if (!path) {
99
+ continue;
100
+ }
101
+ path[strcspn(path, "\n")] = '\0';
102
+ for (i = 0; i < n_names && !strstr(path, names[i]); ++i) {
103
+ }
104
+ if (i == n_names || strlen(path) >= sizeof(seen[0])) {
105
+ continue;
106
+ }
107
+ for (i = 0; i < n_seen && strcmp(seen[i], path) != 0; ++i) {
108
+ }
109
+ if (i == n_seen) {
110
+ strcpy(seen[n_seen++], path);
111
+ printf(" %s", path);
112
+ }
113
+ }
114
+ printf("\n");
115
+ fclose(f);
116
+ }
117
+
118
+ int main(int argc, char **argv) {
119
+ scs_int m = PSD_BLOCKS * PSD_LEN, blocks[PSD_BLOCKS];
120
+ scs_int i, j, k, idx = 0, status = -1;
121
+ scs_float c[1] = {1.};
122
+ scs_int A_p[2] = {0, 0};
123
+ scs_float *A_x, *b;
124
+ scs_int *A_i;
125
+ double v[PSD_N], nrm, a, x = 0.;
126
+ unsigned long seed = 1234;
127
+ int mkl_nt = 0, mkl_now = 0, threads, fail = 0;
128
+ int short_run = argc > 2, flags = RTLD_NOW | RTLD_LOCAL;
129
+ const char *mkl_first = getenv("MKL_PSD_GUARD_MKL_FIRST");
130
+ ScsMatrix A = {0};
131
+ ScsData d = {0};
132
+ ScsCone cone = {0};
133
+ ScsSettings stgs;
134
+ ScsSolution sol = {0};
135
+ ScsInfo info;
136
+ ScsWork *w;
137
+ void *lib;
138
+ init_fn init = 0;
139
+ solve_fn solve = 0;
140
+ finish_fn finish = 0;
141
+ defaults_fn defaults = 0;
142
+ mkl_set_local_fn mkl_set_local = 0;
143
+ mkl_get_max_fn mkl_get_max = 0;
144
+
145
+ if (argc < 2) {
146
+ fprintf(stderr, "usage: %s <SCS shared library> [iterations]\n", argv[0]);
147
+ return 1;
148
+ }
149
+ setvbuf(stdout, NULL, _IOLBF, 0); /* keep the output if the solve crashes */
150
+ if (mkl_first && *mkl_first) {
151
+ /* MKL chooses its threading layer in its first call */
152
+ lib = dlopen(mkl_first, RTLD_NOW | RTLD_LOCAL);
153
+ if (lib) {
154
+ *(void **)(&mkl_get_max) = dlsym(lib, "MKL_Get_Max_Threads");
155
+ }
156
+ if (!lib || !mkl_get_max) {
157
+ fprintf(stderr, "cannot start MKL from %s\n", mkl_first);
158
+ return 1;
159
+ }
160
+ mkl_get_max();
161
+ #ifdef RTLD_DEEPBIND
162
+ flags |= RTLD_DEEPBIND;
163
+ #endif
164
+ }
165
+ lib = dlopen(argv[1], flags);
166
+ if (!lib) {
167
+ fprintf(stderr, "cannot load %s: %s\n", argv[1], dlerror());
168
+ return 1;
169
+ }
170
+ /* the assignment through void ** is the conversion POSIX asks for */
171
+ *(void **)(&init) = dlsym(lib, "scs_init");
172
+ *(void **)(&solve) = dlsym(lib, "scs_solve");
173
+ *(void **)(&finish) = dlsym(lib, "scs_finish");
174
+ *(void **)(&defaults) = dlsym(lib, "scs_set_default_settings");
175
+ if (!init || !solve || !finish || !defaults) {
176
+ fprintf(stderr, "%s is not an SCS library\n", argv[1]);
177
+ return 1;
178
+ }
179
+ /* MKL's own functions, found among the libraries that SCS brings in */
180
+ *(void **)(&mkl_set_local) = dlsym(lib, "MKL_Set_Num_Threads_Local");
181
+ *(void **)(&mkl_get_max) = dlsym(lib, "MKL_Get_Max_Threads");
182
+
183
+ A_x = (scs_float *)calloc(m, sizeof(scs_float));
184
+ A_i = (scs_int *)calloc(m, sizeof(scs_int));
185
+ b = (scs_float *)calloc(m, sizeof(scs_float));
186
+ if (!A_x || !A_i || !b) {
187
+ fprintf(stderr, "out of memory\n");
188
+ return 1;
189
+ }
190
+ /* column 0 of A is M_k and b is the identity, block after block: the lower
191
+ * triangle by columns, off-diagonal entries scaled by sqrt(2) */
192
+ for (k = 0; k < PSD_BLOCKS; ++k) {
193
+ blocks[k] = PSD_N;
194
+ a = 1. - 0.1 * (double)k;
195
+ nrm = 0.;
196
+ for (i = 0; i < PSD_N; ++i) {
197
+ v[i] = next_rand(&seed);
198
+ nrm += v[i] * v[i];
199
+ }
200
+ nrm = sqrt(nrm);
201
+ for (i = 0; i < PSD_N; ++i) {
202
+ v[i] /= nrm;
203
+ }
204
+ for (j = 0; j < PSD_N; ++j) {
205
+ for (i = j; i < PSD_N; ++i) {
206
+ A_i[idx] = idx;
207
+ if (i == j) {
208
+ A_x[idx] = 1. - (1. + a) * v[i] * v[i];
209
+ b[idx] = 1.;
210
+ } else {
211
+ A_x[idx] = -sqrt(2.) * (1. + a) * v[i] * v[j];
212
+ }
213
+ ++idx;
214
+ }
215
+ }
216
+ }
217
+ A_p[1] = m;
218
+ A.x = A_x;
219
+ A.i = A_i;
220
+ A.p = A_p;
221
+ A.m = m;
222
+ A.n = 1;
223
+ d.m = m;
224
+ d.n = 1;
225
+ d.A = &A;
226
+ d.b = b;
227
+ d.c = c;
228
+ cone.s = blocks;
229
+ cone.ssize = PSD_BLOCKS;
230
+ defaults(&stgs);
231
+ stgs.verbose = 1; /* the header says whether the projection is parallel */
232
+ if (short_run) {
233
+ stgs.max_iters = (scs_int)atoi(argv[2]);
234
+ }
235
+
236
+ w = init(&d, &cone, &stgs);
237
+ if (w) {
238
+ if (mkl_set_local && mkl_get_max) {
239
+ /* A thread-local setting for this thread, equal to the global one so
240
+ * that it changes nothing: the projection must leave it as it is. */
241
+ mkl_nt = mkl_get_max();
242
+ mkl_set_local(mkl_nt);
243
+ }
244
+ status = solve(w, &sol, &info, 0);
245
+ x = sol.x ? (double)sol.x[0] : 0.;
246
+ }
247
+ threads = os_threads();
248
+ if (mkl_set_local && mkl_get_max) {
249
+ mkl_now = mkl_set_local(0); /* returns the setting and removes it */
250
+ }
251
+ print_runtimes();
252
+
253
+ printf("mkl_psd_guard: status=%d iters=%ld x=%.6f os_threads=%d "
254
+ "mkl_threads=%d mkl_threads_after=%d\n",
255
+ (int)status, w ? (long)info.iter : 0L, x, threads, mkl_nt, mkl_now);
256
+ if (!w) {
257
+ fprintf(stderr, "mkl_psd_guard: scs_init failed\n");
258
+ fail = 1;
259
+ } else if (!short_run && (status != SCS_SOLVED || fabs(x + 1.) > 1e-2)) {
260
+ fprintf(stderr, "mkl_psd_guard: wrong solve, expected status %d, x = -1\n",
261
+ (int)SCS_SOLVED);
262
+ fail = 1;
263
+ }
264
+ if (mkl_now != mkl_nt) {
265
+ fprintf(stderr,
266
+ "mkl_psd_guard: the solve changed the MKL thread setting of its "
267
+ "caller from %d to %d\n",
268
+ mkl_nt, mkl_now);
269
+ fail = 1;
270
+ }
271
+ if (w) {
272
+ finish(w);
273
+ }
274
+ free(sol.x);
275
+ free(sol.y);
276
+ free(sol.s);
277
+ free(A_x);
278
+ free(A_i);
279
+ free(b);
280
+ /* the library stays loaded: its OpenMP threads are still there */
281
+ return fail;
282
+ }
@@ -14,6 +14,46 @@
14
14
 
15
15
  #define _MAX_RAND_VAL (1073741823) /* 2^30 - 1 */
16
16
 
17
+ /* The tolerances and checks in this suite assume double precision: many sit
18
+ * below what a single-precision solve can reach (machine epsilon is 1.2e-7, and
19
+ * the KKT solve loses a further factor of 1 / rho_x). So in SFLOAT builds every
20
+ * solve is run with tolerances no tighter than these, which keeps each test's
21
+ * problem and expected status while asking for an achievable accuracy. A
22
+ * tolerance of zero or less is left alone since it can be deliberate (disabling
23
+ * a check) or the invalid input a validation test wants rejected. */
24
+ #ifdef SFLOAT
25
+ #define SFLOAT_TEST_EPS (1e-4)
26
+ #define SFLOAT_TEST_EPS_INFEAS (1e-4)
27
+ static void raise_tols_for_single_precision(ScsSettings *stgs) {
28
+ if (!stgs) {
29
+ return;
30
+ }
31
+ if (stgs->eps_abs > 0 && stgs->eps_abs < SFLOAT_TEST_EPS) {
32
+ stgs->eps_abs = SFLOAT_TEST_EPS;
33
+ }
34
+ if (stgs->eps_rel > 0 && stgs->eps_rel < SFLOAT_TEST_EPS) {
35
+ stgs->eps_rel = SFLOAT_TEST_EPS;
36
+ }
37
+ if (stgs->eps_infeas > 0 && stgs->eps_infeas < SFLOAT_TEST_EPS_INFEAS) {
38
+ stgs->eps_infeas = SFLOAT_TEST_EPS_INFEAS;
39
+ }
40
+ }
41
+ #define scs_init(d, k, stgs) \
42
+ (raise_tols_for_single_precision(stgs), scs_init(d, k, stgs))
43
+ #define scs(d, k, stgs, sol, info) \
44
+ (raise_tols_for_single_precision(stgs), scs(d, k, stgs, sol, info))
45
+ /* double, single: recomputing a residual or objective outside the solver
46
+ * disagrees by roundoff, about 1e-7 of the magnitudes involved */
47
+ #define VERIFY_TOL(dbl, sgl) (sgl)
48
+ #else
49
+ #define VERIFY_TOL(dbl, sgl) (dbl)
50
+ #endif
51
+ /* how close a solve must get to a known optimal objective or solution */
52
+ #define SOL_TOL VERIFY_TOL(1e-4, 1e-2)
53
+ /* the solver stops as soon as it meets its tolerances, so its roundoff can put
54
+ * a recomputed residual just outside them */
55
+ #define FEAS_SLACK VERIFY_TOL(1., 1.1)
56
+
17
57
  /* uniform random number in [-1,1] */
18
58
  static scs_float rand_scs_float(void) {
19
59
  return 2 * (((scs_float)ran_arr_next()) / _MAX_RAND_VAL) - 1; /* in [-1, 1] */
@@ -39,6 +79,11 @@ void gen_random_prob_data(scs_int nnz, scs_int col_nnz, ScsData *d, ScsCone *k,
39
79
  A->x = (scs_float *)scs_calloc(nnz, sizeof(scs_float));
40
80
  A->n = d->n;
41
81
  A->m = d->m;
82
+ /* seed before the first draw, so that the generated instance is a pure
83
+ * function of (seed, n, m, nnz, col_nnz, k) rather than of whatever state
84
+ * the generator was left in by an earlier caller */
85
+ ran_start(seed);
86
+
42
87
  /* y, s >= 0 and y'*s = 0 */
43
88
  for (i = 0; i < m; i++) {
44
89
  y[i] = z[i] = rand_scs_float();
@@ -59,7 +104,6 @@ void gen_random_prob_data(scs_int nnz, scs_int col_nnz, ScsData *d, ScsCone *k,
59
104
  c = -A'*y
60
105
  b = A*x + s
61
106
  */
62
- ran_start(seed);
63
107
  A->p[0] = 0;
64
108
  for (j = 0; j < n; j++) { /* column */
65
109
  r = 0;
@@ -80,6 +124,47 @@ void gen_random_prob_data(scs_int nnz, scs_int col_nnz, ScsData *d, ScsCone *k,
80
124
  scs_free(z);
81
125
  }
82
126
 
127
+ /* Tolerance on the cone distances that the tests assert.
128
+ *
129
+ * A distance is measured with the cone projection itself, so it is only as
130
+ * accurate as that projection. Every projection is closed-form or converges
131
+ * to rounding, except the logdet cone's: that one is an iterative solve that
132
+ * falls back from Newton to an interior-point method, and the fallback can
133
+ * stop with a primal residual near 1e-4 (log_cone_wrapper accepts residuals
134
+ * up to 1e-2). A point on the boundary of the cone, inside it to 1e-16, has
135
+ * measured 2e-5 away that way.
136
+ *
137
+ * Which solves end on such a point is decided by rounding. With the data of
138
+ * test_spectral_metric_updates perturbed by 1e-13, about one solve in a
139
+ * thousand measured 2e-5 and none measured more than 2.2e-5, so a limit of
140
+ * 1e-5 fails whenever a change to the solver, the BLAS or the CPU moves the
141
+ * iterates onto one. 1e-3 is about 50 times the largest value seen. */
142
+ static scs_float cone_dist_tol(const ScsCone *k) {
143
+ #ifdef USE_SPECTRAL_CONES
144
+ if (k->dsize > 0) {
145
+ return 1e-3;
146
+ }
147
+ #endif
148
+ (void)k;
149
+ return 1e-5;
150
+ }
151
+
152
+ /* distance of v (length len) from the cone: in single precision a projection
153
+ * is accurate to about 1e-7 of the vector's size, so the limit grows with it */
154
+ #define CONE_DIST_TOL(k, v, len) \
155
+ VERIFY_TOL(cone_dist_tol(k), \
156
+ MAX(cone_dist_tol(k), 1e-4 * (1 + NORM(v, len))))
157
+
158
+ /* single precision: the rounding in recomputing M v, where v is a certificate
159
+ * (scaled so that b'y or c'x is -1, so its size is set by the problem) and the
160
+ * product nearly cancels: a few machine epsilons of ||M||_F ||v|| */
161
+ #define PRODUCT_ROUND(M, v, len) \
162
+ (1e-5 * (1 + NORM((M)->x, (M)->p[(M)->n]) * NORM(v, len)))
163
+ /* the same for |Ax + s| and |Px| of an unboundedness certificate x */
164
+ #define UNBDD_A_ROUND(d, x, s, n, m) \
165
+ (PRODUCT_ROUND((d)->A, x, n) + 1e-5 * NORM(s, m))
166
+ #define UNBDD_P_ROUND(d, x, n) ((d)->P ? PRODUCT_ROUND((d)->P, x, n) : 0.)
167
+
83
168
  static scs_float get_dual_cone_dist(const scs_float *y, ScsConeWork *c,
84
169
  scs_int m) {
85
170
  scs_float dist;
@@ -213,39 +298,55 @@ const char *verify_solution_correct(ScsData *d, ScsCone *k, ScsSettings *stgs,
213
298
  * quantities (~ the objective scale), like the gap and objective
214
299
  * checks below already do */
215
300
  mu_assert_less("Primal residual ERROR", ABS(res_pri - info->res_pri),
216
- 1e-10 * (1 + ABS(pobj)));
301
+ VERIFY_TOL(1e-10, 1e-4) * (1 + ABS(pobj)));
217
302
  mu_assert_less("Dual residual ERROR", ABS(res_dual - info->res_dual),
218
- 1e-10 * (1 + ABS(pobj)));
219
- mu_assert_less("Gap ERROR", ABS(gap - info->gap), 1e-7 * (1 + ABS(gap)));
303
+ VERIFY_TOL(1e-10, 1e-4) * (1 + ABS(pobj)));
304
+ mu_assert_less("Gap ERROR", ABS(gap - info->gap),
305
+ VERIFY_TOL(1e-7 * (1 + ABS(gap)), 1e-4 * (1 + grl)));
220
306
  mu_assert_less("Primal obj ERROR", ABS(pobj - info->pobj),
221
- 1e-9 * (1 + ABS(pobj)));
307
+ VERIFY_TOL(1e-9, 1e-4) * (1 + ABS(pobj)));
222
308
  mu_assert_less("Dual obj ERROR", ABS(dobj - info->dobj),
223
- 1e-9 * (1 + ABS(dobj)));
309
+ VERIFY_TOL(1e-9, 1e-4) * (1 + ABS(dobj)));
224
310
  /* slightly looser tol */
225
311
  mu_assert_less("Complementary slackness ERROR", ABS(sty),
226
- 5e-8 * MAX(NORM(s, m), NORM(y, m)));
227
- mu_assert_less("s cone dist ERROR", ABS(sdist), 1e-5);
228
- mu_assert_less("y cone dist ERROR", ABS(ydist), 1e-5);
312
+ VERIFY_TOL(5e-8, 1e-4) * MAX(NORM(s, m), NORM(y, m)));
313
+ mu_assert_less("s cone dist ERROR", ABS(sdist), CONE_DIST_TOL(k, s, m));
314
+ mu_assert_less("y cone dist ERROR", ABS(ydist), CONE_DIST_TOL(k, y, m));
229
315
 
230
316
  mu_assert_less("Primal feas ERROR", res_pri,
231
- stgs->eps_abs + stgs->eps_rel * prl);
317
+ FEAS_SLACK * (stgs->eps_abs + stgs->eps_rel * prl));
232
318
  mu_assert_less("Dual feas ERROR", res_dual,
233
- stgs->eps_abs + stgs->eps_rel * drl);
234
- mu_assert_less("Gap feas ERROR", gap, stgs->eps_abs + stgs->eps_rel * grl);
319
+ FEAS_SLACK * (stgs->eps_abs + stgs->eps_rel * drl));
320
+ mu_assert_less("Gap feas ERROR", gap,
321
+ FEAS_SLACK * (stgs->eps_abs + stgs->eps_rel * grl));
235
322
 
236
323
  } else if (status == SCS_INFEASIBLE) {
237
- mu_assert_less("Infeas ERROR", ABS(res_infeas - info->res_infeas), 1e-8);
238
- mu_assert_less("bty ERROR", ABS(bty + 1), 1e-12);
239
- mu_assert_less("y cone dist ERROR", ABS(ydist), 1e-5);
240
- mu_assert_less("Infeas invalid ERROR", res_infeas, stgs->eps_infeas);
324
+ mu_assert_less("Infeas ERROR", ABS(res_infeas - info->res_infeas),
325
+ VERIFY_TOL(1e-8, PRODUCT_ROUND(d->A, y, m)));
326
+ /* the solver scales y so that b'y = -1; recomputing the sum rounds in
327
+ * proportion to its terms, which can be far larger than 1 */
328
+ mu_assert_less("bty ERROR", ABS(bty + 1),
329
+ VERIFY_TOL(1e-12, 1e-5 * (1 + NORM(b, m) * NORM(y, m))));
330
+ mu_assert_less("y cone dist ERROR", ABS(ydist), CONE_DIST_TOL(k, y, m));
331
+ mu_assert_less("Infeas invalid ERROR", res_infeas,
332
+ FEAS_SLACK * stgs->eps_infeas +
333
+ VERIFY_TOL(0., PRODUCT_ROUND(d->A, y, m)));
241
334
 
242
335
  } else if (status == SCS_UNBOUNDED) {
243
- mu_assert_less("Unbdd_a ERROR", ABS(res_unbdd_a - info->res_unbdd_a), 1e-8);
244
- mu_assert_less("Unbdd_p ERROR", ABS(res_unbdd_p - info->res_unbdd_p), 1e-8);
245
- mu_assert_less("ctx ERROR", ABS(ctx + 1), 1e-12);
246
- mu_assert_less("s cone dist ERROR", ABS(sdist), 1e-5);
247
- mu_assert_less("Unbounded P invalid ERROR", res_unbdd_p, stgs->eps_infeas);
248
- mu_assert_less("Unbounded A invalid ERROR", res_unbdd_a, stgs->eps_infeas);
336
+ mu_assert_less("Unbdd_a ERROR", ABS(res_unbdd_a - info->res_unbdd_a),
337
+ VERIFY_TOL(1e-8, UNBDD_A_ROUND(d, x, s, n, m)));
338
+ mu_assert_less("Unbdd_p ERROR", ABS(res_unbdd_p - info->res_unbdd_p),
339
+ VERIFY_TOL(1e-8, UNBDD_P_ROUND(d, x, n)));
340
+ /* as for b'y above */
341
+ mu_assert_less("ctx ERROR", ABS(ctx + 1),
342
+ VERIFY_TOL(1e-12, 1e-5 * (1 + NORM(c, n) * NORM(x, n))));
343
+ mu_assert_less("s cone dist ERROR", ABS(sdist), CONE_DIST_TOL(k, s, m));
344
+ mu_assert_less("Unbounded P invalid ERROR", res_unbdd_p,
345
+ FEAS_SLACK * stgs->eps_infeas +
346
+ VERIFY_TOL(0., UNBDD_P_ROUND(d, x, n)));
347
+ mu_assert_less("Unbounded A invalid ERROR", res_unbdd_a,
348
+ FEAS_SLACK * stgs->eps_infeas +
349
+ VERIFY_TOL(0., UNBDD_A_ROUND(d, x, s, n, m)));
249
350
 
250
351
  } else {
251
352
  return "INVALID STATUS";
@@ -65,7 +65,8 @@ static const char *complex_PSD(void) {
65
65
  scs_printf("primal obj error %4e\n", perr);
66
66
  scs_printf("dual obj error %4e\n", derr);
67
67
 
68
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
68
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
69
+ exitflag == SCS_SOLVED;
69
70
 
70
71
  mu_assert("complex_PSD: SCS failed to produce outputflag SCS_SOLVED",
71
72
  success);
@@ -7,6 +7,10 @@
7
7
  #include "util.h"
8
8
 
9
9
  /* test degenerate cones */
10
+ /* The four solves below pose one problem and must agree on its objective.
11
+ * In single precision they differ by rounding, and with a linear-system
12
+ * library that is not reproducible run to run (cuDSS) by about 2e-6. */
13
+ #define DEGENERATE_AGREE_TOL VERIFY_TOL(1e-8, 1e-4)
10
14
  static const char *degenerate(void) {
11
15
  ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
12
16
  ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
@@ -87,7 +91,8 @@ static const char *degenerate(void) {
87
91
  }
88
92
  perr = info.pobj - tpobj;
89
93
  derr = info.dobj - tdobj;
90
- success = ABS(perr) < 1e-8 && ABS(derr) < 1e-8 && exitflag == SCS_SOLVED;
94
+ success = ABS(perr) < DEGENERATE_AGREE_TOL && ABS(derr) < DEGENERATE_AGREE_TOL &&
95
+ exitflag == SCS_SOLVED;
91
96
  mu_assert("degenerate box cone failure", success);
92
97
 
93
98
  /* degenerate SOC cone */
@@ -102,7 +107,8 @@ static const char *degenerate(void) {
102
107
  }
103
108
  perr = info.pobj - tpobj;
104
109
  derr = info.dobj - tdobj;
105
- success = ABS(perr) < 1e-8 && ABS(derr) < 1e-8 && exitflag == SCS_SOLVED;
110
+ success = ABS(perr) < DEGENERATE_AGREE_TOL && ABS(derr) < DEGENERATE_AGREE_TOL &&
111
+ exitflag == SCS_SOLVED;
106
112
  mu_assert("degenerate SOC cone failure", success);
107
113
 
108
114
  /* degenerate PSD cone */
@@ -118,7 +124,8 @@ static const char *degenerate(void) {
118
124
  }
119
125
  perr = info.pobj - tpobj;
120
126
  derr = info.dobj - tdobj;
121
- success = ABS(perr) < 1e-8 && ABS(derr) < 1e-8 && exitflag == SCS_SOLVED;
127
+ success = ABS(perr) < DEGENERATE_AGREE_TOL && ABS(derr) < DEGENERATE_AGREE_TOL &&
128
+ exitflag == SCS_SOLVED;
122
129
  mu_assert("degenerate PSD cone failure", success);
123
130
 
124
131
  SCS(free_sol)(sol);
@@ -50,7 +50,8 @@ static const char *dense_qp(void) {
50
50
  scs_printf("primal obj error %4e\n", perr);
51
51
  scs_printf("dual obj error %4e\n", derr);
52
52
 
53
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
53
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
54
+ exitflag == SCS_SOLVED;
54
55
 
55
56
  mu_assert("dense_qp: SCS failed to produce outputflag SCS_SOLVED", success);
56
57
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
@@ -79,7 +79,8 @@ static const char *hs21_tiny_qp(void) {
79
79
  scs_printf("primal obj error %4e\n", perr);
80
80
  scs_printf("dual obj error %4e\n", derr);
81
81
 
82
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
82
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
83
+ exitflag == SCS_SOLVED;
83
84
 
84
85
  mu_assert("hs21_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
85
86
  success);
@@ -93,7 +94,8 @@ static const char *hs21_tiny_qp(void) {
93
94
  * count of one particular metric and breaks whenever the scaling
94
95
  * changes, even though the warm solve is correct */
95
96
  mu_assert("hs21_tiny_qp: warm-start failure", info.iter <= cold_iter / 2);
96
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
97
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
98
+ exitflag == SCS_SOLVED;
97
99
 
98
100
  mu_assert("hs21_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
99
101
  success);
@@ -114,11 +116,13 @@ static const char *hs21_tiny_qp(void) {
114
116
  scs_printf("primal obj error %4e\n", perr);
115
117
  scs_printf("dual obj error %4e\n", derr);
116
118
 
117
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
119
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
120
+ exitflag == SCS_SOLVED;
118
121
 
119
122
  mu_assert("hs21_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
120
123
  success);
121
124
 
125
+ remove("hs21_tiny_qp.csv");
122
126
  SCS(free_sol)(sol);
123
127
  scs_free(d->A);
124
128
  scs_free(d->P);
@@ -105,7 +105,8 @@ static const char *hs21_tiny_qp_rw(void) {
105
105
  scs_printf("primal obj error %4e\n", perr);
106
106
  scs_printf("dual obj error %4e\n", derr);
107
107
 
108
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
108
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
109
+ exitflag == SCS_SOLVED;
109
110
 
110
111
  mu_assert("hs21_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
111
112
  success);
@@ -119,11 +120,13 @@ static const char *hs21_tiny_qp_rw(void) {
119
120
  * count of one particular metric and breaks whenever the scaling
120
121
  * changes, even though the warm solve is correct */
121
122
  mu_assert("hs21_tiny_qp_rw: warm-start failure", info.iter <= cold_iter / 2);
122
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
123
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
124
+ exitflag == SCS_SOLVED;
123
125
 
124
126
  mu_assert("hs21_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
125
127
  success);
126
128
 
129
+ remove("hs21_tiny_qp");
127
130
  SCS(free_data)(d);
128
131
  SCS(free_cone)(k);
129
132
  SCS(free_sol)(sol);
Binary file
@@ -0,0 +1,19 @@
1
+ #include "glbopts.h"
2
+ #include "problems/test_prob_from_data_file.h"
3
+ #include "scs.h"
4
+
5
+ /*
6
+ * QP reported in cvxgrp/scs#140: a ~360 variable SOCP that ECOS and Gurobi
7
+ * agree solves to 2.875, but which SCS 2.1.1 could not get near in 100k
8
+ * iterations. The data comes from the `ecos_v_scs.mat` file attached to the
9
+ * issue (github.com/ekrimsk/ECOS_SCS_FILES).
10
+ *
11
+ * The current algorithm solves it in well under a thousand iterations, but
12
+ * only with the diagonal rescaling on: with `adaptive_diag_scale = 0` the
13
+ * primal residual still stalls around 1e-4 for 100k iterations. The data file
14
+ * therefore carries the default settings, and this test guards that default.
15
+ */
16
+ static const char *issue_140(void) {
17
+ scs_float OPT = 2.875113; /* from scs at eps 1e-11, matches ECOS to 6 sf */
18
+ return _test_prob_from_data("test/problems/issue_140", OPT);
19
+ }
Binary file
@@ -0,0 +1,37 @@
1
+ #include "glbopts.h"
2
+ #include "problems/test_prob_from_data_file.h"
3
+ #include "scs.h"
4
+
5
+ /*
6
+ * The SOS problem from cvxgrp/scs#220: the symmetry-reduced (Wedderburn)
7
+ * sum-of-squares relaxation of the Robinson form under the dihedral group
8
+ * D4, whose exact optimum is 3825 / 4096. Rebuilt from
9
+ * SymbolicWedderburn.jl's test/action_dihedral.jl (the dump file attached to
10
+ * the issue was lost with its host); the reconstruction reproduces the
11
+ * dimensions in the issue's log exactly: n = 12, m = 17, nnz(A) = 25,
12
+ * z = 6, four psd blocks of side 2, 1, 1, 3.
13
+ *
14
+ * SCS converges on it, but slowly: the relaxation is degenerate (the Robinson
15
+ * form sits on the boundary of the SOS cone), which is the regime where a
16
+ * first-order method's rate collapses. That is why it looked like a failure
17
+ * to converge in 2022 at 3.2.0. No scale, rho_x, alpha or acceleration
18
+ * setting removes it.
19
+ *
20
+ * The test runs at eps 1e-4, which the iterates reach steadily, in about
21
+ * 1e3 to 4e3 iterations. It must not be tightened to 1e-5. There the
22
+ * residuals sit on a plateau just above the tolerance (the dual residual
23
+ * moves from 2.7e-5 to 2.5e-5 between iteration 1e4 and 2e5) and the solve
24
+ * ends only when a jump happens to land inside it, so the iteration count
25
+ * is decided by rounding: changing `scale` by one part in 1e13 moved it
26
+ * between 6e3 and more than 2e5, and CI runners with different CPUs (and so
27
+ * different BLAS kernels) took 3e4 to more than 2e5, which is the limit
28
+ * stored in the data file.
29
+ *
30
+ * The price of 1e-4 is a less accurate objective: it lands within 2.6e-3 of
31
+ * the exact value, against 8e-4 at 1e-5, hence the tolerance of 5e-3 below.
32
+ * The test guards the data, not a bug.
33
+ */
34
+ static const char *issue_220(void) {
35
+ scs_float OPT = 3825. / 4096.; /* exact */
36
+ return _test_prob_from_data_eps("test/problems/issue_220", OPT, 1e-4, 5e-3);
37
+ }