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
@@ -121,6 +121,47 @@ ScsLinSysWork *scs_init_lin_sys_work(const ScsMatrix *A, const ScsMatrix *P,
121
121
  CUDSS_CHECK_ABORT(cudssDataCreate(p->handle, &p->solver_data), p,
122
122
  "cudssDataCreate");
123
123
 
124
+ /* Plain LDL' with no pivoting, matching or refinement, as in the CPU direct
125
+ * solver (QDLDL): the KKT matrix [R_x + P, A'; A, -R_y] is quasi-definite,
126
+ * so the factorization exists under any ordering. From version 1.0 cuDSS by
127
+ * default applies a matching to a symmetric indefinite matrix. With its
128
+ * default pivoting that makes the factor up to four times larger (2.4 times
129
+ * in geometric mean on 17 LPs and QPs), and without pivoting it made the
130
+ * solves inaccurate enough to stall SCS on some LPs. Tradeoff: one solve
131
+ * per iteration, but the accuracy of a solve rests on the conditioning of
132
+ * the system (worst test-suite residual 6e-8, against 5e-11 with cuDSS's
133
+ * default pivoting and matching).
134
+ *
135
+ * Single precision keeps one refinement step per solve, which about doubles
136
+ * the cost of a solve: without it the test suite fails (rob_gauss_cov_est
137
+ * does not converge), and Bunch-Kaufman pivoting instead of refinement does
138
+ * not fix that. */
139
+ {
140
+ cudssPivotType_t pivot_type = CUDSS_PIVOT_NONE;
141
+ #ifdef SFLOAT
142
+ int ir_n_steps = 1;
143
+ #else
144
+ int ir_n_steps = 0; /* cuDSS's default, set so that it stays fixed */
145
+ #endif
146
+ CUDSS_CHECK_ABORT(cudssConfigSet(p->solver_config, CUDSS_CONFIG_PIVOT_TYPE,
147
+ &pivot_type, sizeof(pivot_type)),
148
+ p, "cudssConfigSet: pivot type");
149
+ CUDSS_CHECK_ABORT(cudssConfigSet(p->solver_config, CUDSS_CONFIG_IR_N_STEPS,
150
+ &ir_n_steps, sizeof(ir_n_steps)),
151
+ p, "cudssConfigSet: refinement steps");
152
+ #if defined(CUDSS_VERSION) && CUDSS_VERSION >= 10000
153
+ /* cuDSS 1.0 turned matching on by default (CUDSS_MATCHING_ALG_AUTO).
154
+ * Older versions do not match unless asked to (0.5 has no matching, 0.6
155
+ * and 0.7 default to CUDSS_CONFIG_USE_MATCHING = 0, 0.8 to
156
+ * CUDSS_MATCHING_ALG_NONE), so they need no call. */
157
+ cudssMatchingAlg_t matching_alg = CUDSS_MATCHING_ALG_NONE;
158
+ CUDSS_CHECK_ABORT(cudssConfigSet(p->solver_config,
159
+ CUDSS_CONFIG_MATCHING_ALG, &matching_alg,
160
+ sizeof(matching_alg)),
161
+ p, "cudssConfigSet: matching");
162
+ #endif
163
+ }
164
+
124
165
  /* Allocate device memory for KKT matrix */
125
166
  scs_int nnz = p->kkt->p[p->n_plus_m];
126
167
 
@@ -208,7 +249,14 @@ ScsLinSysWork *scs_init_lin_sys_work(const ScsMatrix *A, const ScsMatrix *P,
208
249
  p->d_sol_mat, p->d_b_mat),
209
250
  p, "cudssExecute: factorization");
210
251
 
211
- /* Inertia check: verify P is PSD by checking positive eigenvalue count */
252
+ /* Inertia check. The KKT matrix has n positive eigenvalues exactly when
253
+ * R_x + P + A' R_y^{-1} A is positive definite, which holds whenever P is
254
+ * PSD. Fewer means P is not PSD (a P that is only mildly indefinite can
255
+ * still pass). cuDSS returns the two counts in the matrix's index type
256
+ * (SCS_CUDA_INDEX): 64-bit integers under DLONG, where it writes 16 bytes,
257
+ * and 32-bit ones otherwise, where it rejects a 16-byte buffer (cuDSS 1.0.0).
258
+ * scs_int follows DLONG in the same way, so it matches; test_non_psd_p
259
+ * covers both widths. */
212
260
  {
213
261
  scs_int inertia[2]; /* [0] = positive, [1] = negative */
214
262
  size_t inertia_written;
@@ -217,7 +265,7 @@ ScsLinSysWork *scs_init_lin_sys_work(const ScsMatrix *A, const ScsMatrix *P,
217
265
  sizeof(inertia), &inertia_written),
218
266
  p, "cudssDataGet: inertia");
