Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cplex backend: allow to set logfile #19037

Closed
dcoudert opened this issue Aug 15, 2015 · 19 comments
Closed

Cplex backend: allow to set logfile #19037

dcoudert opened this issue Aug 15, 2015 · 19 comments

Comments

@dcoudert
Copy link
Contributor

With this patch it is now possible to set a logfile for Cplex. This is useful for instance when you want to remember the logs or when you want to have access to them but don't want to see them on screen.

I don't know how to do the same for other backends, in particular GLPK.

CC: @nathanncohen

Component: linear programming

Author: David Coudert

Branch/Commit: 8efd3d3

Reviewer: Nathann Cohen

Issue created by migration from https://trac.sagemath.org/ticket/19037

@dcoudert
Copy link
Contributor Author

Branch: public/19037

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 15, 2015

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

44ad5fdtrac #19037: allow to set logfile for Cplex backend

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 15, 2015

Commit: 44ad5fd

@dcoudert

This comment has been minimized.

@dcoudert
Copy link
Contributor Author

comment:3

The proposed implementation might certainly be improved.
Also, I'm not sure that the CPXsetlogfile method returns something else than 0, which means successful according the documentation http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.6.2/ilog.odms.cplex.help/refcallablelibrary/cpxapi/setlogfile.html?cp=SSSA5P_12.6.2%2F2-8-1-256. I did some unsuccessful trials...

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Aug 15, 2015

comment:4

The proposed implementation might certainly be improved.

Mostly up to you. The only way I see to see things differently is this: given that this is not a 'solver parameter' in the same sense than others, it could be worth creating an individual function to do that -- as it exposes a specific CPLEX API function.

Either way it must appear in the documentation somewhere.

Also, I'm not sure that the CPXsetlogfile method returns something else than 0, which means successful according the documentation http://www-01.ibm.com/support/knowledgecenter/SSSA5P_12.6.2/ilog.odms.cplex.help/refcallablelibrary/cpxapi/setlogfile.html?cp=SSSA5P_12.6.2%2F2-8-1-256. I did some unsuccessful trials...

They say in the doc that it returns an 'error code' when somethings goes wrong. You should probably call the 'check' function defined in the cplex backend file, just in case. It is done almost everywhere in the file.

Nathann

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 16, 2015

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

e80b2f7trac #19037: improve logfile manipulation
f1da76etrac #19037: improve logfile example
114e14btrac #19037: fix general doctest issue in cplex backend
0e5fb5btrac #19037: avoid deprecation warnings

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 16, 2015

Changed commit from 44ad5fd to 0e5fb5b

@dcoudert
Copy link
Contributor Author

comment:6

Hello,

since LogFile is a solver parameter for Gurobi, I prefer to have similar access method for Cplex.
I have added the parameter to the documentation and I'm now using the check method.

Also, I had to

  • modify all doctests of the cplex_backend.pyx file for the following reason: a call to ./sage -t -l --optional=CPLEX src/sage/numerical/backends/cplex_backend.pyx was reporting 149 doctests failures!
**********************************************************************
File "src/sage/numerical/backends/cplex_backend.pyx", line 78, in sage.numerical.backends.cplex_backend.CPLEXBackend.add_variable
Failed example:
    p = get_solver(solver = "CPLEX")                  # optional - CPLEX
Exception raised:
    Traceback (most recent call last):
      File "/Users/dcoudert/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 496, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 858, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.numerical.backends.cplex_backend.CPLEXBackend.add_variable[0]>", line 1, in <module>
        p = get_solver(solver = "CPLEX")                  # optional - CPLEX
    NameError: name 'get_solver' is not defined
**********************************************************************
File "src/sage/numerical/backends/cplex_backend.pyx", line 79, in sage.numerical.backends.cplex_backend.CPLEXBackend.add_variable
Failed example:
    p.ncols()                                         # optional - CPLEX
Exception raised:
    Traceback (most recent call last):
      File "/Users/dcoudert/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 496, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 858, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.numerical.backends.cplex_backend.CPLEXBackend.add_variable[1]>", line 1, in <module>
        p.ncols()                                         # optional - CPLEX
    NameError: name 'p' is not defined
