How to use cvxpy with scs on windows 8 ?

736 views
Skip to first unread message

caglar ari

unread,
Aug 19, 2014, 3:18:52 AM8/19/14
to cv...@googlegroups.com
Hi,
I have been trying to build atlas on windows 8.1 64 bit machine using cygwin with no success. I have also tried to link scs with some pre-built atlas blas lapack libraries but scs said that they were incompatible. I want to use scs for some computationally expensive experiments so the amount of time spent is important. I am thinking about using linux through virtual machine for experiments. Do you guys know how slow it would be if I use it through virtual machine ? Do you know any links that explains how to build atlas and lapack on windows 8.1 64 bit ? I used to be able to build atlas and lapack on windows 7 relatively easily using cygwin but so far I couldn't manage to build them on windows 8.1.
Regards,
Caglar

Steven Diamond

unread,
Aug 19, 2014, 8:48:51 PM8/19/14
to cv...@googlegroups.com

Try following this guide:

 

Here is a step-by-step guide to installing cvxpy on a Windows machine. Reply to this thread with error messages, etc. if you have an issue.

 

(1) If you have Python installed already, it's probably a good idea to remove it first. (Sorry!)

(2) Download the latest version of Python(x,y).

(3) Install Python(x,y). When prompted to select optional components, make sure to check cvxopt and MinGW, as shown below.

 

 

 

(4) We need to set the default compiler as mingw32. Open Notepad and type the following, save the file at C:\Python27\Lib\distutils\distutils.cfg. (This is the default location. If you installed Python somewhere else, use the appropriate location.)

 

 

(5) Open Python(x,y) and launch the interactive console (highlighted button in the picture). This will bring up a console.

 

 

(6) From the console, run "pip install ecos" to install ecos.

(7) We need to install BLAS and LAPACK libraries, and make the scs package use them. Go here to download the win32 version of the dll and lib files of both BLAS and LAPACK. Put them under some directory, say C:\blaslapack, as shown below.

 

 

(8) The system needs to know where to find the libraries. Right click on This PC (or My Computer), click Properties, Advanced system settings, then Environment Variables. Under the System variables list, find a variable named Path, and press Edit. Then, at the end of the list, put the address to the directory where you put the library files. All paths must be separated by semicolons.

 

 

(9) Go here and download the scs package as a zip file. Unzip it.

(10) Browse to scs-master directory, and edit line 48 of the file scs.mk to "USE_LAPACK = 1". Without this, scs won't be able to solve SDPs.

 

 

(11) Browse to the src directory, and open the file cones.c. Edit lines 11 and 13 to look like the following.

 

 

(12) We have to change the numpy settings so that it knows where to find the libraries. Open C:\Python27\Lib\site-packages\numpy\distutils\site.cfg and add the following lines to the end of the file:

 

[blas]
library_dirs = C:\blaslapack
blas_libs = blas

[lapack]
library_dirs = C:\blaslapack
lapack_libs = lapack

 

You can remove what's already in there, and replace the file with just the six lines above.

 

 

(13) Go back to the Python(x,y) terminal, and browse to the python directory of scs-master. From there, type "python setup.py build" to build scs. (If this step results in some error, remove the build directory and try again.) After the build is successful, run "python setup.py install" to install.

(14) After scs is installed, run "pip install cvxpy" to install cvxpy.

(15) Reboot your computer so that the path environment variable we set in step (8) takes effect.

(16) cvxpy should work now. You can use the Spyder IDE from the Python(x,y) home window. Click on the Spyder button to launch it. This IDE allows you to code, run, and view the console all in the same window. In order to check if the installation was successful, open a terminal, browse to C:\Python27\Lib\site-packages\cvxpy, and run "nosetests tests". This runs all unit tests and reports any error found.

 

Caglar Ari

unread,
Aug 20, 2014, 6:07:32 AM8/20/14
to cv...@googlegroups.com
Hi Steven,