219
267
  if (inertia[0] < p->n) {
220
- scs_printf("KKT matrix has < n positive eigenvalues. P not PSD.");
268
+ scs_printf("KKT matrix has < n positive eigenvalues. P not PSD.\n");
221
269
  scs_free_lin_sys_work(p);
222
270
  return SCS_NULL;
223
271
  }
@@ -1,6 +1,8 @@
1
1
  #include "private.h"
2
2
  #include "linsys.h"
3
3
 
4
+ #include <string.h>
5
+
4
6
  /* norm to use when deciding convergence */
5
7
  /* should be consistent with CG_NORM in glbopts.h */
6
8
  #define USE_L2_NORM (0)
@@ -123,12 +125,23 @@ void scs_free_lin_sys_work(ScsLinSysWork *p) {
123
125
  }
124
126
  }
125
127
 
126
- /* z = M * z elementwise in place, assumes M, z on GPU */
128
+ /* z = M * z elementwise in place, assumes M, z on GPU.
129
+ *
130
+ * dgmm computes C = diag(M) * A; here A and C are both z, as an n x 1 matrix.
131
+ * cuBLAS allows C == A when their leading dimensions are equal.
132
+ *
133
+ * This runs three times per CG iteration. It used to be tbmv with zero
134
+ * bandwidth, which gives the same values but whose time grows as n^2 (cuBLAS
135
+ * 13.1: 0.7 ms per call at n = 1e5 and 63 ms at n = 1e6, against 0.01 ms and
136
+ * 0.1 ms for dgmm).
137
+ */
127
138
  static void scale_by_diag(cublasHandle_t cublas_handle, scs_float *M,
128
139
  scs_float *z, scs_int n) {
129
- CUBLAS(tbmv)
130
- (cublas_handle, CUBLAS_FILL_MODE_LOWER, CUBLAS_OP_N, CUBLAS_DIAG_NON_UNIT, n,
131
- 0, M, 1, z, 1);
140
+ if (n <= 0) {
141
+ return; /* dgmm rejects a leading dimension of 0 */
142
+ }
143
+ CUBLAS(dgmm)
144
+ (cublas_handle, CUBLAS_SIDE_LEFT, n, 1, z, n, M, 1, z, n);
132
145
  }
133
146
 
134
147
  /* y = (R_x + P + A' R_y^{-1} A) x */
@@ -164,7 +164,7 @@ ScsLinSysWork *scs_init_lin_sys_work(const ScsMatrix *A, const ScsMatrix *P,
164
164
  }
165
165
 
166
166
  if (p->iparm[21] < p->n) {
167
- scs_printf("KKT matrix has < n positive eigenvalues. P not PSD.");
167
+ scs_printf("KKT matrix has < n positive eigenvalues. P not PSD.\n");
168
168
  scs_free_lin_sys_work(p);
169
169
  return SCS_NULL;
170
170
  }
data/vendor/scs/scs.mk CHANGED
@@ -61,6 +61,10 @@ endif
61
61
  # Default CUDA path; override with CUDA_PATH=/path/to/cuda
62
62
  ifeq ($(CUDA_PATH), )
63
63
  CUDA_PATH=/usr/local/cuda
64
+ endif
65
+
66
+ # Default the compiler independently, including when CUDA_PATH is supplied.
67
+ ifeq ($(CUCC), )
64
68
  CUCC = $(CUDA_PATH)/bin/nvcc
65
69
  endif
66
70
 
@@ -164,9 +168,11 @@ OMPROOT ?= $(MKLROOT)
164
168
  MKLFLAGS = -L$(MKLROOT)/lib -L$(MKLROOT)/lib/intel64 -L$(OMPROOT)/lib -Wl,--no-as-needed -lmkl_rt -liomp5 -lpthread -ldl
165
169
 
166
170
  ############ OPENMP: ############
167
- # set USE_OPENMP = 1 to allow openmp (multi-threaded matrix multiplies):
171
+ # set USE_OPENMP = 1 to allow openmp (multi-threaded matrix multiplies and
172
+ # projections onto exponential cones):
168
173
  # set the number of threads to, for example, 4 by entering the command:
169
174
  # export OMP_NUM_THREADS=4
175
+ # The PSD blocks are projected in parallel only with USE_PARALLEL_PSD (below)
170
176
 
171
177
  USE_OPENMP = 0
172
178
  ifneq ($(USE_OPENMP), 0)
