Skip to content

Commit

Permalink
Merge pull request #14 from bnaras/bodono_v3.2.3_tinytest
Browse files Browse the repository at this point in the history
Bodono v3.2.3 tinytest
  • Loading branch information
FlorianSchwendinger authored Apr 11, 2023
2 parents 7e30714 + 1326df0 commit da152c4
Show file tree
Hide file tree
Showing 64 changed files with 2,031 additions and 517 deletions.
3 changes: 0 additions & 3 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ src/scs/linsys/gpu
src/scs/linsys/indirect
inst/tools/*

tests/testthat/test_sparse_utils.R
tests/testthat/test_problems.R

# Remove the citation file to pass checks. It is also in inst/CITATION
src/scs/CITATION.cff
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.Rhistory
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: scs
Version: 3.0-1
Version: 3.2.3
Title: Splitting Conic Solver
Authors@R: c( person("Florian", "Schwendinger", role = c("aut", "cre"), email = "[email protected]"),
person("Brendan", "O'Donoghue", role = c("aut", "cph")),
Expand All @@ -14,8 +14,9 @@ Description: Solves convex cone programs via operator splitting. Can solve:
Depends: R (>= 3.5.0)
SystemRequirements: GNU Make
Suggests:
Matrix,
slam,
testthat
tinytest
Encoding: UTF-8
License: GPL-3
URL: https://github.com/FlorianSchwendinger/scs
Expand Down
19 changes: 6 additions & 13 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
citHeader("To cite scs in publications use:")

citEntry(entry = "Article",
bibentry(bibtype = "Article",
title = "Operator Splitting for Conic Optimization via Homogeneous Self-Dual Embedding",
author = personList(as.person("O'Donoghue Brendan"),
as.person("Chu Eric"),
as.person("Parikh Neal"),
as.person("Boyd Stephen")),
author = c(person(given = "Brendan", family = "O'Donoghue"),
person(given = "Eric", family = "Chu"),
person(given = "Parikh", family = "Neal"),
person(given = "Stephen", family = "Boyd")),
journal = "Journal of Optimization Theory and Applications",
year = "2016",
month = "Jun",
Expand All @@ -15,11 +13,6 @@ citEntry(entry = "Article",
pages = "1042--1068",
doi = "10.1007/s10957-016-0892-3",
url = "https://doi.org/10.1007/s10957-016-0892-3",

textVersion =
paste("O'Donoghue Brendan, Chu Eric, Parikh Neal, Boyd Stephen (2016).",
"Operator Splitting for Conic Optimization via Homogeneous Self-Dual Embedding.",
"Journal of Optimization Theory and Applications 169(3), 1042-1068.",
"URL https://doi.org/10.1007/s10957-016-0892-3.")
header = "To cite scs in publications use:"
)

50 changes: 0 additions & 50 deletions inst/check.R

This file was deleted.

5 changes: 5 additions & 0 deletions inst/tinytest/problem_results/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Saved Results from scs 3.2.3 Tests

These test problems and expected results were saved from `scs` source
(`C`) test files using
[RInside](https://cran.r-project.org/package=RInside).
Binary file added inst/tinytest/problem_results/degenerate1.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/degenerate2.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/degenerate3.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/degenerate4.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/hs21_tiny_qp
Binary file not shown.
177 changes: 177 additions & 0 deletions inst/tinytest/problem_results/hs21_tiny_qp.csv

Large diffs are not rendered by default.

Binary file added inst/tinytest/problem_results/hs21_tiny_qp1.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/hs21_tiny_qp2.RDS
Binary file not shown.
Binary file not shown.
Binary file added inst/tinytest/problem_results/max_ent.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/qafiro_tiny_qp1.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/qafiro_tiny_qp2.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/qafiro_tiny_qp3.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/random_prob.RDS
Binary file not shown.
Binary file not shown.
Binary file added inst/tinytest/problem_results/small_lp.RDS
Binary file not shown.
Binary file added inst/tinytest/problem_results/small_qp1.RDS
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions inst/tinytest/test_example.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## A simple example"

A <- matrix(c(1), 2, 1)
b <- c(1,1)
c <- c(1)
cone <- list(z = 2)
params <- list(eps_abs = 1e-3, eps_rel = 1e-3, max_iters = 50)
sol <- scs(A = A, b = b, obj = c, cone = cone, control = params)

expect_equal(sol$info$status, "solved")
expect_equal(sol$x, 1, tolerance = 1e-7)
expect_equal(sol$y, c(-0.5, -0.5), tolerance = 1e-7)
expect_equal(sol$info$pobj, 1, tolerance = 1e-7)
53 changes: 53 additions & 0 deletions inst/tinytest/test_problems.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## "Saved Problems"

rds_files <- c(
"degenerate1.RDS",
"degenerate2.RDS",
"degenerate3.RDS",
"degenerate4.RDS",
"hs21_tiny_qp1.RDS",
"hs21_tiny_qp2.RDS",
"infeasible_tiny_qp.RDS",
"max_ent.RDS",
"qafiro_tiny_qp1.RDS",
"qafiro_tiny_qp2.RDS",
"qafiro_tiny_qp3.RDS",
"random_prob.RDS",
"rob_gauss_cov_est.RDS",
"small_lp.RDS",
"small_qp1.RDS",
"unbounded_tiny_qp.RDS"
)

info_vars_to_check <- c(
"iter",
"status",
"status_val",
"scale_updates",
"pobj",
"dobj",
## "res_pri",
## "res_dual",
## "gap",
## "res_infeas",
"res_unbdd_a",
"res_unbdd_p",
## "setup_time",
## "solve_time",
"scale",
## "comp_slack",
"rejected_accel_steps",
"accepted_accel_steps"
## "lin_sys_time",
## "cone_time",
## "accel_time"
)

sol_vars_to_check <- c("x", "y", "s")

for (fname in rds_files) {
d <- readRDS(file.path("problem_results", fname))
sol <- scs(A = d$data$A, P = d$data$P, b = d$data$b, obj = d$data$obj, cone = d$cone, control = d$settings)
expect_equal(sol$info[info_vars_to_check], d$sol$info[info_vars_to_check], tolerance = d$settings$eps_abs)
expect_equal(sol[sol_vars_to_check], d$sol[sol_vars_to_check], tolerance = d$settings$eps_abs)
}
29 changes: 29 additions & 0 deletions inst/tinytest/test_psd.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Simple PSD Test

A <- simple_triplet_matrix(
i = c(1L, 2L, 3L, 4L, 5L, 7L, 8L, 9L, 1L, 2L, 3L, 5L, 6L, 7L, 8L, 9L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L),
j = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L),
v = c(-7, -15.556349186104, 3, -21, -15.556349186104, 10, 11.3137084989848,
5, 7, -25.4558441227157, 8, 14.142135623731, 22.6274169979695,
-10, -14.142135623731, 3, -2, -11.3137084989848, 1, -5, 2.82842712474619,
-24.0416305603426, -6, 11.3137084989848, 6), nrow = 9L, ncol = 3L)

rhs <- c(33, -12.7279220613579, 26, 14, 12.7279220613579, 56.5685424949238, 91, 14.142135623731, 15)
obj <- c(1, -1, 1)
cone <- list(z = 0L, l = 0L, s = c(2, 3))

sol <- scs(A = A, b = rhs, obj = obj, cone = cone, control = list(verbose = 1))
expect_equal(sol$info$status, "solved")
expect_equal(sol$x,
c(-0.36778629730617, 1.89834935806707, -0.88746074956525),
tolerance = 1e-4)
expect_equal(sol$y,
c(0.00396134156379081, -0.00613634113889057, 0.00475276897567086, 0.0558030988006113,
-0.00340904764830297, 0.0342440719001259, 0.000104130479854425, -0.00147926212203912,
0.0105070907711366),
tolerance = 1e-4)
expect_equal(sol$info$pobj, -3.1535964049385, tolerance = 1e-4)
expect_equal(sol$info$dobj, -3.1535519733301, tolerance = 1e-4)

14 changes: 14 additions & 0 deletions inst/tinytest/test_random_lp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## A Random LP Problem

set.seed(1)
m <- 100
n <- 100
A <- matrix(rnorm(m * n), m, n)
b <- rnorm(m)
c <- rnorm(n)
cone <- list(z = m)
params <- list(eps_rel = 1e-4, eps_abs = 1e-4, max_iters = 5000)
sol <- scs(A = A, b = b, obj = c, cone = cone, control = params)
expect_equal(sol$info$status, "solved")
expect_equal(sol$info$pobj, 13.5089, tolerance = 1e-4)
expect_equal(sol$info$dobj, 13.5089, tolerance = 1e-4)
12 changes: 12 additions & 0 deletions inst/tinytest/test_socp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## SOCP Test

A <- simple_triplet_matrix(i = 1:4, j = c(1L, 1L, 2L, 3L), v = c(1, -1, -1, -1), nrow = 4L, ncol = 3L)
rhs <- c(1.4142135623731, 0, 0, 0)
obj <- c(1, 1, 1)
cone <- list(z = 1L, l = 0L, q = 3L)

sol <- scs(A = A, b = rhs, obj = obj, cone = cone)
expect_equal(sol$info$status, "solved")
expect_equal(sol$x, c(sqrt(2), -1, -1), tolerance = 1e-7)
expect_equal(sol$info$pobj, -0.5857864, tolerance = 1e-5)
expect_equal(sol$info$dobj, -0.5857864, tolerance = 1e-5)
23 changes: 23 additions & 0 deletions inst/tinytest/test_sparse_utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Some tests for utils

s <- Matrix::sparseMatrix(i = c(2,4,3:5), j= c(4,7:5,5), x = 1:5, dims = c(7,7), symmetric = TRUE)

## Test that make_csc_sym_matrix works on plain matrices

ms <- as.matrix(s)
cm <- scs:::make_csc_symm_matrix.matrix(ms)
s2 <- Matrix::sparseMatrix(i = cm[["matind"]], p = cm[["matbeg"]], x = cm[["values"]],
symmetric = TRUE, index1 = FALSE)

expect_equal(s, s2)


## Test that make_csc_sym_matrix works on simple triplet matrices

ts <- as(s, "dgTMatrix")
sl <- slam::simple_triplet_matrix(i = ts@i, j = ts@j, v = ts@x, nrow = 7, ncol = 7)

tm <- scs:::make_csc_symm_matrix.simple_triplet_matrix(sl)
s3 <- Matrix::sparseMatrix(i = tm[["matind"]], p = tm[["matbeg"]], x = tm[["values"]], dims = c(7, 7),
symmetric = TRUE, index1 = FALSE)
expect_equal(s, s3)
7 changes: 7 additions & 0 deletions inst/tinytest/test_tiny.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## A tiny test

sol <- scs(A = matrix(c(0.5, 2), 2, 1), b = c(3, 1), obj = 1,
cone = list(l = 2), control = list(max_iters = 5000))
expect_equal(sol$info$status, "unbounded")
expect_equal(sol$info$pobj, -Inf)
expect_equal(sol$info$dobj, -Inf)
14 changes: 3 additions & 11 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
SCS_DIR=scs
SCS_MODS_DIR=scs_mods

SOLARIS=$(shell $(R_HOME)/bin/Rscript -e 'cat(grepl("SunOS", Sys.info()["sysname"]))')

ifeq ($(SOLARIS),TRUE)
SOLARIS_FLAG=-DSOLARIS
else
SOLARIS_FLAG=-USOLARIS
endif

PKG_CFLAGS=$(SOLARIS_FLAG) -I./$(SCS_DIR)/include -DUSE_LAPACK -DCOPYAMATRIX
PKG_CFLAGS=-I./$(SCS_DIR)/include -DUSE_LAPACK -DCOPYAMATRIX
PKG_LIBS=-L$(SCS_DIR)/out -lscsdir $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

$(SHLIB): init.o scsr.o

scsr.o: scs.ts

scs.ts:
(cp -f $(SCS_MODS_DIR)/scs.mk $(SCS_DIR) && \
cp -f $(SCS_MODS_DIR)/rw.c $(SCS_DIR)/src && \
(cp -f $(SCS_MODS_DIR)/rw.c $(SCS_MODS_DIR)/scs.c $(SCS_DIR)/src && \
cp -f $(SCS_MODS_DIR)/private.c $(SCS_DIR)/linsys/cpu/direct && \
(cd $(SCS_DIR) && \
($(MAKE) purge && \
$(MAKE) out/libscsdir.a CC="$(CC)" CFLAGS="$(CFLAGS) $(PKG_CFLAGS) $(CPICFLAGS) $(SOLARIS_FLAG)" AR="$(AR)" RANLIB="$(RANLIB)")) && \
Expand Down
4 changes: 2 additions & 2 deletions src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $(SHLIB): init.o scsr.o
scsr.o: scsr.ts

scsr.ts:
cp -f $(SCS_MODS_DIR)/scs.mk $(SCS_DIR)
cp -f $(SCS_MODS_DIR)/rw.c $(SCS_DIR)/src
cp -f $(SCS_MODS_DIR)/rw.c $(SCS_MODS_DIR)/scs.c $(SCS_DIR)/src
cp -f $(SCS_MODS_DIR)/private.c $(SCS_DIR)/linsys/cpu/direct
cd $(SCS_DIR) && CC="$(CC)" CFLAGS="$(CFLAGS) $(PKG_CFLAGS) $(CPICFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)" $(MAKE) out/libscsdir.a
touch $@
2 changes: 1 addition & 1 deletion src/scs
Submodule scs updated 133 files
11 changes: 5 additions & 6 deletions src/scs_mods/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
## Summary of modifications

These modifications are against scs 3.0 (3aaa93c7aa04c7001df5e51b81f21b126dfa99b3).
These modifications are against [scs@fa32d87](https://github.com/cvxgrp/scs).

1. In `rw.c`, all the `fread` calls were checked for returned `bytes`
to avoid compilation warnings. Routines affected are
`read_scs_cone`, `read_scs_stgs`, `read_amatrix`, `read_scs_data`,
`SCS`.
`SCS`. This was done by adding two macros `FREAD` and `FWRITE` and
globally replacing `fread` with `FREAD` and `fwrite` with
`FWRITE`, except for line 144.

2. In `scs.mk` added a solaris check to ensure it compiles using
Oracle developer studio or GNU tools. This is for CRAN.


2. Remove all SOLARIS patches as the platform is no longer supported.
Loading

0 comments on commit da152c4

Please sign in to comment.