Thanks for the help. I think the code part of the step 11 is missing. There isn't any code after "11) Browse to the src directory, and open the file cones.c. Edit lines 11 and 13 to look like the following." 

I have been experimenting with something like this yesterday. I got to a point where everything seems ok until cvxpy calls scs. Then scs crashes. I am hoping it can be fixed with the changes in step 11. 
Regards,
Caglar
 

Steven Diamond

unread,
Aug 20, 2014, 1:55:54 PM8/20/14
to cv...@googlegroups.com
You're welcome! The picture after "11) Browse to the src directory, and open the file cones.c. Edit lines 11 and 13 to look like the following." shows how to change the file. You want to change lines 11 and 13 to be the same as in the picture.

Caglar Ari

unread,
Aug 21, 2014, 12:33:23 AM8/21/14
to cv...@googlegroups.com
Hi Steven,

I managed to get scs to work with anaconda (64 bit) on windows 8.1 using a weird hack. 

However when I run "nosetests tests", I got 1 error and 1 failure. 

ERROR: test_log_det, ..., z[ind] = 1.0 TypeError: invalid index arguments
FAIL: Test scalar LP problems...test_non_optimal.py ... test_scalar_lp ... AssertionError. 

Is this expected ?

Hack:
When I tried to use 32-bit lib and dll files, I got some errors in the building processes. They were linking errors due to incompatibility. So I replaced the 32-bit dlls with 64-bit dlls and tried again. Then everything worked fine.

However when I tested scs with a logdet sdp which works fine with cvxopt

import numpy as np
import cvxpy as cp

kD=3
vS=cp.semidefinite(kD)
pS=cp.Parameter(kD,kD)

#obj=cp.norm(vS-pS)
#prob=cp.Problem(cp.Minimize(obj))

obj=-cp.log_det(vS)+cp.trace(vS*pS)
prob=cp.Problem(cp.Minimize(obj))
pS.value=np.identity(kD)
prob.solve(verbose=True,solver=cp.SCS)


I got the following output


----------------------------------------------------------------------------

SCS v1.0.5 - Splitting Conic Solver

(c) Brendan O'Donoghue, Stanford University, 2012

----------------------------------------------------------------------------

Lin-sys: sparse-direct, nnz in A = 225

EPS = 1.00e-003, ALPHA = 1.80, MAX_ITERS = 2500, NORMALIZE = 1, SCALE = 5.00

Variables n = 66, constraints m = 156

Cones: primal zero / dual free vars: 93

sd vars: 54, sd blks: 3

exp vars: 9, dual exp vars: 0

Setup time: 6.21e-004s

----------------------------------------------------------------------------

Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)

----------------------------------------------------------------------------

0|1.15e+001 1.30e+000 1.#Re+000 -1.#Je+000 1.#Je+000 1.#Je+000 6.40e-004

FATAL: syevr failure, info = 2

FAILURE:error in projectCones

---------------------------------------------------------------------------

SolverError Traceback (most recent call last)

<ipython-input-3-deb011a651af> in <module>()

12 prob=cp.Problem(cp.Minimize(obj))

13 pS.value=np.identity(kD)

---> 14 prob.solve(verbose=True,solver=cp.SCS)


C:\Anaconda\lib\site-packages\cvxpy-0.2.10-py2.7.egg\cvxpy\problems\problem.pyc in solve(self, *args, **kwargs)

322 return func(self, *args, **kwargs)

323 else:

--> 324 return self._solve(*args, **kwargs)

325

326 @classmethod


C:\Anaconda\lib\site-packages\cvxpy-0.2.10-py2.7.egg\cvxpy\problems\problem.pyc in _solve(self, solver, ignore_dcp, verbose, **kwargs)

450 elif status == s.SOLVER_ERROR:

451 raise SolverError(

--> 452 "Solver '%s' failed. Try another solver." % solver

453 )

454 # Infeasible or unbounded.


SolverError: Solver 'SCS' failed. Try another solver.







caglar ari

