(scs) verbose option does not work under standard R
reumle opened this issue · comments
reumle commented
But does work, in some sense, under Rstudio.
- the code
library("scs")
library("CVXR")
nCol =5
nRow = 50
AA = matrix(rnorm(nRow*nCol),ncol=nCol)
x = Variable( ncol( AA))
y = Variable( nrow( AA))
objective1 = Minimize( sum(y) )
constraints = list( x<=10,x>= -10,
AA %*% x <= y,
AA %*% x >= -y,
sum(x) > 10)
prob1 = Problem( objective1, constraints)
solut2 = psolve( prob1,verbose=TRUE,solver="SCS",max_iters=20000,warm_start=FALSE)
- an R session with it. See how no print output comes, in spite of the computation going through.
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library("scs")
> library("CVXR")
Attaching package: ‘CVXR’
The following object is masked from ‘package:stats’:
power
>
>
> nCol =5
> nRow = 50
>
> AA = matrix(rnorm(nRow*nCol),ncol=nCol)
> x = Variable( ncol( AA))
> y = Variable( nrow( AA))
>
> objective1 = Minimize( sum(y) )
> constraints = list( x<=10,x>= -10,
+ AA %*% x <= y,
+ AA %*% x >= -y,
+ sum(x) > 10)
>
> prob1 = Problem( objective1, constraints)
>
>
> solut2=psolve( prob1,verbose=TRUE,solver="SCS",max_iters=20000,warm_start=FALSE)
> solut2=psolve( prob1,verbose=TRUE,solver="SCS",max_iters=20000,warm_start=FALSE)
> str(solut2)
List of 15
$ status : chr "optimal"
$ value : num 159
$ 3 : num [1:50, 1] 6.44 4.42 1.28 7.22 2.57 ...
$ 2 : num [1:5, 1] 1.38 1.82 2.06 2.52 2.21
$ 5 : num [1:5, 1] 0 0 0 0 0
$ 7 : num [1:5, 1] 0 0 0 0 0
$ 9 : num [1:50, 1] 0 1 1 0 1 ...
$ 11 : num [1:50, 1] 1 0 0 1 0 ...
$ 13 : num 15.9
$ solver : chr "SCS"
$ solve_time : num 0.00681
$ setup_time : num 0.000145
$ num_iters : int 160
$ getValue :function (objet)
$ getDualValue:function (objet)
>
- session info
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252 LC_NUMERIC=C LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] CVXR_0.99-7 scs_1.3-2
loaded via a namespace (and not attached):
[1] bit_1.1-14 compiler_3.6.1 R6_2.4.1 Matrix_1.2-17 gmp_0.5-13.5 Rcpp_1.0.3 bit64_0.9-7 R.methodsS3_1.7.1 grid_3.6.1 R.utils_2.9.0 ECOSolveR_0.5.3
[12] Rmpfr_0.7-2 R.oo_1.23.0 lattice_0.20-38
>
- Rstudio Session, same code from within a notebook, shows the little trick to make it work: I need to call the solver three times, which then flushes the print buffer (my guess), and I do get all three printouts (not sure how practical that is with long computes…)
- the buffer flush is also not complete...see at the very last lines.
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
>
>
> library("scs")
> library("CVXR")
Attaching package: ‘CVXR’
The following object is masked from ‘package:stats’:
power
>
>
> nCol =5
> nRow = 50
>
> AA = matrix(rnorm(nRow*nCol),ncol=nCol)
> x = Variable( ncol( AA))
> y = Variable( nrow( AA))
>
> objective1 = Minimize( sum(y) )
> constraints = list( x<=10,x>= -10,
+ AA %*% x <= y,
+ AA %*% x >= -y,
+ sum(x) > 10)
>
> prob1 = Problem( objective1, constraints)
>
>
> solut2 = psolve( prob1,verbose=TRUE,solver="SCS",max_iters=20000,warm_start=FALSE)
>
> solut2 = psolve( prob1,verbose=TRUE,solver="SCS",max_iters=20000,warm_start=FALSE)
>
> solut2 = psolve( prob1,verbose=TRUE,solver="SCS",max_iters=20000,warm_start=FALSE)
----------------------------------------------------------------------------
SCS v2.1.1 - Splitting Conic Solver
(c) Brendan O'Donoghue, Stanford University, 2012
----------------------------------------------------------------------------
Lin-sys: sparse-direct, nnz in A = 615
eps = 1.00e-005, alpha = 1.50, max_iters = 20000, normalize = 1, scale = 1.00
acceleration_lookback = 10, rho_x = 1.00e-003
Variables n = 55, constraints m = 111
Cones: linear vars: 111
Setup time: 2.10e-004s
----------------------------------------------------------------------------
Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)
----------------------------------------------------------------------------
0|6.18e+019 4.64e+019 1.00e+000 -6.10e+021 1.79e+021 1.35e+022 2.53e-005
100|3.83e-004 9.81e-004 9.35e-005 1.59e+002 1.59e+002 1.01e-014 4.39e-003
180|5.26e-007 2.18e-006 1.88e-007 1.59e+002 1.59e+002 9.29e-015 7.85e-003
----------------------------------------------------------------------------
Status: Solved
Timing: Solve time: 7.85e-003s
Lin-sys: nnz in L factor: 849, avg solve time: 1.55e-006s
Cones: avg projection time: 9.50e-008s
Acceleration: avg step time: 3.97e-005s
----------------------------------------------------------------------------
Error metrics:
dist(s, K) = 1.9277e-015, dist(y, K*) = 0.0000e+000, s'y/|s||y| = 4.3360e-017
primal res: |Ax + s - b|_2 / (1 + |b|_2) = 5.2574e-007
dual res: |A'y + c|_2 / (1 + |c|_2) = 2.1761e-006
rel gap: |c'x + b'y| / (1 + |c'x| + |b'y|) = 1.8843e-007
----------------------------------------------------------------------------
c'x = 158.9533, -b'y = 158.9534
============================================================================
----------------------------------------------------------------------------
SCS v2.1.1 - Splitting Conic Solver
(c) Brendan O'Donoghue, Stanford University, 2012
----------------------------------------------------------------------------
Lin-sys: sparse-direct, nnz in A = 615
eps = 1.00e-005, alpha = 1.50, max_iters = 20000, normalize = 1, scale = 1.00
acceleration_lookback = 10, rho_x = 1.00e-003
Variables n = 55, constraints m = 111
Cones: linear vars: 111
Setup time: 1.32e-004s
----------------------------------------------------------------------------
Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)
----------------------------------------------------------------------------
0|6.18e+019 4.64e+019 1.00e+000 -6.10e+021 1.79e+021 1.35e+022 1.95e-005
100|3.83e-004 9.81e-004 9.35e-005 1.59e+002 1.59e+002 1.01e-014 5.17e-003
180|5.26e-007 2.18e-006 1.88e-007 1.59e+002 1.59e+002 9.29e-015 8.54e-003
----------------------------------------------------------------------------
Status: Solved
Timing: Solve time: 8.55e-003s
Lin-sys: nnz in L factor: 849, avg solve time: 1.78e-006s
Cones: avg projection time: 1.24e-007s
Acceleration: avg step time: 4.30e-005s
----------------------------------------------------------------------------
Error metrics:
dist(s, K) = 1.9277e-015, dist(y, K*) = 0.0000e+000, s'y/|s||y| = 4.3360e-017
primal res: |Ax + s - b|_2 / (1 + |b|_2) = 5.2574e-007
dual res: |A'y + c|_2 / (1 + |c|_2) = 2.1761e-006
rel gap: |c'x + b'y| / (1 + |c'x| + |b'y|) = 1.8843e-007
----------------------------------------------------------------------------
c'x = 158.9533, -b'y = 158.9534
============================================================================
----------------------------------------------------------------------------
SCS v2.1.1 - Splitting Conic Solver
(c) Brendan O'Donoghue, Stanford University, 2012
----------------------------------------------------------------------------
Lin-sys: sparse-direct, nnz in A = 615
eps = 1.00e-005, alpha = 1.50, max_iters = 20000, normalize = 1, scale = 1.00
acceleration_lookback = 10, rho_x = 1.00e-003
Variables n = 55, constraints m = 111
Cones: linear vars: 111
Setup time: 1.21e-004s
----------------------------------------------------------------------------
Iter | pri res | dua res | rel gap | pri obj>
>
>
Last but not least, Thank You for these great packages!
Balasubramanian Narasimhan commented
Unable to reproduce.
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> > if (identical(getOption('pager'), file.path(R.home('bin'), 'pager'))) options(pager='console') # rather take the ESS one
> options(STERM='iESS', str.dendrogram.last="'", editor='emacsclient', show.error.locations=TRUE)
> library(CVXR)
Registered S3 method overwritten by 'R.oo':
method from
throw.default R.methodsS3
Attaching package: 'CVXR'
The following object is masked from 'package:stats':
power
> nCol =5
> nRow = 50
> AA = matrix(rnorm(nRow*nCol),ncol=nCol)
> x = Variable( ncol( AA))
> y = Variable( nrow( AA))
> objective1 = Minimize( sum(y) )
> constraints = list( x<=10,x>= -10,
+ AA %*% x <= y,
+ AA %*% x >= -y,
+ sum(x) > 10)
> prob1 = Problem( objective1, constraints)
> solut2=psolve( prob1,verbose=TRUE,solver="SCS",max_iters=20000,warm_start=FALSE)
----------------------------------------------------------------------------
SCS v2.1.1 - Splitting Conic Solver
(c) Brendan O'Donoghue, Stanford University, 2012
----------------------------------------------------------------------------
Lin-sys: sparse-direct, nnz in A = 615
eps = 1.00e-005, alpha = 1.50, max_iters = 20000, normalize = 1, scale = 1.00
acceleration_lookback = 10, rho_x = 1.00e-003
Variables n = 55, constraints m = 111
Cones: linear vars: 111
Setup time: 7.57e-004s
----------------------------------------------------------------------------
Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)
----------------------------------------------------------------------------
0|6.39e+019 4.69e+019 1.00e+000 -6.49e+021 1.95e+021 1.44e+022 3.63e-004
100|1.62e-003 4.40e-003 7.56e-004 1.44e+002 1.44e+002 1.72e-014 5.54e-003
180|2.32e-006 7.63e-006 8.86e-007 1.44e+002 1.44e+002 8.48e-015 9.70e-003
----------------------------------------------------------------------------
Status: Solved
Timing: Solve time: 9.75e-003s
Lin-sys: nnz in L factor: 849, avg solve time: 1.65e-006s
Cones: avg projection time: 1.24e-007s
Acceleration: avg step time: 4.61e-005s
----------------------------------------------------------------------------
Error metrics:
dist(s, K) = 1.0228e-015, dist(y, K*) = 0.0000e+000, s'y/|s||y| = 2.3077e-017
primal res: |Ax + s - b|_2 / (1 + |b|_2) = 2.3223e-006
dual res: |A'y + c|_2 / (1 + |c|_2) = 7.6325e-006
rel gap: |c'x + b'y| / (1 + |c'x| + |b'y|) = 8.8633e-007
----------------------------------------------------------------------------
c'x = 143.8009, -b'y = 143.8006
============================================================================
> solut2=psolve( prob1,verbose=TRUE,solver="SCS",max_iters=20000,warm_start=FALSE)
----------------------------------------------------------------------------
SCS v2.1.1 - Splitting Conic Solver
(c) Brendan O'Donoghue, Stanford University, 2012
----------------------------------------------------------------------------
Lin-sys: sparse-direct, nnz in A = 615
eps = 1.00e-005, alpha = 1.50, max_iters = 20000, normalize = 1, scale = 1.00
acceleration_lookback = 10, rho_x = 1.00e-003
Variables n = 55, constraints m = 111
Cones: linear vars: 111
Setup time: 8.28e-004s
----------------------------------------------------------------------------
Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)
----------------------------------------------------------------------------
0|6.39e+019 4.69e+019 1.00e+000 -6.49e+021 1.95e+021 1.44e+022 3.72e-004
100|1.62e-003 4.40e-003 7.56e-004 1.44e+002 1.44e+002 1.72e-014 6.31e-003
180|2.32e-006 7.63e-006 8.86e-007 1.44e+002 1.44e+002 8.48e-015 1.20e-002
----------------------------------------------------------------------------
Status: Solved
Timing: Solve time: 1.20e-002s
Lin-sys: nnz in L factor: 849, avg solve time: 2.34e-006s
Cones: avg projection time: 1.53e-007s
Acceleration: avg step time: 5.72e-005s
----------------------------------------------------------------------------
Error metrics:
dist(s, K) = 1.0228e-015, dist(y, K*) = 0.0000e+000, s'y/|s||y| = 2.3077e-017
primal res: |Ax + s - b|_2 / (1 + |b|_2) = 2.3223e-006
dual res: |A'y + c|_2 / (1 + |c|_2) = 7.6325e-006
rel gap: |c'x + b'y| / (1 + |c'x| + |b'y|) = 8.8633e-007
----------------------------------------------------------------------------
c'x = 143.8009, -b'y = 143.8006
============================================================================
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] CVXR_0.99-6
loaded via a namespace (and not attached):
[1] bit_1.1-14 compiler_3.6.1 R6_2.4.0 Matrix_1.2-17
[5] gmp_0.5-13.5 Rcpp_1.0.1 bit64_0.9-7 R.methodsS3_1.7.1
[9] grid_3.6.1 scs_1.3-2 R.utils_2.8.0 ECOSolveR_0.5.3
[13] Rmpfr_0.7-2 R.oo_1.22.0 lattice_0.20-38
> q()
Process R finished at Sun Dec 15 22:09:28 2019