SAGE CPLEX

339 views
Skip to first unread message

yannche

unread,
Feb 9, 2012, 8:38:24 PM2/9/12
to sage-support
Hi Everyone,

I find SAGE absolutely awesome, and I use it on a daily basis.
I am desperately trying to have CPLEX work on SAGE 4.8. I have
installed CPLEX 12.3 on my Mac OS 10.6 (Intel CPU). CPLEX works fine
as a standalone. However,

I followed the installation procedure detailed here
http://www.sagemath.org/doc/thematic_tutorials/linear_programming.html
everything went ok during the installation, I had no error message.

But then, on SAGE, when I type
lp = MixedIntegerLinearProgram(solver="CPLEX")

I get the following errors. Any clue ?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_3.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding:
utf-8 -*-\\n" +
_support_.preparse_worksheet_cell(base64.b64decode("bHAgPSBNaXhlZEludGVnZXJMaW5lYXJQcm9ncmFtKHNvbHZlcj0iQ1BMRVgiKQ=="),globals())
+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>

File "/private/var/folders/4r/km32m_0s09d58glt8bk9bpcr0000gn/T/
tmpJgGWMi/___code___.py", line 2, in <module>
exec compile(u'lp = MixedIntegerLinearProgram(solver="CPLEX")
File "", line 1, in <module>

File "mip.pyx", line 200, in
sage.numerical.mip.MixedIntegerLinearProgram.__init__ (sage/numerical/
mip.c:1360)
File "generic_backend.pyx", line 864, in
sage.numerical.backends.generic_backend.get_solver (sage/numerical/
backends/generic_backend.c:5952)
File "generic_backend.pyx", line 922, in
sage.numerical.backends.generic_backend.get_solver (sage/numerical/
backends/generic_backend.c:5768)
ImportError: No module named cplex_backend

kcrisman

unread,
Feb 9, 2012, 9:48:32 PM2/9/12
to sage-support


On Feb 9, 8:38 pm, yannche <yann....@gmail.com> wrote:
> Hi Everyone,
>
> I find SAGE absolutely awesome, and I use it on a daily basis.
> I am desperately trying to have CPLEX work on SAGE 4.8. I have
> installed CPLEX 12.3 on my Mac OS 10.6 (Intel CPU). CPLEX works fine
> as a standalone. However,
>
> I followed the installation procedure detailed herehttp://www.sagemath.org/doc/thematic_tutorials/linear_programming.html
> everything went ok during the installation, I had no error message.
>

I have a really dumb question, sort of like "did you plug it in"...
but just in case, the last thing is

sage -b

in that tutorial. Did you do that? I assume so, but just checking.

My guess is that Nathann will be on this as soon as it is light in
France :)

yannche

unread,
Feb 10, 2012, 4:03:18 AM2/10/12
to sage-support
Hi kcrisman,

Thanks for answering. Yes, I did "sage -b" which worked perfectly.
I tried the procedure on two different machines (one on Mac OS 10.6
and the other on Mac OS 10.7), but I got the same error message on
both.

regards,
yann

Nathann Cohen

unread,
Feb 10, 2012, 5:52:05 AM2/10/12
to sage-s...@googlegroups.com
Heloooooooooo Yann !!!

Hmmm, like Karl said, what your error tells us is that something went wrong when CPLEX was installed.

Sage detects that you want to install CPLEX by checking that there is a file named "libcplex.a" in SAGE_ROOT/local/lib/ and a file "cplex.h" in SAGE_ROOT/local/include/. It is very important that they be named this way, or Sage will not even try to install it when you type "sage -b" :-)

Now, the error message that could help us in this case is the one that (should be ?) printed when CPLEX is detected and installed. So, to ask Sage to do the job again, could you try the following :

- Go into the directory : SAGE_ROOT/devel/sage/sage/numerical/
- type "touch mip.pyx backends/glpk_backend.pyx backends/cplex_backend.pyx"
- then "sage -b"

Sage should try once more to detect CPLEX and compile it. Could you then send me the output (it may be long) of this "sage -b" command ? Its purpose is to say to Sage to "recompile the files that changed since the last time". Hence, if you run it twice, the result you will obtain the second time will be different from the one you obtained the first time. This is why I ask you to "touch" the files, so that Sage believes they have been modified :-)

I hope we will sort this out ! :-)

Nathann

Nathann Cohen

unread,
Feb 10, 2012, 5:56:46 AM2/10/12
to sage-s...@googlegroups.com
Oh and by the way, I would be very glad to know what you are doing with Sage and with LP ! Just being curious :-)

Nathann

yannche

unread,
Feb 10, 2012, 2:08:43 PM2/10/12
to sage-support
Salut Nathann !

Thanks for your answer.
I "touched" the files as you asked, and here is the result below. The
"sage -b" command went much faster than when I first installed CPLEX.

By the way, I'm using MILP to solve machine learning problems with
some combinatorial aspects. For example, given a dataset, I'm trying
to find a linear separator with small integer weights. I'm comparing
my own algorithms and heuristics with the result of GLPK (for now, but
also CPLEX I hope).. This is for research purposes of course.

regards,
yann


./sage -b
Building Sage on OS X in 64-bit mode
Creating SAGE_LOCAL/lib/sage-64.txt since it does not exist
Detected SAGE64 flag
Building Sage on OS X in 64-bit mode

----------------------------------------------------------
sage: Building and installing modified Sage library files.