unread,
Aug 21, 2014, 3:39:15 PM8/21/14
to cv...@googlegroups.com
Hi Steven,

I couldn't manage to modify the scs's max_iters parameter using cvxpy. The code I used is below. I have also done some tests with more complicated logdet sdps and although scs throws an error for a simple logdet sdp, it works fine for more complicated ones. Only problem was that the solution I got was very inaccurate probably due to insufficient number of iterations.

import numpy as np
import cvxpy as cp

#Jointly Gaussian Estimation
kD1=2
kD2=2
kD=kD1+kD2
v_m1=cp.Variable(kD1,1,name='m1')
v_m2=cp.Variable(kD2,1,name='m2')

v_S11=cp.Variable(kD1,kD1,name='S11')
v_S12=cp.Variable(kD1,kD2,name='S12')
v_S21=cp.Variable(kD2,kD1,name='S21')
v_S22=cp.Variable(kD2,kD2,name='S22')

v_m=cp.vstack(v_m1,v_m2)

S1=cp.hstack(v_S11,v_S12)
S2=cp.hstack(v_S21,v_S22)
v_S=cp.vstack(S1,S2)

p_mu1=cp.Parameter(kD1,1,name='mu1')
p_mu2=cp.Parameter(kD2,1,name='mu2')
p_mu=cp.vstack(p_mu1,p_mu2)

p_R11=cp.Parameter(kD1,kD1,name='R11')
p_R12=cp.Parameter(kD1,kD2,name='R12')
p_R21=cp.Parameter(kD2,kD1,name='R21')
p_R22=cp.Parameter(kD2,kD2,name='R22')
p_R1=cp.hstack(p_R11,p_R12)
p_R2=cp.hstack(p_R21,p_R22)
p_R=cp.vstack(p_R1,p_R2)

#Use new matrix fractional function directly
mff=cp.matrix_frac(v_m,v_S)

objLogParta=-0.5*cp.log_det(v_S)+0.5*mff+((kD1+kD2)/2.)*np.log(2.*np.pi)
objlina=v_m.T*p_mu-0.5*cp.trace(v_S*p_R)
obja=objLogParta-objlina

proba=cp.Problem(cp.Minimize(obja),[v_S==cp.semidefinite(kD1+kD2)])

mus=np.matrix([[ 11.5246781 ],
[ 95.10309315],
[ 48.23004509],
[ 87.15415752]])

Rs=np.matrix([[ 133.84781055, 1096.28400987, 555.84647973, 1004.39183137],
[ 1096.28400987, 9045.51193752, 4586.67906518, 8288.65859466],
[ 555.84647973, 4586.67906518, 2327.41452827, 4203.40178978],
[ 1004.39183137, 8288.65859466, 4203.40178978, 7596.65383194]])

p_mu1.value=mus[0:kD1]
p_mu2.value=mus[kD1:kD]

p_R11.value=Rs[0:kD1,0:kD1]
p_R12.value=Rs[0:kD1,kD1:kD]
p_R21.value=Rs[kD1:kD,0:kD1]
p_R22.value=Rs[kD1:kD,kD1:kD]

kOptValcvxopt=proba.solve(verbose=True,solver=cp.CVXOPT)

opts={}
opts['max_iters']=10000
kOptValscs=proba.solve(verbose=True,solver=cp.SCS,solver_specific_opts=opts)

#Optimum solution
optS=np.linalg.pinv(Rs-mus*mus.T)
optm=optS*mus

Steven Diamond

unread,
Sep 2, 2014, 6:43:43 AM9/2/14
to cv...@googlegroups.com
I'm pretty sure I responded to this already. I'm posting an answer here so other people can see it.

The new interface for solver specific options is to pass in the arguments directly, like this:

kOptValscs=proba.solve(verbose=True,solver=cp.SCS,max_iters=10000)

There are more details in the cvxpy.org documentation (in the advanced section in the tutorial).
Reply all
Reply to author
Forward
0 new messages