osqp / osqp-r Goto Github PK
View Code? Open in Web Editor NEWR interface for OSQP
Home Page: https://osqp.org/
License: Apache License 2.0
R interface for OSQP
Home Page: https://osqp.org/
License: Apache License 2.0
My R package imports package osqp, I got an E-Mail from Prof Brian Ripley that your package will be archived due to the following reason:
``We have asked for an update fixing the check problems shown at
https://cran.r-project.org/web/checks/check_results_osqp.html
with no update from the maintainer thus far.''
Are you aware of this (since university e-mail adresses can change)?
If this is not on purpose please get in contact with [email protected] .
I will write back that I created an issue here.
Hi Gentlemen,
I notice that OSQP does not always return the same result eventhough the parameters are the same (see hereafter a test I ran on my PC):
load(file = "C:/temp/data.RData")
tries <- data.frame()
for(i in 1:200)
{
quadraticProgram <- osqp::osqp(P = osqp.P, q = osqp.q, A = osqp.A, l = osqp.l, u = osqp.u, pars = osqp::osqpSettings(eps_abs = 0.000001, eps_rel = 0.000001, verbose = FALSE))
result_RstudioDesktop <- quadraticProgram$Solve()
tries <- rbind(tries, data.frame(try <- i, iter <- result_RstudioDesktop$info$iter, pri_res <- result_RstudioDesktop$info$pri_res, dua_res <- result_RstudioDesktop$info$dua_res))
}
most of the time the solver returns the same result after 950 iterations but few times it ended after 875 or 850 iterations with another result (not far from the other one).
Reading the documentation of the solver, I can't find what is the default starting point of the algorithm (x0, y0, and z0). I wonder if the difference comes from a different starting point or if it comes from machine precision at a key point of the algorithm (test for stopping conditions or checking for a change on step size parameters).
Can you confirm that OSQP should always return the same result when called with the same parameter (cold start)? Can you help me finding out why I observed this unwilled phenomenon?
Kind regards,
Philippe Carpentier
I would like to use OSQP in a C file that is meant to be wrapped in R and Python (and uploaded to CRAN and PyPI), and I’m wondering what would be the best way of accomplishing this using the OSQP packages in CRAN and PyPI as dependencies.
My first thought was to include all header files from OSQP in the package, generate osqp_configure.h
and qdldl_types.h
, and link to the shared object that the CRAN install generates, but the demo example from https://osqp.org/docs/examples/demo.html#c will segfault if I try that.
I realize that for Python it’s possible to directly include the binaries in a wheel, but I think this is not possible for packages that go to CRAN.
Any suggestions on how to create an R package with C code that links to OSQP taking only the CRAN package as dependency? I know it’s possible to create C++ code with Rcpp that would call the R functions (same for Cython in Python), but I’m wondering if there’s a better way.
Hi!
I'm unable to set the time_limit
parameter:
> osqp::osqpSettings(time_limit = 10)
Error in osqp::osqpSettings(time_limit = 10) :
unused argument (time_limit = 10)
I'm using the most up-to-date version of the interface
> packageVersion("osqp")
[1] ‘0.6.0.3’
Am I doing something wrong?
Cordially,
R version 4.2.1 (2022-06-23 ucrt) -- "Funny-Looking Kid"
Package osqp version 0.6.0.5
When I run the following infeasible problem, R crashes.
rm(list = ls())
library(osqp)
## example, adapted from OSQP documentation
library(Matrix)
P <- Matrix(c(11., 0.,
0., 0.), 2, 2, sparse = TRUE)
q <- c(3., 4.)
A <- Matrix(c(-1., 0., -1., 2., 3.,
0., -1., -3., 5., 4.)
, 5, 2, sparse = TRUE)
u <- c(0., 0., -15., 100., 80)
l <- u + 1
settings <- osqpSettings(verbose = TRUE)
# Solve with OSQP
res <- solve_osqp(P, q, A, l, u, settings)
res$x
The merging of osqp/osqp#396 in the main OSQP library repo will allow us to move the R-specific printing functions to the R repo, removing the need to include the R headers and code in the main library.
This is also possible to do with the memory allocation functions currently, and hopefully the timing/interrupt functions will move to this as well, so we can then move all R-interface specific code to the interface and remove it from the main library repo - allowing us to then remove the R CMake parts from the main library and only have it here in the interface.
R version: 4.3.1 (2023-06-16)
OSQP version: 0.6.3.2
I noticed that osqp
has problems reaching convergence when the upper limit is considered to be Inf
.
I am not sure what the problem is due to, and it does not always occur. It occurs mostly when the variable x in my problem contains very high values.
I leave an example to reproduce it.
library("osqp")
x <- c(24347.5410, 7743.3586, 4957.3505, 5588.0308, 1445.2660, 3002.4793, 643.5833, 240.3561)
A <- matrix(c(1,-1,-1,-1,-1,-1,-1,-1,
0, 1, 0, 0, 0, 0, 0, 0), 2, byrow = TRUE)
# constraints: Ax => x[1] = x[2] + x[3] + x[4] + x[5] + x[6] + x[7] + x[8]
# x[2] >= 0
W <- diag(c(2280147, 428471, 184644, 472915, 45151, 124546, 25157, 30286))
P <- solve(W)
q <- (-1) * t(P) %*% as.vector(x)
rec1 <- solve_osqp(P, q, A, c(0, rep(0, NROW(A)-1)), c(0, rep(Inf, NROW(A)-1)))
#> -----------------------------------------------------------------
#> OSQP v0.6.3 - Operator Splitting QP Solver
#> (c) Bartolomeo Stellato, Goran Banjac
#> University of Oxford - Stanford University 2021
#> -----------------------------------------------------------------
#> problem: variables n = 8, constraints m = 2
#> nnz(P) + nnz(A) = 17
#> settings: linear system solver = qdldl,
#> eps_abs = 1.0e-03, eps_rel = 1.0e-03,
#> eps_prim_inf = 1.0e-04, eps_dual_inf = 1.0e-04,
#> rho = 1.00e-01 (adaptive),
#> sigma = 1.00e-06, alpha = 1.60, max_iter = 4000
#> check_termination: on (interval 25),
#> scaling: on, scaled_termination: off
#> warm start: on, polish: off, time_limit: off
#>
#> iter objective pri res dua res rho time
#> 1 -1.9594e+02 1.16e-03 2.17e-02 1.00e-01 6.53e-05s
#> 25 -1.0000e+30 9.16e-07 2.01e-02 1.00e-01 1.17e-04s
#>
#> status: dual infeasible
#> number of iterations: 25
#> run time: 1.61e-04s
#> optimal rho estimate: 7.87e-06
rec2 <- solve_osqp(P, q, A, c(0, rep(0, NROW(A)-1)), c(0, rep(9e25, NROW(A)-1)))
#> -----------------------------------------------------------------
#> OSQP v0.6.3 - Operator Splitting QP Solver
#> (c) Bartolomeo Stellato, Goran Banjac
#> University of Oxford - Stanford University 2021
#> -----------------------------------------------------------------
#> problem: variables n = 8, constraints m = 2
#> nnz(P) + nnz(A) = 17
#> settings: linear system solver = qdldl,
#> eps_abs = 1.0e-03, eps_rel = 1.0e-03,
#> eps_prim_inf = 1.0e-04, eps_dual_inf = 1.0e-04,
#> rho = 1.00e-01 (adaptive),
#> sigma = 1.00e-06, alpha = 1.60, max_iter = 4000
#> check_termination: on (interval 25),
#> scaling: on, scaled_termination: off
#> warm start: on, polish: off, time_limit: off
#>
#> iter objective pri res dua res rho time
#> 1 -1.9594e+02 1.16e-03 2.17e-02 1.00e-01 6.67e-05s
#> 50 -3.6796e+02 7.30e-04 1.70e-09 7.87e-06 1.25e-04s
#>
#> status: solved
#> number of iterations: 50
#> optimal objective: -367.9584
#> run time: 1.58e-04s
#> optimal rho estimate: 1.05e-05
I am trying to solve quadratic programming in R with package osqp. However, the result doesn't look right to me. I really appreciate your suggestion.
The code for reproducing the example attached here:(the objective function is the minimization
library(osqp)
library(Matrix)
P <- Matrix(c(1., 0.,0,
0., 1.,0, 0,0,1), 3, 3, sparse = TRUE)
q <- c(0, 1,1)
A <- Matrix(c(1., 1., 0.,
1., 0., 1.,1,0,1), 3, 3, sparse = TRUE)
l <- c(1.2, 0., 0.7)
u <- c(2., 0.8, 0.7)
settings <- osqpSettings(alpha = 1.0,eps_abs = 1.0e-05, eps_rel = 1.0e-05,)
model <- osqp(P, q, A, l, u, settings)
res <- model$Solve()
This is the output of the model, and it shows the optimal value is 0.7
However, if use the optimal solution to plug into the objective function it gives me 1.018556
#this should be the final objective value after solving
0.5*t(res$x)%*%P%*%res$x+t(c(0,1,1))%*%res$x
#the solution
res$x
#0.6261887 0.3500000 0.3500000
More importantly, i think this is not the optimal solution. If I eyeballed the solution, I could find another answer with a smaller objective function with a value of 0.5,0.1,0.6
I am not sure what I did wrong.
Thank you for any advice in advance!
osqp
failed the automatic CRAN checks, which has been some trouble for my package optweight
that depends on it. Is there a timeline for this being fixed so I can keep my package on CRAN, or should I change the dependency to another optimization package (e.g., rosqp
, the old version) until this is fixed?
There is a bug in osqpSettings
in the use match.call
which returns an unevaluated call causing the following to fail:
library(osqp)
max_iter <- 1000
eps <- 1e-5
settings <- osqp::osqpSettings(max_iter = max_iter, eps_abs = eps)
## Results in
Error in as.integer(l) :
cannot coerce type 'symbol' to vector of type 'integer'
Below is a self-contained replacement with the same existing signature that I believe does the job. Happy to make a PR if needed.
osqpSettings = function(rho = 0.1, sigma = 1e-06, max_iter = 4000L, eps_abs = 0.001,
eps_rel = 0.001, eps_prim_inf = 1e-04, eps_dual_inf = 1e-04,
alpha = 1.6, linsys_solver = c(QDLDL_SOLVER=0L),
delta = 1e-06, polish = FALSE, polish_refine_iter = 3L, verbose = TRUE,
scaled_termination = FALSE, check_termination = 25L, warm_start = TRUE,
scaling = 10L, adaptive_rho = 1L, adaptive_rho_interval = 0L,
adaptive_rho_tolerance = 5, adaptive_rho_fraction = 0.4) {
given_args <- as.list(environment())
call_arg_names <- names(match.call()[-1]) # lose the function name at index 1
default_args <- formals() ## this is the default list of arg values
given_args <- given_args[call_arg_names] ## restrict to specified args
for (name in call_arg_names) {
given <- given_args[[name]]
if (length(given) != 1 || is.na(given)) {
given_args[[name]] <- default_args[[name]] ## force default
} else {
storage.mode(given_args[[name]]) <- storage.mode(default_args[[name]])
}
}
given_args
}
Here are some test checks.
> max_iter <- 1000
> eps <- 1e-5
> settings <- osqpSettings(max_iter = max_iter, eps_abs = eps)
> lapply(settings, typeof)
$max_iter
[1] "integer"
$eps_abs
[1] "double"
> settings <- osqpSettings(max_iter = max_iter, eps_abs = eps, verbose = 0, linsys_solver=NA)
> settings
$max_iter
[1] 1000
$eps_abs
[1] 1e-05
$linsys_solver
c(QDLDL_SOLVER = 0L)
$verbose
[1] FALSE
> lapply(settings, typeof)
$max_iter
[1] "integer"
$eps_abs
[1] "double"
$linsys_solver
[1] "language"
$verbose
[1] "logical"
There is a small mistake in the Update-method of the osqp-object : the l and u arguments are swapped ... causing an update of the upper bound to affect the lower bound (and vice versa)
We have in line 128 of osqp.R :
osqpUpdate(private$.work, q, u, l)
which should rather become
osqpUpdate(private$.work, q, l, u)
It seems that the downstream code for osqpUpdate assumes indeed that the lower-bound precedes the upper bound.
I am getting error messages when trying to install the package. Any ideas what the problem is? R sessionInfo() output is also below.
install.packages("osqp")
Installing package into '/usr/local/lib/R/4.0/site-library'
(as 'lib' is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/osqp_0.6.0.3.tar.gz'
Content type 'application/x-gzip' length 975221 bytes (952 KB)
==================================================
downloaded 952 KB
* installing *source* package ‘osqp’ ...
** package ‘osqp’ successfully unpacked and MD5 sums checked
** using staged installation
+++ command -v cmake
++ '[' -x /usr/local/bin/cmake ']'
++ echo '-- Trying to build libosqp.a via cmake ...'
-- Trying to build libosqp.a via cmake ...
++ cd src/osqp_sources
++ mkdir -p build
++ cd build
++ cmake -DR_LANG=TRUE -DCMAKE_INSTALL_PREFIX:PATH=../../ ..
-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- We are on a Darwin system
-- Embedded is OFF
-- Printing is ON
-- Profiling is ON
-- User interrupt is ON
-- Floats are OFF
-- Long integers (64bit) are ON
-- Code coverage is OFF
-- MKL Pardiso: ON
-- We are building the R interface
-- R exec is: /usr/local/bin/R
-- R root dir is: /usr/local/Cellar/r/4.0.1/lib/R
-- R includes are in: /usr/local/include
-- Floats are OFF
-- Long integers (64bit) are ON
-- Configuring done
-- Generating done
-- Build files have been written to: /private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/build
++ cmake --build . --target install
Scanning dependencies of target qdldlobject
[ 2%] Building C object lin_sys/direct/qdldl/qdldl_sources/CMakeFiles/qdldlobject.dir/src/qdldl.c.o
[ 2%] Built target qdldlobject
Scanning dependencies of target linsys_pardiso
[ 5%] Building C object lin_sys/direct/CMakeFiles/linsys_pardiso.dir/pardiso/pardiso_interface.c.o
[ 8%] Building C object lin_sys/direct/CMakeFiles/linsys_pardiso.dir/pardiso/pardiso_loader.c.o
[ 8%] Built target linsys_pardiso
Scanning dependencies of target linsys_qdldl
[ 11%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_1.c.o
[ 13%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_2.c.o
[ 16%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_aat.c.o
[ 19%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_control.c.o
[ 22%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_defaults.c.o
[ 25%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_info.c.o
[ 27%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_order.c.o
[ 30%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_post_tree.c.o
[ 33%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_postorder.c.o
[ 36%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_preprocess.c.o
[ 38%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/amd_valid.c.o
[ 41%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/amd/src/SuiteSparse_config.c.o
[ 44%] Building C object lin_sys/direct/qdldl/CMakeFiles/linsys_qdldl.dir/qdldl_interface.c.o
[ 44%] Built target linsys_qdldl
Scanning dependencies of target osqpstatic
[ 47%] Building C object CMakeFiles/osqpstatic.dir/src/auxil.c.o
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/auxil.c:214:3: warning: implicit declaration of function 'project' is invalid in C99 [-Wimplicit-function-declaration]
project(work, work->z);
^
1 warning generated.
[ 50%] Building C object CMakeFiles/osqpstatic.dir/src/error.c.o
[ 52%] Building C object CMakeFiles/osqpstatic.dir/src/lin_alg.c.o
[ 55%] Building C object CMakeFiles/osqpstatic.dir/src/osqp.c.o
[ 58%] Building C object CMakeFiles/osqpstatic.dir/src/proj.c.o
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:4:14: error: unknown type name 'OSQPWorkspace'
void project(OSQPWorkspace *work, c_float *z) {
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:4:35: error: unknown type name 'c_float'; did you mean 'float'?
void project(OSQPWorkspace *work, c_float *z) {
^~~~~~~
float
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:5:3: error: use of undeclared identifier 'c_int'
c_int i, m;
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:7:3: error: use of undeclared identifier 'm'
m = work->data->m;
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:9:8: error: use of undeclared identifier 'i'
for (i = 0; i < m; i++) {
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:9:15: error: use of undeclared identifier 'i'
for (i = 0; i < m; i++) {
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:9:19: error: use of undeclared identifier 'm'
for (i = 0; i < m; i++) {
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:9:22: error: use of undeclared identifier 'i'
for (i = 0; i < m; i++) {
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:10:7: error: use of undeclared identifier 'i'
z[i] = c_min(c_max(z[i],
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:10:12: warning: implicit declaration of function 'c_min' is invalid in C99 [-Wimplicit-function-declaration]
z[i] = c_min(c_max(z[i],
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:10:18: warning: implicit declaration of function 'c_max' is invalid in C99 [-Wimplicit-function-declaration]
z[i] = c_min(c_max(z[i],
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:10:26: error: use of undeclared identifier 'i'
z[i] = c_min(c_max(z[i],
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:11:38: error: use of undeclared identifier 'i'
work->data->l[i]), // Between lower
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:12:32: error: use of undeclared identifier 'i'
work->data->u[i]); // and upper bounds
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:16:25: error: unknown type name 'OSQPWorkspace'
void project_normalcone(OSQPWorkspace *work, c_float *z, c_float *y) {
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:16:46: error: unknown type name 'c_float'; did you mean 'float'?
void project_normalcone(OSQPWorkspace *work, c_float *z, c_float *y) {
^~~~~~~
float
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:16:58: error: unknown type name 'c_float'; did you mean 'float'?
void project_normalcone(OSQPWorkspace *work, c_float *z, c_float *y) {
^~~~~~~
float
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:17:3: error: use of undeclared identifier 'c_int'
c_int i, m;
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:21:3: error: use of undeclared identifier 'm'
m = work->data->m;
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:23:8: error: use of undeclared identifier 'i'
for (i = 0; i < m; i++) {
^
/private/var/folders/t1/9nfnfvn95f99vzc_r1p5gs1h0000gq/T/RtmpcHq2W5/R.INSTALL8cdf3b51abb4/osqp/src/osqp_sources/src/proj.c:23:15: error: use of undeclared identifier 'i'
for (i = 0; i < m; i++) {
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
make[2]: *** [CMakeFiles/osqpstatic.dir/src/proj.c.o] Error 1
make[1]: *** [CMakeFiles/osqpstatic.dir/all] Error 2
make: *** [all] Error 2
ERROR: configuration failed for package ‘osqp’
* removing ‘/usr/local/lib/R/4.0/site-library/osqp’
sessionInfo()
R version 4.0.1 (2020-06-06)
Platform: x86_64-apple-darwin19.5.0 (64-bit)
Running under: macOS Catalina 10.15.5
Matrix products: default
BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.9/lib/libopenblasp-r0.3.9.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] colorout_1.2-2
loaded via a namespace (and not attached):
[1] gert_0.3 memuse_4.1-0 clisymbols_1.2.0 prompt_1.0.0
[5] digest_0.6.25 crayon_1.3.4 prettycode_1.1.0 sys_3.4
[9] credentials_1.1 rprofile_0.1.3 rlang_0.4.7 remotes_1.1.0
[13] tools_4.0.1 compiler_4.0.1 parallel_4.0.1 askpass_1.1
[17] memoise_1.1.0 openssl_1.4.2
I have 13500 non-negative variables but in the result they are negative?
my code:
library(osqp)
library(Matrix)
P1<- matrix(0,13500+21 ,13500+21 )
diag(P1[1:21,1:21])<-1
P<- Matrix(P1, sparse=TRUE)
df1<-train[1:4500,]
ModeTrain<-df1$MODE
df<-df1[,]
df<-df[,-1]
A<-scale(df)
m2<-data.matrix(A)
dim(m2)
h<-matrix(1, 4500,1)
m2<-cbind(m2,h)
BigKernel<-Matrix::bdiag(replicate(3, m2, simplify = FALSE))
BigKernel<-as.matrix(BigKernel)
Amat<-BigKernel[,]
vec_mode<-ModeTrain
vec_mode<-as.numeric(factor(vec_mode))
library(reshape2)
matr <- matrix(-1, nrow = length(vec_mode), ncol = max(vec_mode))
matr[cbind(seq_along(vec_mode), vec_mode)]<- 1
colnames(matr) <- paste0( seq_len(max(vec_mode)))
Y.long<-melt(matr, id.vars = 1:3)
y<-Y.long[,-1:-2]
Am<-Amat[,]*y
I<- matrix(0,13500 ,13500 )
diag(I) <- 1
A<-cbind(Am,I)
Z<- matrix(0,13500 ,21)
Ep<- matrix(0,13500 ,13500 )
diag(Ep) <- 1
A1<-cbind(Z,Ep)
AA<-rbind(A,A1)
AAS<- Matrix(AA, sparse=TRUE)
w<-matrix(0,21,1)
a<-matrix(10,13500 ,1)
q<- c(w,a)
u<-rep(c(10), times = 2*13500 )
l1<-rep(c(1), times = 13500 )
l2<-rep(c(0), times = 13500 )
l<-c(l1,l2)
settings <- osqpSettings(verbose = TRUE)
res <- solve_osqp(P, q, AAS, l, u, settings)
res$x
Hello,
We we were working on the CVXR package and noticed an inconsistency in a solution output for the osqp solver
Here is a reproducible example for both R and Python
library(osqp)
library(Matrix)
P <- sparseMatrix(i=1, j=1, x = 0)
q <- 1
A <- sparseMatrix(i=c(1,2), j=c(1,1), x = c(-1.0, 1.0))
lA <- c(-Inf, -Inf)
uA <- c(-1., 0.)
solver_opts <- list()
solver_opts$eps_abs <- 1e-5
solver_opts$eps_rel <- 1e-5
solver_opts$max_iter <- 10000
solver_opts$polish <- TRUE
model <- osqp::osqp(P, q, A, lA, uA, solver_opts)
result <- model$Solve()
print(result$x) #It's .5 when it should be infeasible
#Should be infeasible but it reaches max iter instead. Status code -2
print(result$info$status_val)
import scipy.sparse as sp
import numpy as np
import osqp
P = sp.csc_matrix([0])
q = np.array([1.])
A = sp.vstack([-1.0, 1.0]).tocsc()
lA = np.array([-np.inf, -np.inf])
uA = np.array([-1., 0.])
solver_opts = {
"eps_abs" : 1e-5,
"eps_rel" : 1e-5,
"max_iter" : 10000,
"polish": True
}
solver = osqp.OSQP()
solver.setup(P, q, A, lA, uA, verbose=True, **solver_opts)
results = solver.solve()
print(results.x) #None
print(results.info.status_val) #Primal infeasible
Thanks so much!
hi @bnaras!
I'm having an installation issue with the current R package release, which could be fixed by upgrading your osqp submodule to the newest version. Could you do that please?
The current/old version from https://github.com/osqp/osqp/blob/0dd00a578cf1c2691c5c379965d504c75bf6cfad/configure/cmake/FindR.cmake#L10C34-L11C35 is
find_program(R_EXEC NAMES R R.exe)
which causes an issue for my installation, because it does not search the R_HOME first, tdhock/data.table-revdeps#3
The new version in https://github.com/osqp/osqp/blob/master/configure/cmake/FindR.cmake#L11 has
find_program(R_EXEC NAMES R Rdev R.exe HINTS ENV R_HOME /opt/R-devel PATH_SUFFIXES bin)
which fixes my issue because the HINTS tells it to search R_HOME before looking on PATH.
Hi there , How I can find an example to use OSQP in R? which function should I call? what is input order?
I do not want to crosspost, so I would rather provide a summary here and link to the StackOverflow post that lead to this issue.
The goal is to be able to parallelize osqp
, by creating an osqp
object and passing it to several workers that can call methods on that object instance.
Take the following scenario:
(function() {
# Create cluster.
cluster <- parallel::makePSOCKcluster(parallel::detectCores() - 1)
# Stop cluster.
on.exit(parallel::stopCluster(cluster))
# Bare minimum data.
x <- matrix(rnorm(100), 10, 10)
y <- runif(10)
# The 'osqp' object is created in the main process.
model <- osqp::osqp(P = crossprod(x), q = -crossprod(x, y), pars = list(verbose = FALSE))
# Run operation.
result <- parallel::parSapply(cluster, c(1), function(i) {
# Calling the solver on the worker process.
return(model$Solve()$x)
})
# Inspect result.
print(result)
})()
The code above results in an error:
Error in checkForRemoteErrors(val) :
one node produced an error: external pointer is not valid
It appears that environment(model$Solve)
contains a private
environment that contains an externalptr
object .work
:
typeof(model$.__enclos_env__$private$.work)
# "externalptr"
This pointer .work
is created using compiled code, i.e., via an Rcpp
export:
Lines 8 to 23 in c38b1de
It seems that this pointer is managed by compiled code and, as such, cannot be used within the workers. It is fine to call the compiled code and create this pointer from within the workers. What is not fine is to create this pointer in another process (i.e., the main process) and then pass it to the worker processes. This is probably because each worker is created as a separate R process, with its own memory space.
This is very limiting for the cases in which one has no control over the osqp
object creation and is only allowed to call methods on an already provided object. Perhaps it would be an idea to not create .work
using Rccp
or, if that is not possible to provide a deep clone method to somehow copy the data at that pointer.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.