Installing c_lib
64 bit mode
scons: `install' is up to date.
Updating Cython code....
Building modified file sage/numerical/mip.pyx.
Executing 1 command (using 1 thread)
python `which cython` --old-style-globals --disable-function-
redefinition --embed-positions --directive
cdivision=True,autotestdict=False,fast_getattr=True -I/Applications/
Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/devel/sage-main -o
sage/numerical/mip.c sage/numerical/mip.pyx
sage/numerical/mip.pyx --> /Applications/Sage-4.8-OSX-64bit-10.6.app/
Contents/Resources/sage/local/lib/python2.6/site-packages//sage/
numerical/mip.pyx
Time to execute 1 command: 1.74332094193 seconds
Finished compiling Cython code (time = 2.51089596748 seconds)
running install
running build
running build_py
copying sage/numerical/__init__.py -> build/lib.macosx-10.7-x86_64-2.6/
sage/numerical
copying sage/numerical/all.py -> build/lib.macosx-10.7-x86_64-2.6/sage/
numerical
copying sage/numerical/knapsack.py -> build/lib.macosx-10.7-x86_64-2.6/
sage/numerical
copying sage/numerical/optimize.py -> build/lib.macosx-10.7-x86_64-2.6/
sage/numerical
copying sage/numerical/test.py -> build/lib.macosx-10.7-x86_64-2.6/
sage/numerical
running build_ext
warning: Replacing library search directory in linker command:
"/Users/buildbot/build/sage/bsd-1/bsd_64_binary/build/sage-4.8/local/
lib" -> "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/
sage/local/lib"

building 'sage.numerical.mip' extension
Executing 1 command (using 1 thread)
gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -O3 -m64 -Wall -Wstrict-
prototypes -I/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/local/include/ -I/Applications/Sage-4.8-
OSX-64bit-10.6.app/Contents/Resources/sage/local/include -I/
Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/
include/csage -I/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/devel/sage/sage/ext -I/Applications/Sage-4.8-
OSX-64bit-10.6.app/Contents/Resources/sage/local/include/python2.6 -c
sage/numerical/mip.c -o build/temp.macosx-10.7-x86_64-2.6/sage/
numerical/mip.o -w
gcc -m64 -L/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/local/lib -bundle -undefined dynamic_lookup build/
temp.macosx-10.7-x86_64-2.6/sage/numerical/mip.o -L/Applications/
Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib -lcsage -
lcsage -lstdc++ -lstdc++ -lntl -o build/lib.macosx-10.7-x86_64-2.6/
sage/numerical/mip.so
Time to execute 1 command: 3.75301504135 seconds
Total time spent compiling C/C++ extensions: 3.82160997391 seconds.
running install_lib
copying build/lib.macosx-10.7-x86_64-2.6/sage/numerical/__init__.py -
> /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/
local/lib/python2.6/site-packages/sage/numerical
copying build/lib.macosx-10.7-x86_64-2.6/sage/numerical/all.py -> /
Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/
lib/python2.6/site-packages/sage/numerical
copying build/lib.macosx-10.7-x86_64-2.6/sage/numerical/knapsack.py -
> /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/
local/lib/python2.6/site-packages/sage/numerical
copying build/lib.macosx-10.7-x86_64-2.6/sage/numerical/mip.so -> /
Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/
lib/python2.6/site-packages/sage/numerical
copying build/lib.macosx-10.7-x86_64-2.6/sage/numerical/optimize.py -
> /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/
local/lib/python2.6/site-packages/sage/numerical
copying build/lib.macosx-10.7-x86_64-2.6/sage/numerical/test.py -> /
Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/
lib/python2.6/site-packages/sage/numerical
byte-compiling /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/local/lib/python2.6/site-packages/sage/numerical/
__init__.py to __init__.pyc
byte-compiling /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/local/lib/python2.6/site-packages/sage/numerical/all.py
to all.pyc
byte-compiling /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/local/lib/python2.6/site-packages/sage/numerical/
knapsack.py to knapsack.pyc
byte-compiling /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/local/lib/python2.6/site-packages/sage/numerical/
optimize.py to optimize.pyc
byte-compiling /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/local/lib/python2.6/site-packages/sage/numerical/
test.py to test.pyc
running install_egg_info
Removing /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/
sage/local/lib/python2.6/site-packages/sage-0.0.0-py2.6.egg-info
Writing /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/
sage/local/lib/python2.6/site-packages/sage-0.0.0-py2.6.egg-info

real 0m7.640s
user 0m6.862s
sys 0m0.746s

Jason Grout

unread,
Feb 10, 2012, 2:12:29 PM2/10/12
to sage-s...@googlegroups.com
On 2/10/12 1:08 PM, yannche wrote:
> Salut Nathann !
>
> Thanks for your answer.
> I "touched" the files as you asked, and here is the result below. The
> "sage -b" command went much faster than when I first installed CPLEX.
>

New versions of CPLEX need one more symbolic link. See
http://trac.sagemath.org/sage_trac/ticket/11958 for the ticket from a
couple of months ago.

I just enabled cplex on a sage install this morning and this is what I did:

ln -s
/opt/ibm/ILOG/CPLEX_Studio_Academic123/cplex/lib/x86-64_sles10_4.1/static_pic/libcplex.a
~/sage/local/lib/libcplex.a
ln -s
/opt/ibm/ILOG/CPLEX_Studio_Academic123/cplex/include/ilcplex/cplex.h
~/sage/local/include/cplex.h
ln -s
/opt/ibm/ILOG/CPLEX_Studio_Academic123/cplex/include/ilcplex/cpxconst.h
~/sage/local/include/cpxconst.h
~/sage/sage -b


Thanks,

Jason

Nathann Cohen

unread,
Feb 10, 2012, 2:57:48 PM2/10/12
to sage-s...@googlegroups.com
Helloooooo !!

> New versions of CPLEX need one more symbolic link.  See
> http://trac.sagemath.org/sage_trac/ticket/11958 for the ticket from a couple
> of months ago.

Arggg !! I had totally forgotten this ticket !
I just updated the patch :-)

Yann, could you add this link Jason mentionned, then touch all the
files again and run "sage -b" ? :-)

I find it weird that your log says nothing about the missing .h, but
well.... It's worth a try anyway !

Nathann

yannche

unread,
Feb 10, 2012, 4:35:52 PM2/10/12
to sage-support
Hello,

Unfortunately, I had already made the symbolic link to cpxconst.h
before requesting for help on this forum (I did found this ticket you
mentioned by googling).... So the bug comes from elsewhere... I'm a
bit desperate :-(


Yann

On 10 fév, 20:57, Nathann Cohen <nathann.co...@gmail.com> wrote:
> Helloooooo !!
>
> > New versions of CPLEX need one more symbolic link.  See
> >http://trac.sagemath.org/sage_trac/ticket/11958for the ticket from a couple

Nathann Cohen

unread,
Feb 10, 2012, 6:34:08 PM2/10/12
to sage-s...@googlegroups.com
Unfortunately, I had already made the symbolic link to cpxconst.h
before requesting for help on this forum (I did found this ticket you
mentioned by googling).... So the bug comes from elsewhere... I'm a
bit desperate :-(

Hello !!!

To be honest I have no idea what is going on. It looks like something is missing from the log message you sent us -- the "touch" command I gave you should also have triggered a recompilation of the GLPK backend but nothing appears about that.

Two other checks :

Can you make sure the files you linked in local/include and local/lib are named as they should ?
Can you also make sure that you are using a version of CPLEX corresponding to your architecture (64bits) and that you can start CPLEX as a standalone solver (with its executable, outside of Sage) without any problem ? 

Nathann

yannche

unread,
Feb 10, 2012, 7:25:07 PM2/10/12
to sage-support
Hi Nathan,

Yes, I checked local/include and local/lib. CPLEX runs fine also as a
64 bit standalone.
I recompiled everything with ./sage -ba, and now
MixedIntegerLinearProgram(solver="CPLEX") triggers a new error
message !!!!
I put the log below:
-----

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_3.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding:
utf-8 -*-\\n" +
_support_.preparse_worksheet_cell(base64.b64decode("bHAgPSBNaXhlZEludGVnZXJMaW5lYXJQcm9ncmFtKHNvbHZlcj0iQ1BMRVgiKQ=="),globals())
+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>


File "/private/var/folders/4r/km32m_0s09d58glt8bk9bpcr0000gn/T/
tmp28dJQ6/___code___.py", line 2, in <module>
exec compile(u'lp = MixedIntegerLinearProgram(solver="CPLEX")
File "", line 1, in <module>

File "mip.pyx", line 200, in
sage.numerical.mip.MixedIntegerLinearProgram.__init__ (sage/numerical/
mip.c:1360)
File "generic_backend.pyx", line 864, in
sage.numerical.backends.generic_backend.get_solver (sage/numerical/
backends/generic_backend.c:5952)
File "generic_backend.pyx", line 922, in
sage.numerical.backends.generic_backend.get_solver (sage/numerical/
backends/generic_backend.c:5768)
ImportError: dlopen(/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/local/lib/python2.6/site-packages/sage/numerical/
backends/cplex_backend.so, 2): Symbol not found: _kIOMasterPortDefault
Referenced from: /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/
Resources/sage/local/lib/python2.6/site-packages/sage/numerical/
backends/cplex_backend.so
Expected in: flat namespace
in /Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/
local/lib/python2.6/site-packages/sage/numerical/backends/
cplex_backend.so

Nathann Cohen

unread,
Feb 14, 2012, 2:54:22 PM2/14/12
to sage-s...@googlegroups.com
> Yes, I checked local/include and local/lib. CPLEX runs fine also as a
> 64 bit standalone.
> I recompiled everything with ./sage -ba, and now
> MixedIntegerLinearProgram(solver="CPLEX") triggers a new error
> message !!!!
> I put the log below:

Hmmm... Well, I am sorry but I really have no idea what is creating
this bug, and as I can not reproduce it on my computer it looks like I
cannot be of any help ^^;

Nathann

Dima Pasechnik

unread,
Feb 16, 2012, 12:55:10 PM2/16/12
to sage-s...@googlegroups.com
In gmane.comp.mathematics.sage.support, you wrote:
> Hi Nathan,
>
> Yes, I checked local/include and local/lib. CPLEX runs fine also as a
> 64 bit standalone.
> I recompiled everything with ./sage -ba, and now
> MixedIntegerLinearProgram(solver="CPLEX") triggers a new error
> message !!!!

it might be a good test for compatibility if you
fire up sage's python (i.e. start "sage -sh"
and run python within this shell))
and test CPLEX's own Python interface.
(you'd need to run python setup.py at an appropriate place to
install the CPLEX's python interface)

Please report here on how this went.

Thanks,
Dmitrii

Xuân Nam Nguyễn

unread,
Apr 18, 2014, 5:29:35 AM4/18/14
to sage-s...@googlegroups.com
Hello,


I got the same error and try to find the why.

What I have done:
Install CPLEX and test it works (version 12.6)
Install  SAGE and test it works
Build  CPLEX python interface using SAGE Python
Make symbolic links for libcplex.a, cplex.h and cpxconst.a

ln -s ./CPLEX_Studio126/cplex/lib/x86-64_linux/static_pic/libcplex.a  /home/xnnguyen/SAGE/sage-6.1.1-x86_64-Linux/local/lib/libcplex.a
ln -s  ./CPLEX_Studio126/cplex/include/ilcplex/cplex.h /home/xnnguyen/SAGE/sage-6.1.1-x86_64-Linux/local/include/cplex.h
ln -s ./CPLEX_Studio126/cplex/include/ilcplex/cpxconst.h /home/xnnguyen/SAGE/sage-6.1.1-x86_64-Linux/local/include/cpxconst.h


Rebuild

touch ~/SAGE/sage-6.1.1-x86_64-Linux/src/sage/numerical/mip.pyx ~/SAGE/sage-6.1.1-x86_64-Linux/src/sage/numerical/backends/glpk_backend.pyx ~/SAGE/sage-6.1.1-x86_64-Linux/src/sage/numerical/backends/cplex_backend.pyx
sage -b (i also tried sage -ba)

However, I still got this error:

Traceback (most recent call last):
  File "officer.py", line 129, in <module>
    p = MixedIntegerLinearProgram(solver="CPLEX", maximization=True)
  File "mip.pyx", line 328, in sage.numerical.mip.MixedIntegerLinearProgram.__init__ (sage/numerical/mip.c:1774)
  File "generic_backend.pyx", line 956, in sage.numerical.backends.generic_backend.get_solver (sage/numerical/backends/generic_backend.c:7614)
  File "generic_backend.pyx", line 1019, in sage.numerical.backends.generic_backend.get_solver (sage/numerical/backends/generic_backend.c:7365)

ImportError: No module named cplex_backend

Do you have any suggestions ?

Thanks.

NGUYEN Xuan Nam

leif

unread,
Apr 18, 2014, 8:07:25 AM4/18/14
to sage-s...@googlegroups.com
From
https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014540277
:

"You need to link the frameworks CoreFoundation and IOKit for the
academic version of the product since the license enforcement tools
depend on them. The relevant linker command line arguments are
"-framework CoreFoundation -framework IOKit"."


-leif

--
() The ASCII Ribbon Campaign
/\ Help Cure HTML E-Mail

Nathann Cohen

unread,
Apr 22, 2014, 4:31:24 AM4/22/14
to sage-s...@googlegroups.com
Hellooooooooooooo !!!

Do you have any suggestions ?


Could you please give us the output of sage -b right after you run this "touch" command ? It looks like it the module is not compiled properly.

Nathann 

Dima Pasechnik

unread,
Apr 22, 2014, 5:02:32 AM4/22/14
to sage-s...@googlegroups.com
On 2012-02-10, yannche <yann...@gmail.com> wrote:
> Hi Everyone,
>
> I find SAGE absolutely awesome, and I use it on a daily basis.
> I am desperately trying to have CPLEX work on SAGE 4.8. I have
> installed CPLEX 12.3 on my Mac OS 10.6 (Intel CPU). CPLEX works fine
> as a standalone. However,

why on Sage 4.8?! Can't you use a newer version?

Reply all
Reply to author
Forward
0 new messages