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
@@ -66,7 +66,8 @@ static const char *test_soc_size1(void) {
66
66
  scs_printf("primal obj error %4e\n", perr);
67
67
  scs_printf("dual obj error %4e\n", derr);
68
68
 
69
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
69
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
70
+ exitflag == SCS_SOLVED;
70
71
  mu_assert("test_soc_size1: SCS failed to produce SCS_SOLVED", success);
71
72
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
72
73
 
@@ -140,7 +141,8 @@ static const char *test_soc_size2(void) {
140
141
  scs_printf("primal obj error %4e\n", perr);
141
142
  scs_printf("dual obj error %4e\n", derr);
142
143
 
143
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
144
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
145
+ exitflag == SCS_SOLVED;
144
146
  mu_assert("test_soc_size2: SCS failed to produce SCS_SOLVED", success);
145
147
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
146
148
 
@@ -215,7 +217,8 @@ static const char *test_soc_size3(void) {
215
217
  scs_printf("primal obj error %4e\n", perr);
216
218
  scs_printf("dual obj error %4e\n", derr);
217
219
 
218
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
220
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
221
+ exitflag == SCS_SOLVED;
219
222
  mu_assert("test_soc_size3: SCS failed to produce SCS_SOLVED", success);
220
223
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
221
224
 
@@ -295,7 +298,8 @@ static const char *test_soc_size5(void) {
295
298
  scs_printf("primal obj error %4e\n", perr);
296
299
  scs_printf("dual obj error %4e\n", derr);
297
300
 
298
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
301
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
302
+ exitflag == SCS_SOLVED;
299
303
  mu_assert("test_soc_size5: SCS failed to produce SCS_SOLVED", success);
300
304
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
301
305
 
@@ -380,7 +384,8 @@ static const char *test_multi_soc(void) {
380
384
  scs_printf("primal obj error %4e\n", perr);
381
385
  scs_printf("dual obj error %4e\n", derr);
382
386
 
383
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
387
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
388
+ exitflag == SCS_SOLVED;
384
389
  mu_assert("test_multi_soc: SCS failed to produce SCS_SOLVED", success);
385
390
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
386
391
 
@@ -60,6 +60,13 @@
60
60
  * at least once during the solve.
61
61
  */
62
62
  static const char *test_adaptive_scale(void) {
63
+ #ifdef SFLOAT
64
+ /* From this test's deliberately bad scale, the single-precision unpivoted
65
+ * LDLT in Apple Accelerate diverges (residuals near 1e18 at max_iters). */
66
+ if (strstr(scs_get_lin_sys_method(), "accelerate")) {
67
+ return mu_skipped;
68
+ }
69
+ #endif
63
70
  ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
64
71
  ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
65
72
  ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
@@ -371,7 +378,7 @@ static const char *test_normalize_off(void) {
371
378
  if (fail) return fail;
372
379
 
373
380
  mu_assert("test_normalize_off: objectives differ between normalize=0 and 1",
374
- ABS(pobj0 - pobj1) < 1e-4);
381
+ ABS(pobj0 - pobj1) < SOL_TOL);
375
382
  return 0;
376
383
  }
377
384
 
@@ -452,7 +459,7 @@ static const char *test_normalize_roundtrip(void) {
452
459
  ABS(sol0->x[i] - sol1->x[i]) < 1e-3);
453
460
  }
454
461
  mu_assert("test_normalize_roundtrip: objectives differ",
455
- ABS(info0.pobj - info1.pobj) < 1e-4);
462
+ ABS(info0.pobj - info1.pobj) < SOL_TOL);
456
463
 
457
464
  _CLEANUP_NRM(d0, k0, stgs0, sol0);
458
465
  _CLEANUP_NRM(d1, k1, stgs1, sol1);
@@ -546,7 +553,7 @@ static const char *test_warm_start(void) {
546
553
  exitflag = scs_solve(w, sol, &info, 1);
547
554
  mu_assert("test_warm_start: warm solve failed", exitflag == SCS_SOLVED);
548
555
  mu_assert("test_warm_start: wrong objective after warm start",
549
- ABS(info.pobj - 2.0) < 1e-4);
556
+ ABS(info.pobj - 2.0) < SOL_TOL);
550
557
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
551
558
 
552
559
  scs_finish(w);
@@ -68,7 +68,8 @@ static const char *test_zero_cone(void) {
68
68
  scs_printf("primal obj error %4e\n", perr);
69
69
  scs_printf("dual obj error %4e\n", derr);
70
70
 
71
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
71
+ success = ABS(perr) < SOL_TOL && ABS(derr) < SOL_TOL &&
72
+ exitflag == SCS_SOLVED;
72
73
  mu_assert("test_zero_cone: SCS failed to produce SCS_SOLVED", success);
73
74
  fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
74
75
 
@@ -30,6 +30,14 @@ scs_int override_setting(ScsSettings *s, char *param, char *val) {
30
30
  s->acceleration_lookback = atoi(val);
31
31
  } else if (strcmp(param, "acceleration_interval") == 0) {
32
32
  s->acceleration_interval = atoi(val);
33
+ } else if (strcmp(param, "acceleration_type_1") == 0) {
34
+ s->acceleration_type_1 = atoi(val);
35
+ } else if (strcmp(param, "acceleration_regularization") == 0) {
36
+ s->acceleration_regularization = atof(val);
37
+ } else if (strcmp(param, "acceleration_relaxation") == 0) {
38
+ s->acceleration_relaxation = atof(val);
39
+ } else if (strcmp(param, "time_limit_secs") == 0) {
40
+ s->time_limit_secs = atof(val);
33
41
  } else if (strcmp(param, "adaptive_scale") == 0) {
34
42
  s->adaptive_scale = atoi(val);
35
43
  } else if (strcmp(param, "adaptive_diag_scale") == 0) {
@@ -10,6 +10,7 @@
10
10
  #include "problems/dense_qp.h"
11
11
  #include "problems/hs21_tiny_qp.h"
12
12
  #include "problems/infeasible_lp.h"
13
+ #include "problems/issue_499.h"
13
14
  #include "problems/infeasible_socp.h"
14
15
  #include "problems/infeasible_tiny_qp.h"
15
16
  #include "problems/lp_update.h"
@@ -20,6 +21,7 @@
20
21
  #include "problems/test_exp_cone.h"
21
22
  #include "problems/test_inaccurate.h"
22
23
  #include "problems/test_mixed_cones.h"
24
+ #include "problems/test_non_psd_p.h"
23
25
  #include "problems/test_normalize_roundtrip.h"
24
26
  #include "problems/test_power_cone.h"
25
27
  #include "problems/test_root_plus.h"
@@ -33,14 +35,21 @@
33
35
  #include "problems/unbounded_tiny_qp.h"
34
36
 
35
37
  int tests_run = 0;
38
+ int tests_failed = 0;
39
+ int tests_skipped = 0;
40
+ const char *failed_tests[MU_MAX_FAILED_TESTS];
41
+ const char *skipped_tests[MU_MAX_FAILED_TESTS];
42
+ const char *const mu_skipped = "skipped";
43
+
44
+ /* Number of mu_run_test calls in all_tests() below. A build flag can compile a
45
+ * test out, in which case _SKIP replaces it with a stub that reports itself
46
+ * as skipped, and main() checks that run + skipped == MU_TOTAL_TESTS. A build
47
+ * that silently loses tests therefore fails instead of printing ALL TESTS
48
+ * PASSED. Bump this when adding a test. */
49
+ #define MU_TOTAL_TESTS 78
36
50
 
37
- /* decrement tests_run since mu_unit will increment it, so this cancels */
38
51
  #define _SKIP(problem) \
39
- char *problem(void) { \
40
- scs_printf("skipped\n"); \
41
- tests_run--; \
42
- return 0; \
43
- }
52
+ static const char *problem(void) { return mu_skipped; }
44
53
 
45
54
  #if NO_VALIDATE == 0
46
55
  #include "problems/test_validation.h"
@@ -53,23 +62,41 @@ _SKIP(test_validation)
53
62
  #include "problems/complex_PSD.h"
54
63
  #include "problems/sd_and_complex_sd.h"
55
64
  #include "problems/test_psd_metric.h"
65
+ #include "problems/test_psd_parallel.h"
66
+ #include "problems/test_psd_scale_updates.h"
56
67
  #else
57
68
  _SKIP(complex_PSD)
58
69
  _SKIP(sd_and_complex_sd)
59
70
  _SKIP(test_psd_metric)
71
+ _SKIP(test_psd_parallel)
72
+ _SKIP(test_psd_parallel_solve)
73
+ _SKIP(test_psd_scale_updates)
60
74
  #endif
61
75
 
62
76
  /* solve SDPs from data files, requires blas / lapack */
63
77
  #if defined(USE_LAPACK) && NO_READ_WRITE == 0
64
- #include "problems/random_prob.h"
65
78
  #include "problems/rob_gauss_cov_est.h" /* tests writing to data file */
66
79
  #else
67
- _SKIP(random_prob)
68
80
  _SKIP(rob_gauss_cov_est)
69
81
  #endif
70
82
 
71
- /* solve SDPs with spectral cones, requires blas / lapack */
72
- #if defined(USE_SPECTRAL_CONES)
83
+ /* The problems stored in test/problems store their floats as doubles, and
84
+ * SCS(read_data) refuses a file whose float size differs from the build's, so
85
+ * single-precision builds cannot load them. */
86
+ #if defined(USE_LAPACK) && NO_READ_WRITE == 0 && !defined(SFLOAT)
87
+ #include "problems/issue_220.h"
88
+ #include "problems/random_prob.h"
89
+ #else
90
+ _SKIP(issue_220)
91
+ _SKIP(random_prob)
92
+ #endif
93
+
94
+ /* solve SDPs with spectral cones, requires blas / lapack. Not in single
95
+ * precision: the inner Newton and interior-point solvers of these cones use
96
+ * fixed tolerances of 1e-7 to 1e-14, which float arithmetic cannot reach, so
97
+ * they run to their iteration limits inside every cone projection. Some
98
+ * problems then fail and the rest take minutes. */
99
+ #if defined(USE_SPECTRAL_CONES) && !defined(SFLOAT)
73
100
  #include "spectral_cones_problems/exp_design.h"
74
101
  #include "spectral_cones_problems/graph_partitioning.h"
75
102
  #include "spectral_cones_problems/robust_pca.h"
@@ -78,6 +105,7 @@ _SKIP(rob_gauss_cov_est)
78
105
  #include "spectral_cones_problems/several_sum_largest.h"
79
106
  #include "spectral_cones_problems/test_ell1_cone.h"
80
107
  #include "spectral_cones_problems/test_ell1_and_nuc.h"
108
+ #include "spectral_cones_problems/test_spectral_metric_updates.h"
81
109
  #else
82
110
  _SKIP(exp_design)
83
111
  _SKIP(robust_pca)
@@ -87,22 +115,30 @@ _SKIP(several_nuc_cone)
87
115
  _SKIP(several_logdet_cones)
88
116
  _SKIP(test_ell1_cone)
89
117
  _SKIP(test_ell1_and_nuc)
118
+ _SKIP(test_spectral_metric_updates)
90
119
  #endif
91
120
 
92
121
  /* solves problems from data files */
93
122
  #if NO_READ_WRITE == 0
94
123
  #include "problems/hs21_tiny_qp_rw.h"
95
124
  #include "problems/test_rw_settings.h"
96
- #include "problems/max_ent.h"
97
- #include "problems/mpc_bug.h"
98
125
  #else
99
126
  _SKIP(hs21_tiny_qp_rw)
100
127
  _SKIP(test_rw_settings)
128
+ #endif
129
+
130
+ /* stored as doubles too, see above */
131
+ #if NO_READ_WRITE == 0 && !defined(SFLOAT)
132
+ #include "problems/issue_140.h"
133
+ #include "problems/max_ent.h"
134
+ #include "problems/mpc_bug.h"
135
+ #else
136
+ _SKIP(issue_140)
101
137
  _SKIP(max_ent)
102
138
  _SKIP(mpc_bug)
103
139
  #endif
104
140
 
105
- static const char *all_tests(void) {
141
+ static void all_tests(void) {
106
142
  mu_run_test(test_validation);
107
143
  mu_run_test(degenerate);
108
144
  mu_run_test(dense_qp);
@@ -113,6 +149,9 @@ static const char *all_tests(void) {
113
149
  mu_run_test(complex_PSD);
114
150
  mu_run_test(sd_and_complex_sd);
115
151
  mu_run_test(test_psd_metric);
152
+ mu_run_test(test_psd_parallel);
153
+ mu_run_test(test_psd_parallel_solve);
154
+ mu_run_test(test_psd_scale_updates);
116
155
  mu_run_test(hs21_tiny_qp);
117
156
  mu_run_test(hs21_tiny_qp_rw);
118
157
  mu_run_test(test_rw_settings);
@@ -126,6 +165,9 @@ static const char *all_tests(void) {
126
165
  mu_run_test(random_prob);
127
166
  mu_run_test(max_ent);
128
167
  mu_run_test(mpc_bug);
168
+ mu_run_test(issue_140);
169
+ mu_run_test(issue_220);
170
+ mu_run_test(issue_499);
129
171
  mu_run_test(test_exp_cone);
130
172
  mu_run_test(test_dual_exp_cone);
131
173
  mu_run_test(test_power_cone);
@@ -133,6 +175,8 @@ static const char *all_tests(void) {
133
175
  mu_run_test(test_dual_power_cone);
134
176
  mu_run_test(test_multi_power);
135
177
  mu_run_test(test_power_cone_infeasible);
178
+ mu_run_test(test_power_cone_small_scale);
179
+ mu_run_test(test_power_cone_proj_tiny_component);
136
180
  mu_run_test(test_soc_size1);
137
181
  mu_run_test(test_soc_size2);
138
182
  mu_run_test(test_soc_size3);
@@ -160,6 +204,7 @@ static const char *all_tests(void) {
160
204
  mu_run_test(test_time_limit_secs);
161
205
  mu_run_test(test_warm_start);
162
206
  mu_run_test(test_mixed_cones);
207
+ mu_run_test(test_non_psd_p);
163
208
  mu_run_test(test_root_plus_equivalence);
164
209
  mu_run_test(test_normalize_roundtrip_lp);
165
210
  mu_run_test(test_normalize_roundtrip_qp);
@@ -171,17 +216,37 @@ static const char *all_tests(void) {
171
216
  mu_run_test(several_logdet_cones);
172
217
  mu_run_test(test_ell1_cone);
173
218
  mu_run_test(test_ell1_and_nuc);
174
- return 0;
219
+ mu_run_test(test_spectral_metric_updates);
175
220
  }
176
221
  int main(void) {
177
- const char *result = all_tests();
178
- if (result != 0) {
179
- scs_printf("%s\n", result);
222
+ int i;
223
+ /* line buffer so that a slow or stuck test is visible in a piped CI log */
224
+ setvbuf(stdout, NULL, _IOLBF, 0);
225
+ all_tests();
226
+ scs_printf("Tests run: %d, skipped: %d, total: %d\n", tests_run, tests_skipped,
227
+ MU_TOTAL_TESTS);
228
+ if (tests_skipped > 0) {
229
+ scs_printf("Skipped (compiled out by build flags):");
230
+ for (i = 0; i < tests_skipped && i < MU_MAX_FAILED_TESTS; ++i) {
231
+ scs_printf(" %s", skipped_tests[i]);
232
+ }
233
+ scs_printf("\n");
234
+ }
235
+ if (tests_run + tests_skipped != MU_TOTAL_TESTS) {
236
+ scs_printf("TEST COUNT MISMATCH: %d run + %d skipped != %d expected "
237
+ "(update MU_TOTAL_TESTS in test/run_tests.c)\n",
238
+ tests_run, tests_skipped, MU_TOTAL_TESTS);
239
+ tests_failed++;
240
+ }
241
+ if (tests_failed > 0) {
242
+ scs_printf("%d TEST(S) FAILED:\n", tests_failed);
243
+ for (i = 0; i < tests_failed && i < MU_MAX_FAILED_TESTS; ++i) {
244
+ scs_printf(" %s\n", failed_tests[i]);
245
+ }
180
246
  scs_printf("TEST FAILED!\n");
181
247
  } else {
182
248
  scs_printf("ALL TESTS PASSED\n");
183
249
  }
184
- scs_printf("Tests run: %d\n", tests_run);
185
250
 
186
- return result != 0;
251
+ return tests_failed != 0;
187
252
  }
@@ -130,6 +130,7 @@ static const char *exp_design(void) {
130
130
  mu_assert("exp_design: dual feas error: ", ABS(info.res_dual) < 1e-6);
131
131
  mu_assert("exp_design: duality gap error: ", ABS(info.gap) < 1e-6);
132
132
 
133
+ remove("test_exp_design.csv");
133
134
  /* kill data */
134
135
  scs_free(d->A);
135
136
  scs_free(k);
@@ -211,6 +211,7 @@ static const char *several_logdet_cones(void) {
211
211
  mu_assert("several logdet cones: duality gap error ",
212
212
  ABS(info.gap) < 5 * 1e-6);
213
213
 
214
+ remove("several_logdet_cone.csv");
214
215
  /* kill data */
215
216
  scs_free(d->A);
216
217
  scs_free(k);
@@ -0,0 +1,163 @@
1
+ #include "glbopts.h"
2
+ #include "linalg.h"
3
+ #include "minunit.h"
4
+ #include "problem_utils.h"
5
+ #include "scs.h"
6
+ #include "scs_matrix.h"
7
+ #include "util.h"
8
+
9
+ /*
10
+ * Spectral cones under mid-solve metric changes.
11
+ *
12
+ * Unlike the closed-form projections of the standard cones, the spectral-cone
13
+ * projections are iterative inner solvers that carry warm-start state across
14
+ * outer iterations (log_cone_warmstarts, saved_log_projs). Both the scalar
15
+ * adaptive_scale and the dynamic diagonal rescaling change the diag_r metric
16
+ * mid-solve, and that state belongs to the metric that produced it, so
17
+ * update_scale drops it via SCS(reset_cone_cache). This test covers the
18
+ * interaction that hook exists for.
19
+ *
20
+ * A regression here is silent: the projections are the only writers of the
21
+ * dual iterate and the SCS residuals never test cone membership, so a bad
22
+ * projection terminates 'solved' with a correct objective and a y far outside
23
+ * the dual cone. The objective checks below would not catch it; the cone
24
+ * distance checks are the point of this test.
25
+ *
26
+ * The problem is the exp_design D-optimal design instance (one logdet cone,
27
+ * the projection with the Newton/IPM inner solver and warm-start cache). We
28
+ * solve it repeatedly from initial scales spanning eight orders of magnitude,
29
+ * which forces many metric updates rather than the handful a well-scaled
30
+ * start produces, and assert that every solve lands on the cone.
31
+ */
32
+ static const char *test_spectral_metric_updates(void) {
33
+ /* initial scales far from the value the heuristic settles on, so that
34
+ * adaptive_scale and the diagonal rescaling both fire repeatedly.
35
+ * The range stops at 1e-3: this instance's logdet projection diverges
36
+ * from a 1e-4 start (on master too, at iteration 0 before any metric
37
+ * update), which is a separate robustness limit and not what this test
38
+ * is about. */
39
+ static const scs_float scales[] = {1e-3, 1e-2, 1e-1, 1e0,
40
+ 1e1, 1e2, 1e3, 1e4};
41
+ const scs_int n_scales = (scs_int)(sizeof(scales) / sizeof(scales[0]));
42
+ scs_int total_scale_updates = 0;
43
+ scs_int trial;
44
+
45
+ /* exp_design data: m = 15, n = 8, one logdet cone of dimension 3 */
46
+ scs_float Ax[] = {
47
+ -1., 1., -1., 3.24, 0.16,
48
+ 1., 4.84, 3.61, 1., -1.,
49
+ 2.54558441, -0.11313708, -0.14142136, 1.24450793, 0.26870058,
50
+ -2.12132034, -1., 2.03646753, 0.05656854, 0.56568542,
51
+ 0.93338095, 4.03050865, 0.28284271, -1., 1.,
52
+ 0.04, 0.01, 0.16, 0.01, 2.25,
53
+ -1., 1.13137085, -0.02828427, -0.05656854, 0.16970563,
54
+ 0.21213203, -0.42426407, -1., 0.64, 0.01,
55
+ 0.16, 0.09, 2.25, 0.04, -1.};
56
+ scs_int Ai[] = {7, 0, 8, 1, 2, 3, 4, 5, 6, 9, 1, 2, 3, 4, 5,
57
+ 6, 10, 1, 2, 3, 4, 5, 6, 11, 1, 2, 3, 4, 5, 6,
58
+ 12, 1, 2, 3, 4, 5, 6, 13, 1, 2, 3, 4, 5, 6, 14};
59
+ scs_int Ap[] = {0, 1, 3, 10, 17, 24, 31, 38, 45};
60
+
61
+ scs_float b[] = {1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0.};
62
+ scs_float c[] = {1., 0., 0., 0., 0., 0., 0., 0.};
63
+
64
+ scs_int m = 15;
65
+ scs_int n = 8;
66
+ scs_int d_array[] = {3};
67
+
68
+ /* computed using mosek (Ax above is truncated, mosek solved the problem
69
+ * with the non-truncated data) */
70
+ scs_float opt = 3.0333290743428574;
71
+
72
+ for (trial = 0; trial < n_scales; ++trial) {
73
+ ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
74
+ ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
75
+ ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
76
+ ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
77
+ ScsConeWork *cone_work;
78
+ ScsInfo info = {0};
79
+ scs_int exitflag;
80
+ scs_float perr, derr, ydist, sdist;
81
+
82
+ d->m = m;
83
+ d->n = n;
84
+ d->b = b;
85
+ d->c = c;
86
+
87
+ d->A = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
88
+ d->A->m = m;
89
+ d->A->n = n;
90
+ d->A->x = Ax;
91
+ d->A->i = Ai;
92
+ d->A->p = Ap;
93
+
94
+ k->z = 1;
95
+ k->l = 6;
96
+ k->d = d_array;
97
+ k->dsize = 1;
98
+
99
+ scs_set_default_settings(stgs);
100
+ stgs->eps_abs = 1e-7;
101
+ stgs->eps_rel = 1e-7;
102
+ stgs->eps_infeas = 1e-9;
103
+ stgs->scale = scales[trial];
104
+ /* both metric-update mechanisms on: the scalar heuristic and the
105
+ * dynamic diagonal rescaling that updates far more often */
106
+ stgs->adaptive_scale = 1;
107
+ stgs->adaptive_diag_scale = 1;
108
+
109
+ exitflag = scs(d, k, stgs, sol, &info);
110
+
111
+ perr = SCS(dot)(d->c, sol->x, d->n) - opt;
112
+ derr = -SCS(dot)(d->b, sol->y, d->m) - opt;
113
+
114
+ scs_printf("scale %.0e: %li scale updates, primal err %.4e, dual err "
115
+ "%.4e\n",
116
+ stgs->scale, (long)info.scale_updates, perr, derr);
117
+
118
+ mu_assert("test_spectral_metric_updates: SCS failed to produce "
119
+ "outputflag SCS_SOLVED",
120
+ exitflag == SCS_SOLVED);
121
+ mu_assert_less("test_spectral_metric_updates: primal obj ERROR", ABS(perr),
122
+ 1e-4);
123
+ mu_assert_less("test_spectral_metric_updates: dual obj ERROR", ABS(derr),
124
+ 1e-4);
125
+
126
+ /* the actual regression check: a projection that mishandled the metric
127
+ * change leaves y outside the dual cone (and s outside the cone) while
128
+ * the objective above still looks right */
129
+ cone_work = SCS(init_cone)(k, m);
130
+ mu_assert("test_spectral_metric_updates: failed to init cone work",
131
+ cone_work != SCS_NULL);
132
+ ydist = get_dual_cone_dist(sol->y, cone_work, m);
133
+ sdist = get_pri_cone_dist(sol->s, cone_work, m);
134
+ SCS(finish_cone)(cone_work);
135
+
136
+ scs_printf("scale %.0e: y cone dist %.4e, s cone dist %.4e\n",
137
+ stgs->scale, ydist, sdist);
138
+
139
+ /* cone_dist_tol: the distances are measured with the logdet projection,
140
+ * which is the limit on how tightly they can be asserted */
141
+ mu_assert_less("test_spectral_metric_updates: y cone dist ERROR",
142
+ ABS(ydist), cone_dist_tol(k));
143
+ mu_assert_less("test_spectral_metric_updates: s cone dist ERROR",
144
+ ABS(sdist), cone_dist_tol(k));
145
+
146
+ total_scale_updates += info.scale_updates;
147
+
148
+ scs_free(d->A);
149
+ scs_free(k);
150
+ scs_free(stgs);
151
+ scs_free(d);
152
+ SCS(free_sol)(sol);
153
+ }
154
+
155
+ /* Guard the guard: if the metric never changed mid-solve, the checks above
156
+ * are vacuous and this test has silently stopped covering the interaction.
157
+ */
158
+ mu_assert("test_spectral_metric_updates: no metric updates were triggered, "
159
+ "so the test no longer exercises mid-solve metric changes",
160
+ total_scale_updates > 0);
161
+
162
+ return 0;
163
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -39,7 +39,6 @@ files:
39
39
  - lib/scs/solver.rb
40
40
  - lib/scs/version.rb
41
41
  - vendor/scs/CITATION.cff
42
- - vendor/scs/CLAUDE.md
43
42
  - vendor/scs/CMakeLists.txt
44
43
  - vendor/scs/CONTRIBUTING.md
45
44
  - vendor/scs/LICENSE.txt
@@ -127,6 +126,7 @@ files:
127
126
  - vendor/scs/src/util.c
128
127
  - vendor/scs/test/minunit.h
129
128
  - vendor/scs/test/mkl_interface_mismatch.c
129
+ - vendor/scs/test/mkl_psd_guard.c
130
130
  - vendor/scs/test/packaging/CMakeLists.txt
131
131
  - vendor/scs/test/packaging/consume.c
132
132
  - vendor/scs/test/problem_utils.h
@@ -138,6 +138,11 @@ files:
138
138
  - vendor/scs/test/problems/infeasible_lp.h
139
139
  - vendor/scs/test/problems/infeasible_socp.h
140
140
  - vendor/scs/test/problems/infeasible_tiny_qp.h
141
+ - vendor/scs/test/problems/issue_140
142
+ - vendor/scs/test/problems/issue_140.h
143
+ - vendor/scs/test/problems/issue_220
144
+ - vendor/scs/test/problems/issue_220.h
145
+ - vendor/scs/test/problems/issue_499.h
141
146
  - vendor/scs/test/problems/lp_update.h
142
147
  - vendor/scs/test/problems/max_ent
143
148
  - vendor/scs/test/problems/max_ent.h
@@ -157,11 +162,14 @@ files:
157
162
  - vendor/scs/test/problems/test_exp_cone.h
158
163
  - vendor/scs/test/problems/test_inaccurate.h
159
164
  - vendor/scs/test/problems/test_mixed_cones.h
165
+ - vendor/scs/test/problems/test_non_psd_p.h
160
166
  - vendor/scs/test/problems/test_normalize_roundtrip.h
161
167
  - vendor/scs/test/problems/test_power_cone.h
162
168
  - vendor/scs/test/problems/test_prob_from_data_file.h
163
169
  - vendor/scs/test/problems/test_psd_metric.h
164
170
  - vendor/scs/test/problems/test_psd_n1.h
171
+ - vendor/scs/test/problems/test_psd_parallel.h
172
+ - vendor/scs/test/problems/test_psd_scale_updates.h
165
173
  - vendor/scs/test/problems/test_root_plus.h
166
174
  - vendor/scs/test/problems/test_rw_settings.h
167
175
  - vendor/scs/test/problems/test_soc_sizes.h
@@ -184,6 +192,7 @@ files:
184
192
  - vendor/scs/test/spectral_cones_problems/several_sum_largest.h
185
193
  - vendor/scs/test/spectral_cones_problems/test_ell1_and_nuc.h
186
194
  - vendor/scs/test/spectral_cones_problems/test_ell1_cone.h
195
+ - vendor/scs/test/spectral_cones_problems/test_spectral_metric_updates.h
187
196
  homepage: https://github.com/ankane/scs-ruby
188
197
  licenses:
189
198
  - MIT
@@ -202,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
211
  - !ruby/object:Gem::Version
203
212
  version: '0'
204
213
  requirements: []
205
- rubygems_version: 4.0.16
214
+ rubygems_version: 4.0.20
206
215
  specification_version: 4
207
216
  summary: SCS - the splitting conic solver - for Ruby
208
217
  test_files: []