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,79 @@
1
+ #include "glbopts.h"
2
+ #include "minunit.h"
3
+ #include "problem_utils.h"
4
+ #include "scs.h"
5
+ #include "util.h"
6
+
7
+ /*
8
+ * cvxgrp/scs#499: a barely infeasible feasibility problem (c = 0, no P), one
9
+ * of the subproblems of a DQCP bisection (nested_call011 in the issue's
10
+ * reproducer, same data and the settings CVXR passes). m = 12, n = 4, three
11
+ * nonnegative rows and three second-order cones of size 3.
12
+ *
13
+ * With c = 0 and P = 0 the dual residual is A'y and so is the only term it
14
+ * is measured against: its relative size is 1 on every iteration. A scale
15
+ * update that balances relative residuals therefore always reads the dual
16
+ * as behind and walks the scale down to its floor, where progress toward
17
+ * the certificate stalls. 3.3.1 needed 84,475 iterations here (3.2.7:
18
+ * 5,500); with the residuals themselves balanced whenever a side has no
19
+ * correct digits it takes about 1,250.
20
+ *
21
+ * The counts move with the platform and the BLAS, so the test only asks for
22
+ * the certificate within 20,000 iterations.
23
+ */
24
+ static const char *issue_499(void) {
25
+ ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
26
+ ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
27
+ ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
28
+ ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
29
+ ScsInfo info = {0};
30
+ scs_int exitflag;
31
+ const char *fail;
32
+
33
+ scs_int Ap[] = {0, 5, 8, 10, 14};
34
+ scs_int Ai[] = {0, 2, 3, 4, 8, 1, 3, 4, 1, 11, 6, 7, 9, 10};
35
+ scs_float Ax[] = {-1., -1., -1., -1., -2., 0.05, -1.,
36
+ 1., -0.35, -2., -1., -1., 1., 1.};
37
+ scs_float b[] = {0., 0., -0.9934259201488199, 0., 0., 2., 1., -1., 0., 2.,
38
+ 0., 0.};
39
+ scs_float c[] = {0., 0., 0., 0.};
40
+ scs_int q[] = {3, 3, 3};
41
+
42
+ scs_int m = 12, n = 4;
43
+
44
+ d->m = m;
45
+ d->n = n;
46
+ d->b = b;
47
+ d->c = c;
48
+
49
+ d->A = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
50
+ d->A->m = m;
51
+ d->A->n = n;
52
+ d->A->x = Ax;
53
+ d->A->i = Ai;
54
+ d->A->p = Ap;
55
+
56
+ k->l = 3;
57
+ k->q = q;
58
+ k->qsize = 3;
59
+
60
+ scs_set_default_settings(stgs);
61
+ stgs->eps_abs = 1e-5;
62
+ stgs->eps_rel = 1e-5;
63
+ stgs->acceleration_lookback = 10;
64
+ stgs->acceleration_interval = 10;
65
+ stgs->max_iters = 20000;
66
+
67
+ exitflag = scs(d, k, stgs, sol, &info);
68
+
69
+ mu_assert("issue_499: expected SCS_INFEASIBLE within 20,000 iterations",
70
+ exitflag == SCS_INFEASIBLE);
71
+ fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
72
+
73
+ SCS(free_sol)(sol);
74
+ scs_free(d->A);
75
+ scs_free(k);
76
+ scs_free(stgs);
77
+ scs_free(d);
78
+ return fail;
79
+ }
@@ -60,7 +60,7 @@ static const char *lp_update(void) {
60
60
 
61
61
  /* base solve: min x s.t. x >= 2, expected obj=2 */
62
62
  exitflag = scs_solve(w, sol, &info, 0);
63
- success = exitflag == SCS_SOLVED && ABS(info.pobj - 2.0) < 1e-4;
63
+ success = exitflag == SCS_SOLVED && ABS(info.pobj - 2.0) < SOL_TOL;
64
64
  mu_assert("lp_update: base solve failed", success);
65
65
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
66
66
  if (fail) return fail;
@@ -69,7 +69,7 @@ static const char *lp_update(void) {
69
69
  b[0] = -3.0;
70
70
  scs_update(w, b, SCS_NULL);
71
71
  exitflag = scs_solve(w, sol, &info, 1);
72
- success = exitflag == SCS_SOLVED && ABS(info.pobj - 3.0) < 1e-4;
72
+ success = exitflag == SCS_SOLVED && ABS(info.pobj - 3.0) < SOL_TOL;
73
73
  mu_assert("lp_update: b-update solve failed", success);
74
74
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
75
75
  if (fail) return fail;
@@ -78,7 +78,7 @@ static const char *lp_update(void) {
78
78
  c[0] = 2.0;
79
79
  scs_update(w, SCS_NULL, c);
80
80
  exitflag = scs_solve(w, sol, &info, 1);
81
- success = exitflag == SCS_SOLVED && ABS(info.pobj - 6.0) < 1e-4;
81
+ success = exitflag == SCS_SOLVED && ABS(info.pobj - 6.0) < SOL_TOL;
82
82
  mu_assert("lp_update: c-update solve failed", success);
83
83
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
84
84
  if (fail) return fail;
@@ -88,7 +88,7 @@ static const char *lp_update(void) {
88
88
  c[0] = 1.0;
89
89
  scs_update(w, b, c);
90
90
  exitflag = scs_solve(w, sol, &info, 1);
91
- success = exitflag == SCS_SOLVED && ABS(info.pobj - 2.0) < 1e-4;
91
+ success = exitflag == SCS_SOLVED && ABS(info.pobj - 2.0) < SOL_TOL;
92
92
  mu_assert("lp_update: b+c-update solve failed", success);
93
93
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
94
94
  if (fail) return fail;
@@ -96,7 +96,7 @@ static const char *lp_update(void) {
96
96
  /* null/null update: no change to problem, result must be identical */
97
97
  scs_update(w, SCS_NULL, SCS_NULL);
98
98
  exitflag = scs_solve(w, sol, &info, 1);
99
- success = exitflag == SCS_SOLVED && ABS(info.pobj - 2.0) < 1e-4;
99
+ success = exitflag == SCS_SOLVED && ABS(info.pobj - 2.0) < SOL_TOL;
100
100
  mu_assert("lp_update: null-null update changed result", success);
101
101
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
102
102
 
@@ -132,7 +132,8 @@ static const char *qafiro_tiny_qp(void) {
132
132
  scs_printf("primal obj error %4e\n", perr);
133
133
  scs_printf("dual obj error %4e\n", derr);
134
134
 
135
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
135
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
136
+ exitflag == SCS_SOLVED;
136
137
 
137
138
  mu_assert("qafiro_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
138
139
  success);
@@ -141,13 +142,28 @@ static const char *qafiro_tiny_qp(void) {
141
142
  /* test warm-starting */
142
143
  stgs->warm_start = 1;
143
144
  exitflag = scs(d, k, stgs, sol, &info);
144
- /* 25 iters should be enough if warm-started */
145
+ /* 25 iters should be enough if warm-started. Not in single precision: there
146
+ * the cold solve ends on a point that meets the tolerance by a margin of
147
+ * the order of the rounding, and the warm-started solve can wander away
148
+ * from it before converging. With Apple's Accelerate, whose factorization
149
+ * differs from run to run, it took 0 to 2,000 iterations over 300 local
150
+ * runs without LAPACK and 1,500 on a CI runner; with QDLDL and the indirect
151
+ * solver it takes 0. */
152
+ #ifndef SFLOAT
145
153
  mu_assert("qafiro_tiny_qp: warm-start failure", info.iter <= 100);
146
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
154
+ #endif
155
+ perr = info.pobj - opt;
156
+ derr = info.dobj - opt;
157
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
158
+ exitflag == SCS_SOLVED;
147
159
 
148
160
  mu_assert("qafiro_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
149
161
  success);
150
162
 
163
+ /* The solves below turn off normalization and adaptive scaling, which this
164
+ * badly scaled instance only survives with double precision: in single
165
+ * precision the iterates diverge and SCS reports it infeasible. */
166
+ #ifndef SFLOAT
151
167
  /* test other settings */
152
168
  stgs->warm_start = 0;
153
169
  stgs->normalize = 0;
@@ -164,7 +180,8 @@ static const char *qafiro_tiny_qp(void) {
164
180
  scs_printf("primal obj error %4e\n", perr);
165
181
  scs_printf("dual obj error %4e\n", derr);
166
182
 
167
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
183
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
184
+ exitflag == SCS_SOLVED;
168
185
 
169
186
  mu_assert("qafiro_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
170
187
  success);
@@ -187,11 +204,14 @@ static const char *qafiro_tiny_qp(void) {
187
204
  scs_printf("primal obj error %4e\n", perr);
188
205
  scs_printf("dual obj error %4e\n", derr);
189
206
 
190
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
207
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
208
+ exitflag == SCS_SOLVED;
191
209
 
192
210
  mu_assert("qafiro_tiny_qp: SCS failed to produce outputflag SCS_SOLVED",
193
211
  success);
194
212
 
213
+ remove("qafiro_tiny_qp.csv");
214
+ #endif
195
215
  SCS(free_sol)(sol);
196
216
  scs_free(d->A);
197
217
  scs_free(d->P);
@@ -19,6 +19,20 @@ static const char *rob_gauss_cov_est(void) {
19
19
  scs_int success, read_status;
20
20
  const char *fail;
21
21
 
22
+ #ifdef SFLOAT
23
+ /* The dense and indirect backends solve the normal equations, which square
24
+ * the conditioning; in single precision they stall on this SDP near a 1e-1
25
+ * primal residual, so only the backends factoring the KKT matrix run it. */
26
+ if (strstr(scs_get_lin_sys_method(), "dense") ||
27
+ strstr(scs_get_lin_sys_method(), "indirect")) {
28
+ scs_free(k);
29
+ scs_free(d);
30
+ scs_free(stgs);
31
+ scs_free(sol);
32
+ return mu_skipped;
33
+ }
34
+ #endif
35
+
22
36
  /* data */
23
37
  scs_float Ax[] = {-1.0,
24
38
  -0.25035003149,
@@ -172,7 +186,8 @@ static const char *rob_gauss_cov_est(void) {
172
186
  scs_printf("primal obj error %4e\n", perr);
173
187
  scs_printf("dual obj error %4e\n", derr);
174
188
 
175
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
189
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
190
+ exitflag == SCS_SOLVED;
176
191
 
177
192
  mu_assert("rob_gauss_cov_est: SCS failed to produce outputflag SCS_SOLVED",
178
193
  success);
@@ -186,7 +201,8 @@ static const char *rob_gauss_cov_est(void) {
186
201
  exitflag = scs(d, k, stgs, sol, &info);
187
202
  mu_assert("rob_gauss_cov_est: warm-start failure",
188
203
  info.iter <= cold_iter / 2);
189
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
204
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
205
+ exitflag == SCS_SOLVED;
190
206
 
191
207
  mu_assert("rob_gauss_cov_est: SCS failed to produce outputflag SCS_SOLVED",
192
208
  success);
@@ -219,7 +235,8 @@ static const char *rob_gauss_cov_est(void) {
219
235
  scs_printf("primal obj error %4e\n", perr);
220
236
  scs_printf("dual obj error %4e\n", derr);
221
237
 
222
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
238
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
239
+ exitflag == SCS_SOLVED;
223
240
 
224
241
  mu_assert("rob_gauss_cov_est_rw: SCS failed to produce outputflag SCS_SOLVED",
225
242
  success);
@@ -243,11 +260,14 @@ static const char *rob_gauss_cov_est(void) {
243
260
  scs_printf("primal obj error %4e\n", perr);
244
261
  scs_printf("dual obj error %4e\n", derr);
245
262
 
246
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
263
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
264
+ exitflag == SCS_SOLVED;
247
265
 
248
266
  mu_assert("rob_gauss_cov_est_rw: SCS failed to produce outputflag SCS_SOLVED",
249
267
  success);
250
268
 
269
+ remove("rob_gauss_cov_est");
270
+ remove("rob_gauss_cov_est.csv");
251
271
  SCS(free_data)(d);
252
272
  SCS(free_cone)(k);
253
273
  SCS(free_sol)(sol);
@@ -134,7 +134,8 @@ static const char *sd_and_complex_sd(void) {
134
134
  scs_printf("primal obj error %4e\n", perr);
135
135
  scs_printf("dual obj error %4e\n", derr);
136
136
 
137
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
137
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
138
+ exitflag == SCS_SOLVED;
138
139
 
139
140
  mu_assert("sd_and_complex_sd: SCS failed to produce outputflag SCS_SOLVED",
140
141
  success);
@@ -40,7 +40,8 @@ static const char *small_lp(void) {
40
40
  scs_printf("primal obj error %4e\n", perr);
41
41
  scs_printf("dual obj error %4e\n", derr);
42
42
 
43
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
43
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
44
+ exitflag == SCS_SOLVED;
44
45
 
45
46
  mu_assert("small_lp: SCS failed to produce outputflag SCS_SOLVED", success);
46
47
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
@@ -285,6 +285,13 @@ scs_float c[] = {0.00000, 0.00000, -35.02643, 0.00000, 0.00000,
285
285
  scs_int A_nnz = 465;
286
286
 
287
287
  static const char *small_qp(void) {
288
+ #ifdef SFLOAT
289
+ /* The optimal objective is about 1e6, so single precision leaves the gap with
290
+ * roundoff well above any useful tolerance. With this test's fixed scale the
291
+ * solve does not converge in max_iters; with adaptive scaling it does on some
292
+ * platforms and not others. */
293
+ return mu_skipped;
294
+ #endif
288
295
  ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
289
296
  ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
290
297
  ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
@@ -79,7 +79,8 @@ static const char *test_box_cone_lp(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
  mu_assert("test_box_cone_lp: SCS failed to produce SCS_SOLVED", success);
84
85
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
85
86
 
@@ -83,7 +83,8 @@ static const char *test_dual_exp_cone(void) {
83
83
  scs_printf("primal obj error %4e\n", perr);
84
84
  scs_printf("dual obj error %4e\n", derr);
85
85
 
86
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
86
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
87
+ exitflag == SCS_SOLVED;
87
88
  mu_assert("test_dual_exp_cone: SCS failed to produce SCS_SOLVED", success);
88
89
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
89
90
 
@@ -100,7 +100,8 @@ static const char *test_mixed_cones(void) {
100
100
  scs_printf("primal obj error %4e\n", perr);
101
101
  scs_printf("dual obj error %4e\n", derr);
102
102
 
103
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
103
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
104
+ exitflag == SCS_SOLVED;
104
105
  mu_assert("test_mixed_cones: SCS failed to produce SCS_SOLVED", success);
105
106
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
106
107
 
@@ -0,0 +1,76 @@
1
+ #include "glbopts.h"
2
+ #include "linsys.h"
3
+ #include "minunit.h"
4
+ #include "problem_utils.h"
5
+ #include "scs.h"
6
+ #include "util.h"
7
+ #include <string.h>
8
+
9
+ /* A QP whose P is not positive semidefinite, P = diag(-10, 1), over the box
10
+ * -1 <= x <= 1. The problem is not convex, and the direct linear solvers
11
+ * that check the inertia of the KKT matrix at setup must refuse it, so scs
12
+ * returns SCS_FAILED: QDLDL through its pivots, MKL Pardiso and cuDSS
13
+ * through the number of positive eigenvalues, the dense solver through its
14
+ * Cholesky factorization. What they test is whether R_x + P + A' R_y^{-1} A
15
+ * is positive definite, so P11 = -10 is chosen to outweigh the A' R_y^{-1} A
16
+ * term after equilibration by a wide margin; a mildly negative P11 such as
17
+ * -0.1 would pass every backend's check. The indirect solvers and Apple
18
+ * Accelerate do not check, so for them the test only runs a few iterations. */
19
+ static const char *test_non_psd_p(void) {
20
+ ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
21
+ ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
22
+ ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
23
+ ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
24
+ ScsInfo info = {0};
25
+ scs_int exitflag;
26
+ const char *method = scs_get_lin_sys_method();
27
+ int checks_inertia = strstr(method, "qdldl") || strstr(method, "mkl") ||
28
+ strstr(method, "cuDSS") || strstr(method, "cholesky");
29
+
30
+ /* A = [I; -I], b = 1: x <= 1 and -x <= 1 */
31
+ scs_float Ax[] = {1., -1., 1., -1.};
32
+ scs_int Ai[] = {0, 2, 1, 3};
33
+ scs_int Ap[] = {0, 2, 4};
34
+ scs_float Px[] = {-10., 1.};
35
+ scs_int Pi[] = {0, 1};
36
+ scs_int Pp[] = {0, 1, 2};
37
+ scs_float b[] = {1., 1., 1., 1.};
38
+ scs_float c[] = {1., 1.};
39
+
40
+ d->m = 4;
41
+ d->n = 2;
42
+ d->b = b;
43
+ d->c = c;
44
+ d->A = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
45
+ d->P = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
46
+ d->A->m = 4;
47
+ d->A->n = 2;
48
+ d->A->x = Ax;
49
+ d->A->i = Ai;
50
+ d->A->p = Ap;
51
+ d->P->m = 2;
52
+ d->P->n = 2;
53
+ d->P->x = Px;
54
+ d->P->i = Pi;
55
+ d->P->p = Pp;
56
+ k->l = 4;
57
+
58
+ scs_set_default_settings(stgs);
59
+ stgs->max_iters = 100;
60
+ stgs->verbose = 0;
61
+
62
+ exitflag = scs(d, k, stgs, sol, &info);
63
+ scs_printf("non_psd_p: %s returned %li\n", method, (long)exitflag);
64
+ if (checks_inertia) {
65
+ mu_assert("non_psd_p: a direct solver accepted a P that is not PSD",
66
+ exitflag == SCS_FAILED);
67
+ }
68
+
69
+ SCS(free_sol)(sol);
70
+ scs_free(d->A);
71
+ scs_free(d->P);
72
+ scs_free(k);
73
+ scs_free(stgs);
74
+ scs_free(d);
75
+ return 0;
76
+ }
@@ -92,9 +92,9 @@ static const char *test_normalize_roundtrip_lp(void) {
92
92
 
93
93
  /* Both should match the known optimal */
94
94
  mu_assert("normalize_roundtrip: unnormalized obj wrong",
95
- ABS(info0.pobj - opt) < 1e-4);
95
+ ABS(info0.pobj - opt) < SOL_TOL);
96
96
  mu_assert("normalize_roundtrip: normalized obj wrong",
97
- ABS(info1.pobj - opt) < 1e-4);
97
+ ABS(info1.pobj - opt) < SOL_TOL);
98
98
 
99
99
  /* Solutions should agree (un-normalization must be correct) */
100
100
  err_x = 0; err_y = 0; err_s = 0;
@@ -113,10 +113,11 @@ static const char *test_normalize_roundtrip_lp(void) {
113
113
  scs_printf("normalize_roundtrip: x_err=%.2e y_err=%.2e s_err=%.2e "
114
114
  "obj_err=%.2e\n", err_x, err_y, err_s, err_obj);
115
115
 
116
- mu_assert("normalize_roundtrip: x vectors differ too much", err_x < 1e-4);
117
- mu_assert("normalize_roundtrip: y vectors differ too much", err_y < 1e-4);
118
- mu_assert("normalize_roundtrip: s vectors differ too much", err_s < 1e-4);
119
- mu_assert("normalize_roundtrip: obj values differ too much", err_obj < 1e-5);
116
+ mu_assert("normalize_roundtrip: x vectors differ too much", err_x < SOL_TOL);
117
+ mu_assert("normalize_roundtrip: y vectors differ too much", err_y < SOL_TOL);
118
+ mu_assert("normalize_roundtrip: s vectors differ too much", err_s < SOL_TOL);
119
+ mu_assert("normalize_roundtrip: obj values differ too much",
120
+ err_obj < VERIFY_TOL(1e-5, 1e-2));
120
121
 
121
122
  /* Cleanup */
122
123
  SCS(free_sol)(sol0);
@@ -235,9 +236,9 @@ static const char *test_normalize_roundtrip_qp(void) {
235
236
  exitflag1 == SCS_SOLVED);
236
237
 
237
238
  mu_assert("normalize_qp: unnormalized obj wrong",
238
- ABS(info0.pobj - opt) < 1e-4);
239
+ ABS(info0.pobj - opt) < SOL_TOL);
239
240
  mu_assert("normalize_qp: normalized obj wrong",
240
- ABS(info1.pobj - opt) < 1e-4);
241
+ ABS(info1.pobj - opt) < SOL_TOL);
241
242
 
242
243
  err_x = 0; err_y = 0; err_s = 0;
243
244
  for (i = 0; i < n; ++i) {
@@ -255,10 +256,11 @@ static const char *test_normalize_roundtrip_qp(void) {
255
256
  scs_printf("normalize_qp: x_err=%.2e y_err=%.2e s_err=%.2e "
256
257
  "obj_err=%.2e\n", err_x, err_y, err_s, err_obj);
257
258
 
258
- mu_assert("normalize_qp: x vectors differ too much", err_x < 1e-4);
259
- mu_assert("normalize_qp: y vectors differ too much", err_y < 1e-4);
260
- mu_assert("normalize_qp: s vectors differ too much", err_s < 1e-4);
261
- mu_assert("normalize_qp: obj values differ too much", err_obj < 1e-5);
259
+ mu_assert("normalize_qp: x vectors differ too much", err_x < SOL_TOL);
260
+ mu_assert("normalize_qp: y vectors differ too much", err_y < SOL_TOL);
261
+ mu_assert("normalize_qp: s vectors differ too much", err_s < SOL_TOL);
262
+ mu_assert("normalize_qp: obj values differ too much",
263
+ err_obj < VERIFY_TOL(1e-5, 1e-2));
262
264
 
263
265
  /* Cleanup */
264
266
  SCS(free_sol)(sol0);
@@ -73,7 +73,8 @@ static const char *test_power_cone(void) {
73
73
  scs_printf("primal obj error %4e\n", perr);
74
74
  scs_printf("dual obj error %4e\n", derr);
75
75
 
76
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
76
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
77
+ exitflag == SCS_SOLVED;
77
78
  mu_assert("test_power_cone: SCS failed to produce SCS_SOLVED", success);
78
79
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
79
80
 
@@ -81,7 +82,7 @@ static const char *test_power_cone(void) {
81
82
  stgs->warm_start = 1;
82
83
  exitflag = scs(d, k, stgs, sol, &info);
83
84
  mu_assert("test_power_cone: warm-start failure", info.iter <= 25);
84
- success = ABS(info.pobj - opt) < 1e-4 && exitflag == SCS_SOLVED;
85
+ success = ABS(info.pobj - opt) < SOL_TOL && exitflag == SCS_SOLVED;
85
86
  mu_assert("test_power_cone: SCS warm-start failed", success);
86
87
 
87
88
  SCS(free_sol)(sol);
@@ -160,7 +161,8 @@ static const char *test_power_cone_p09(void) {
160
161
  scs_printf("primal obj error %4e\n", perr);
161
162
  scs_printf("dual obj error %4e\n", derr);
162
163
 
163
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
164
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
165
+ exitflag == SCS_SOLVED;
164
166
  mu_assert("test_power_cone_p09: SCS failed to produce SCS_SOLVED", success);
165
167
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
166
168
 
@@ -244,7 +246,8 @@ static const char *test_dual_power_cone(void) {
244
246
  scs_printf("primal obj error %4e\n", perr);
245
247
  scs_printf("dual obj error %4e\n", derr);
246
248
 
247
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
249
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
250
+ exitflag == SCS_SOLVED;
248
251
  mu_assert("test_dual_power_cone: SCS failed to produce SCS_SOLVED", success);
249
252
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
250
253
 
@@ -401,7 +404,8 @@ static const char *test_multi_power(void) {
401
404
  scs_printf("primal obj error %4e\n", perr);
402
405
  scs_printf("dual obj error %4e\n", derr);
403
406
 
404
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
407
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
408
+ exitflag == SCS_SOLVED;
405
409
  mu_assert("test_multi_power: SCS failed to produce SCS_SOLVED", success);
406
410
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
407
411
 
@@ -412,3 +416,133 @@ static const char *test_multi_power(void) {
412
416
  scs_free(d);
413
417
  return fail;
414
418
  }
419
+
420
+ /*
421
+ * Regression test for issue #491: the power cone projection used absolute
422
+ * tolerances, so when the (homogeneous, normalized) iterates were tiny the
423
+ * Newton solve stopped early and SCS returned SCS_SOLVED with the slack well
424
+ * outside the cone.
425
+ *
426
+ * Problem: minimize -1000 x s.t. (100, 0.01, x) in K_pow(0.25).
427
+ * K_pow(0.25): u^0.25 * v^0.75 >= |z|, so x* = 100^0.25 * 0.01^0.75 = 0.1.
428
+ *
429
+ * Variables [x] (n=1), m=3:
430
+ * Rows 0-2 (power p=0.25): s = b - A x = (100, 0.01, x)
431
+ *
432
+ * A cols (CSC):
433
+ * col 0 (x): row 2 -> -1
434
+ */
435
+ static const char *test_power_cone_small_scale(void) {
436
+ #ifdef SFLOAT
437
+ /* Checks x and the cone violation to 1e-6 with c = 1000 and b = 100, and in
438
+ * single precision the gap stalls near 1e-3 relative, with the status and
439
+ * the error both depending on the platform's rounding. */
440
+ return mu_skipped;
441
+ #endif
442
+ ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
443
+ ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
444
+ ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
445
+ ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
446
+ ScsInfo info = {0};
447
+ scs_int exitflag;
448
+ scs_float viol;
449
+ scs_int success;
450
+ const char *fail;
451
+
452
+ scs_float xopt = 0.1;
453
+
454
+ scs_float Axs[] = {-1.0};
455
+ scs_int Ais[] = {2};
456
+ scs_int Aps[] = {0, 1};
457
+
458
+ scs_float bs[] = {100.0, 0.01, 0.0};
459
+ scs_float cs[] = {-1000.0};
460
+
461
+ scs_float ps[] = {0.25};
462
+
463
+ scs_int m = 3, n = 1;
464
+
465
+ d->m = m;
466
+ d->n = n;
467
+ d->b = bs;
468
+ d->c = cs;
469
+
470
+ d->A = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
471
+ d->A->m = m;
472
+ d->A->n = n;
473
+ d->A->x = Axs;
474
+ d->A->i = Ais;
475
+ d->A->p = Aps;
476
+
477
+ k->psize = 1;
478
+ k->p = ps;
479
+
480
+ scs_set_default_settings(stgs);
481
+ stgs->eps_abs = 1e-8;
482
+ stgs->eps_rel = 1e-8;
483
+
484
+ exitflag = scs(d, k, stgs, sol, &info);
485
+
486
+ /* cone violation of s = (u, v, z): |z| - u^0.25 * v^0.75 */
487
+ viol = ABS(sol->s[2]) - POWF(MAX(sol->s[0], 0.), 0.25) *
488
+ POWF(MAX(sol->s[1], 0.), 0.75);
489
+
490
+ scs_printf("x error %4e\n", sol->x[0] - xopt);
491
+ scs_printf("cone violation %4e\n", viol);
492
+
493
+ success = exitflag == SCS_SOLVED && ABS(sol->x[0] - xopt) < 1e-6 &&
494
+ viol < 1e-6;
495
+ mu_assert("test_power_cone_small_scale: slack outside cone or wrong x",
496
+ success);
497
+ fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
498
+
499
+ SCS(free_sol)(sol);
500
+ scs_free(d->A);
501
+ scs_free(k);
502
+ scs_free(stgs);
503
+ scs_free(d);
504
+ return fail;
505
+ }
506
+
507
+ /*
508
+ * Projection onto the power cone of points just outside it with one tiny
509
+ * positive component and p near 0 or 1. Starting the Newton solve at
510
+ * r = rh there makes the first step too small to represent, which was
511
+ * mistaken for convergence and returned v unprojected. Reference values
512
+ * are from a 60-digit bisection and satisfy the projection's optimality
513
+ * conditions.
514
+ *
515
+ * P_K(v) is computed from the dual projection via Moreau: v + P_K*(-v).
516
+ */
517
+ static const char *test_power_cone_proj_tiny_component(void) {
518
+ scs_float ps[] = {0.001, 0.001, 0.999};
519
+ scs_float vs[][3] = {{1e-12, 1.0, 1.8482197251762336},
520
+ {1e-9, 1.0, 1.8610309722765279},
521
+ {1.0, 1e-12, -1.8482197251762336}};
522
+ scs_float refs[][3] = {
523
+ {0.024656240189987407, 1.42591697797449, 1.4201429843158235},
524
+ {0.024896473072648813, 1.4323167445745537, 1.4265242797926461},
525
+ {1.42591697797449, 0.024656240189987418, -1.4201429843158235}};
526
+ scs_float t[3], err;
527
+ scs_int i, j;
528
+ ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
529
+ ScsConeWork *c;
530
+
531
+ k->psize = 1;
532
+ for (i = 0; i < 3; ++i) {
533
+ k->p = &(ps[i]);
534
+ c = SCS(init_cone)(k, 3);
535
+ for (j = 0; j < 3; ++j)
536
+ t[j] = -vs[i][j];
537
+ SCS(proj_dual_cone)(t, c, SCS_NULL, SCS_NULL);
538
+ SCS(finish_cone)(c);
539
+ err = 0;
540
+ for (j = 0; j < 3; ++j)
541
+ err = MAX(err, ABS(t[j] + vs[i][j] - refs[i][j]));
542
+ scs_printf("power cone projection %i error %4e\n", (int)i, err);
543
+ mu_assert_less("test_power_cone_proj_tiny_component: projection error",
544
+ err, VERIFY_TOL(1e-9, 1e-4));
545
+ }
546
+ scs_free(k);
547
+ return 0;
548
+ }