@@ -202,6 +208,36 @@ ifneq ($(USE_LAPACK), 0)
202
208
  endif
203
209
  endif
204
210
 
211
+ ############ PARALLEL PSD PROJECTION ############
212
+ # set USE_PARALLEL_PSD = 1, with USE_OPENMP = 1, to project the PSD blocks of
213
+ # a problem in parallel: on up to OMP_NUM_THREADS threads, each of which calls
214
+ # LAPACK for its own blocks. Without it the blocks are projected one after
215
+ # another, and a multithreaded BLAS uses its threads inside each block.
216
+ #
217
+ # It is off by default because it is only faster when the BLAS runs on ONE
218
+ # thread inside the threads of SCS. Otherwise the threads of the two multiply,
219
+ # and the projection is slower than without the option.
220
+ # - A BLAS on the same OpenMP runtime as SCS does that by itself (an OpenMP
221
+ # build of OpenBLAS or BLIS, MKL on the matching threading layer). This is
222
+ # the setup to enable the option for.
223
+ # - A BLAS with threads of its own (a pthreads OpenBLAS, the default on Debian
224
+ # and Ubuntu) has to be set to one thread (OPENBLAS_NUM_THREADS=1).
225
+ # - A BLAS on another OpenMP runtime than SCS starts its own threads in every
226
+ # thread of SCS. SCS stops MKL from doing so where it can (Linux, shared
227
+ # MKL); for any other, build SCS and the BLAS with the same compiler family.
228
+ # See "Parallel projection of PSD blocks" on the BLAS and LAPACK page of the
229
+ # documentation, and the comment on the option in src/cones.c.
230
+ USE_PARALLEL_PSD = 0
231
+ ifneq ($(USE_PARALLEL_PSD), 0)
232
+ ifeq ($(USE_OPENMP), 0)
233
+ $(error USE_PARALLEL_PSD requires USE_OPENMP to be enabled)
234
+ endif
235
+ ifeq ($(USE_LAPACK), 0)
236
+ $(error USE_PARALLEL_PSD requires USE_LAPACK to be enabled)
237
+ endif
238
+ CUSTOM_FLAGS += -DUSE_PARALLEL_PSD
239
+ endif
240
+
205
241
  ############ SPECTRAL CONES ############
206
242
  USE_SPECTRAL_CONES = 0
207
243
  ifneq ($(USE_SPECTRAL_CONES), 0)
@@ -219,9 +255,14 @@ PYTHON = 0
219
255
  ifneq ($(PYTHON), 0)
220
256
  CUSTOM_FLAGS += -DPYTHON=$(PYTHON) # python extension
221
257
  endif
258
+ # Compiling for use in R: SCS then prints with Rprintf, which needs the R
259
+ # headers on the include path. The macro the source reads is R_LANG, which is
260
+ # also what the R package passes in CFLAGS when it builds SCS. Only the
261
+ # libraries can be built this way without R: the demo and test programs call
262
+ # Rprintf and do not link.
222
263
  USING_R = 0
223
264
  ifneq ($(USING_R), 0)
224
- CUSTOM_FLAGS += -DUSING_R=$(USING_R) # R extension
265
+ CUSTOM_FLAGS += -DR_LANG # R extension
225
266
  endif
226
267
 
227
268
  # debug to see var values, e.g. 'make print-OBJECTS' shows OBJECTS value