...
...
...
**********************************************************************
29 items had failures:
   6 of   7 in sage.numerical.backends.cplex_backend.CPLEXBackend.add_col
   7 of   8 in sage.numerical.backends.cplex_backend.CPLEXBackend.add_linear_constraint
   6 of   7 in sage.numerical.backends.cplex_backend.CPLEXBackend.add_linear_constraints
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.add_variables
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.col_bounds
   3 of   4 in sage.numerical.backends.cplex_backend.CPLEXBackend.col_name
   8 of   9 in sage.numerical.backends.cplex_backend.CPLEXBackend.get_objective_value
   8 of   9 in sage.numerical.backends.cplex_backend.CPLEXBackend.get_variable_value
   4 of   5 in sage.numerical.backends.cplex_backend.CPLEXBackend.is_maximization
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.is_variable_binary
   6 of   7 in sage.numerical.backends.cplex_backend.CPLEXBackend.is_variable_continuous
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.is_variable_integer
   4 of   5 in sage.numerical.backends.cplex_backend.CPLEXBackend.ncols
   4 of   5 in sage.numerical.backends.cplex_backend.CPLEXBackend.nrows
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.objective_coefficient
   3 of   4 in sage.numerical.backends.cplex_backend.CPLEXBackend.problem_name
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.row
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.row_bounds
   3 of   4 in sage.numerical.backends.cplex_backend.CPLEXBackend.row_name
   5 of  12 in sage.numerical.backends.cplex_backend.CPLEXBackend.set_objective
   4 of   5 in sage.numerical.backends.cplex_backend.CPLEXBackend.set_sense
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.set_variable_type
   2 of   3 in sage.numerical.backends.cplex_backend.CPLEXBackend.set_verbosity
   6 of   7 in sage.numerical.backends.cplex_backend.CPLEXBackend.solve
  10 of  11 in sage.numerical.backends.cplex_backend.CPLEXBackend.solver_parameter
   5 of  11 in sage.numerical.backends.cplex_backend.CPLEXBackend.variable_lower_bound
   5 of  10 in sage.numerical.backends.cplex_backend.CPLEXBackend.variable_upper_bound
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.write_lp
   5 of   6 in sage.numerical.backends.cplex_backend.CPLEXBackend.write_mps
    [191 tests, 149 failures, 0.11 s]
----------------------------------------------------------------------
sage -t --long src/sage/numerical/backends/cplex_backend.pyx  # 149 doctests failed

Adding # optional - CPLEX to all the lines from sage.numerical.backends.generic_backend import get_solver solve the problem. Don't know why.

  • change some doctests to get rid of deprecation warnings. E.g.,
    doctest:858: DeprecationWarning: The default value of 'nonnegative' will change, to False instead of True. You should add the explicit 'nonnegative=True'.
    See http://trac.sagemath.org/15521 for details.

I have a remaining doctest error for method solve

File "src/sage/numerical/backends/cplex_backend.pyx", line 852, in sage.numerical.backends.cplex_backend.CPLEXBackend.solve
Failed example:
    p.solve()                                       # optional - CPLEX
Expected:
    Traceback (most recent call last):
    ...
    MIPSolverException: ...
Got:
    0

I don't know how to fix the example. I can off course change it to something more understandable. Let me know what you prefer.

David.

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Aug 16, 2015

comment:7

Hello,

since LogFile is a solver parameter for Gurobi, I prefer to have similar access method for Cplex.
I have added the parameter to the documentation and I'm now using the check method.

Okayokay. Could you write it in the doc somewhere? It only appears as examples so far.

Also, I had to

  • modify all doctests of the cplex_backend.pyx file for the following reason: a call to ./sage -t -l --optional=CPLEX src/sage/numerical/backends/cplex_backend.pyx was reporting 149 doctests failures!

That's because you are meant to run optional=sage,cplex.

But people here let things like #18904 to die, so whatever...

  • change some doctests to get rid of deprecation warnings. E.g.,
    doctest:858: DeprecationWarning: The default value of 'nonnegative' will change, to False instead of True. You should add the explicit 'nonnegative=True'.
    See http://trac.sagemath.org/15521 for details.

Okayokay. We should have detected this earlier, but then again, #18904...

I have a remaining doctest error for method solve
I don't know how to fix the example. I can off course change it to something more understandable. Let me know what you prefer.

It's something weird. I played with it a bit, and it looks like you should remove the first 'p.solve'. Afterwards it works. Looks like CPLEX does not like to see a change in the objective function between successive calls to solve.

Nathann

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 16, 2015

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

b22d2d2trac #19037: add documentation and alias for logfile
7cd6559trac #19037: fix and improve doctest of method solve

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 16, 2015

Changed commit from 0e5fb5b to 7cd6559

@dcoudert
Copy link
Contributor Author

comment:9

I tried to address all your comments.
David.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 16, 2015

Changed commit from 7cd6559 to 8efd3d3

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 16, 2015

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

8efd3d3trac #19037: Writing/reading the log file

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Aug 16, 2015

Reviewer: Nathann Cohen

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Aug 16, 2015

comment:11

I tried to address all your comments.

Thank you. I added a commit that reads/write the logfile. If you agree with it, this branch can go.

Nathann

@dcoudert
Copy link
Contributor Author

comment:12

Excellent. I was thinking of adding such a test but did not know how to deal with the print part.
Thank you.

David.

@vbraun
Copy link
Member

vbraun commented Aug 19, 2015

Changed branch from public/19037 to 8efd3d3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants