Opened 4 months ago

Last modified 2 months ago

#27790 needs_review defect

compatibility with cplex 12.9

Reported by: dcoudert Owned by:
Priority: major Milestone: sage-8.9
Component: numerical Keywords:
Cc: Friedrich, Wiemer Merged in:
Authors: David Coudert Reviewers:
Report Upstream: N/A Work issues:
Branch: public/numerical/27790_cplex_logfilename (Commits) Commit: 93ff118d5b71d43b0c0c4fc82f2bd331705070a9
Dependencies: Stopgaps:

Description

Method CPXsetlogfile has been deprecated in cplex 12.8 and removed from cplex 12.9. We must instead use CPXsetlogfilename, introduced in 12.8.

Change History (17)

comment:1 Changed 4 months ago by dcoudert

  • Branch set to public/numerical/27790_cplex_logfilename
  • Commit set to 62a189900d82cb2a35ae369872950b9a01365083
  • Status changed from new to needs_review

This patch works with versions >= 12.8. However, we loose compatibility with versions < 12.8.

To maintain compatibility, we must be able to import CPXsetlogfile only if version < 12.8 and CPXsetlogfilename if version >= 12.8. Then, we can use CPXversionnumber to adjust usage.

I don't know how to do that.


New commits:

62a1899trac #27790: use CPXsetlogfilename

comment:2 follow-up: Changed 3 months ago by vdelecroix

  1. merge failure
  1. A possibility to make it work for both CPLEX versions, you can find out the CPLEX version from the Sage setup.py script and set a Cython constant so that you can use Cython conditional statements.

comment:3 Changed 3 months ago by git

  • Commit changed from 62a189900d82cb2a35ae369872950b9a01365083 to 61e518719f22fe5d1456d1a2883df9405f59c8aa

Branch pushed to git repo; I updated commit sha1. New commits:

61e5187trac #27790: fix merge conflict with 8.8.beta6

comment:4 in reply to: ↑ 2 ; follow-up: Changed 3 months ago by dcoudert

Replying to vdelecroix:

  1. merge failure

fixed

  1. A possibility to make it work for both CPLEX versions, you can find out the CPLEX version from the Sage setup.py script and set a Cython constant so that you can use Cython conditional statements.

Not sure how to do that and where to put the code (setup.py, module_list.py ?).

Somehow, we want to extract line #define CPX_VERSION 12080000 from cpxconst.h, extract the number and use it for conditional compilation.

comment:5 in reply to: ↑ 4 Changed 3 months ago by vdelecroix

Replying to dcoudert:

Replying to vdelecroix:

  1. A possibility to make it work for both CPLEX versions, you can find out the CPLEX version from the Sage setup.py script and set a Cython constant so that you can use Cython conditional statements.

Not sure how to do that and where to put the code (setup.py, module_list.py ?).

It would have been easier with an optional package and a proper spkg-install... I don't know where to put it. These optional Cython modules are not very handy.

Somehow, we want to extract line #define CPX_VERSION 12080000 from cpxconst.h, extract the number and use it for conditional compilation.

I don't think that can be done directly from Cython. Here is a suggestion (similar to what is done in PyNormaliz)

  • run a configure script (or whatever) to obtain the value of CPX_VERSION and write a line "CPX_VERSION=12080000" in a file cplex_config.py
  • in the setup.py script, use the clpex_config.py to define a compile time constant and branch appropriately in the Cython code

If you find an easier way to access the CPX_VERSION macro directly from a .pyx file that would be great!

comment:6 Changed 3 months ago by dcoudert

An idea to make the process transparent to users is to set the version number in module_list.py. I can get the version number like that, but I don't know how to use it with OptionalExtension.

sage: if os.path.exists(SAGE_LOCAL + '/include/cpxconst.h'):
....:     CPX_VERSION = subprocess.check_output(" grep '#define CPX_VERSION ' $SAGE_LOCAL/include/cpxconst.h | grep -o -E '[0-9]+' ", shell=True).strip()
....:     
sage: CPX_VERSION
'12080000'

comment:7 Changed 3 months ago by vdelecroix

You can try the following (that works for normal extensions)

OptionalExtension(...,
   define_macros= [('CPX_VERSION', 12080000)]   # computed value
)

and the in the Cython code (with upper case)

IF CPX_VERSION >= 12080000:
    check( CPXsetlogfilename(self.env, NULL, NULL) )
ELSE:
    check( CPXsetlogfile(self.env, NULL) )

Since both versions of the code only use the self.env parameter you might want to isolate the IF/ELSE statement in a short cdef function.

comment:8 Changed 3 months ago by dcoudert

This is roughly what I already tried: use define_macros, and in cplex_backend.pxd use the macro to conditionally import methods from cplex.h, but I always get

Error compiling Cython file:
------------------------------------------------------------
...
     int CPX_PARAM_SOLNPOOLGAP = 2105
     int CPX_PARAM_SOLNPOOLINTENSITY = 2107
     int CPX_MAX = -1
     int CPX_MIN = 1

IF CPX_VERSION >= 12090000:
  ^
------------------------------------------------------------

sage/numerical/backends/cplex_backend.pxd:217:3: Compile-time name 'CPX_VERSION' not defined

comment:9 Changed 3 months ago by vdelecroix

try compile_time_env instead of define_macros (see cython thread)

comment:10 Changed 3 months ago by git

  • Commit changed from 61e518719f22fe5d1456d1a2883df9405f59c8aa to 72e1ea0439875af0d45840767bd0cdf3b4761242

Branch pushed to git repo; I updated commit sha1. New commits:

72e1ea0trac #27790: try to use compile time parameter

comment:11 Changed 3 months ago by dcoudert

I don't understand how I can use compile_time_env.

I pushed my current trial that is not working as can be seen from the patchbot.

comment:12 Changed 3 months ago by vdelecroix

line 240-241 of src/setup.py the compile_time_env variable is set up (globally). It seems that it erases any specific configuration at an Extension level.

comment:13 Changed 3 months ago by dcoudert

outch... Well, either we are able to find a smart solution, or we could decide to support only cplex >= 12.8 (released Oct 2017). We already dropped support of older versions when the API introduced file cpxconst.h (#11958).

comment:14 Changed 3 months ago by git

  • Commit changed from 72e1ea0439875af0d45840767bd0cdf3b4761242 to 93ff118d5b71d43b0c0c4fc82f2bd331705070a9

Branch pushed to git repo; I updated commit sha1. New commits:

93ff118trac #27790: another trial

comment:15 Changed 3 months ago by dcoudert

still not working :(

comment:16 Changed 2 months ago by asante

  • Cc Friedrich Wiemer added

comment:17 Changed 2 months ago by dcoudert

  • Milestone changed from sage-8.8 to sage-8.9

I'm more and more in favor of dropping support for cplex versions < 12.8. Indeed, we have an easy solution to support versions >= 12.8, but no simple, and more important working, solution for conditional compilation enabling to support < 12.8.

Note: See TracTickets for help on using tickets.