data/vendor/scs/src/aa.c CHANGED
@@ -145,7 +145,9 @@ extern "C" {
145
145
  #endif
146
146
 
147
147
  /* BLAS / LAPACK functions used */
148
+ #ifndef SFLOAT
148
149
  aa_float BLAS(nrm2)(blas_int *n, aa_float *x, blas_int *incx);
150
+ #endif
149
151
  void BLAS(axpy)(blas_int *n, aa_float *a, const aa_float *x, blas_int *incx,
150
152
  aa_float *y, blas_int *incy);
151
153
  void BLAS(gemv)(const char *trans, const blas_int *m, const blas_int *n,
@@ -178,6 +180,24 @@ void BLAS(ormqr)(const char *side, const char *trans, const blas_int *m,
178
180
  }
179
181
  #endif
180
182
 
183
+ /* Single precision does not call snrm2: the legacy Accelerate interface macOS
184
+ * links for -lblas returns REAL functions as a C double (the f2c convention)
185
+ * while other BLAS return a float, so no prototype is right for both. Summing
186
+ * squares in double keeps nrm2's overflow and underflow safety. */
187
+ #ifdef SFLOAT
188
+ static aa_float aa_nrm2(const blas_int *n, const aa_float *x,
189
+ const blas_int *incx) {
190
+ double nmsq = 0.;
191
+ blas_int i;
192
+ for (i = 0; i < *n; ++i) {
193
+ nmsq += (double)x[i * *incx] * (double)x[i * *incx];
194
+ }
195
+ return (aa_float)sqrt(nmsq);
196
+ }
197
+ #else
198
+ #define aa_nrm2 BLAS(nrm2)
199
+ #endif
200
+
181
201
  /* This file uses Anderson acceleration to improve the convergence of
182
202
  * a fixed point mapping.
183
203
  * At each iteration we solve a (small) regularized least-squares
@@ -392,9 +412,9 @@ static void update_accel_params(const aa_float *x, const aa_float *f, AaWork *a,
392
412
  * preserve nrm2's overflow/underflow safety. */
393
413
  if (a->regularization > 0) {
394
414
  if (a->type1) {
395
- a->nrm_s_col[idx] = BLAS(nrm2)(&bdim, s_col, &one);
415
+ a->nrm_s_col[idx] = aa_nrm2(&bdim, s_col, &one);
396
416
  }
397
- a->nrm_y_col[idx] = BLAS(nrm2)(&bdim, y_col, &one);
417
+ a->nrm_y_col[idx] = aa_nrm2(&bdim, y_col, &one);
398
418
  }
399
419
 
400
420
  /* State advance for next iter: (x_prev, f_prev, g_prev) <- (x, f, g).
@@ -409,7 +429,7 @@ static void update_accel_params(const aa_float *x, const aa_float *f, AaWork *a,
409
429
  }
410
430
 
411
431
  /* ||g|| = ||x - f|| (current residual norm, used by the safeguard). */
412
- a->norm_g = BLAS(nrm2)(&bdim, a->g, &one);
432
+ a->norm_g = aa_nrm2(&bdim, a->g, &one);
413
433
 
414
434
  TIME_TOC
415
435
  }
@@ -568,7 +588,7 @@ static aa_float solve(aa_float *f, AaWork *a, aa_int len) {
568
588
  ("NoTrans", &brank, &one, a->W, &bmem, a->ipiv, a->ir_res,
569
589
  &brank, &info);
570
590
  if (info != 0) break;
571
- dnorm = BLAS(nrm2)(&brank, a->ir_res, &one);
591
+ dnorm = aa_nrm2(&brank, a->ir_res, &one);
572
592
  BLAS(axpy)(&brank, &onef, a->ir_res, &one, a->gamma_red, &one);
573
593
  if (k > 0 && dnorm >= 0.5 * prev_dnorm) break;
574
594
  prev_dnorm = dnorm;
@@ -599,7 +619,7 @@ static aa_float solve(aa_float *f, AaWork *a, aa_int len) {
599
619
  }
600
620
  BLAS(trsv)("Upper", "NoTrans", "NonUnit", &brank, a->A_aug,
601
621
  &aug_rows, a->ir_res, &one);
602
- dnorm = BLAS(nrm2)(&brank, a->ir_res, &one);
622
+ dnorm = aa_nrm2(&brank, a->ir_res, &one);
603
623
  BLAS(axpy)(&brank, &onef, a->ir_res, &one, a->gamma_red, &one);
604
624
  if (k > 0 && dnorm >= 0.5 * prev_dnorm) break;
605
625
  prev_dnorm = dnorm;
@@ -618,7 +638,7 @@ static aa_float solve(aa_float *f, AaWork *a, aa_int len) {
618
638
  }
619
639
 
620
640
  /* 5. Validate γ via ‖γ‖₂ against max_weight_norm. */
621
- aa_norm = (info == 0) ? BLAS(nrm2)(&blen, gamma, &one) : -1.0;
641
+ aa_norm = (info == 0) ? aa_nrm2(&blen, gamma, &one) : -1.0;
622
642
 
623
643
  /* Record diagnostics for this solve, regardless of accept/reject.
624
644
  * NaN last_aa_norm signals "no valid norm this solve" — distinguishing
@@ -907,7 +927,7 @@ aa_int aa_safeguard(aa_float *f_new, aa_float *x_new, AaWork *a) {
907
927
  /* work = x_new - f_new */
908
928
  BLAS(axpy)(&bdim, &neg_onef, f_new, &one, a->work, &one);
909
929
  /* norm_diff = || f_new - x_new || */
910
- norm_diff = BLAS(nrm2)(&bdim, a->work, &one);
930
+ norm_diff = aa_nrm2(&bdim, a->work, &one);
911
931
  /* g = f - x */
912
932
  if (norm_diff > a->safeguard_factor * a->norm_g) {
913
933
  /* in this case we reject the AA step and reset */