Skip to content

Commit

Permalink
README.md: Remove instructions for patching into Sage < 9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jul 2, 2024
1 parent 5ffdb07 commit 7d34cfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 79 deletions.
72 changes: 9 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ from which it would be built as an "optional extension" if the proprietary CPLEX

Because of the proprietary nature of the CPLEX software, `CPLEXBackend` is not available in any binary distributions of SageMath.

The present standalone Python package `sage-numerical-backends-cplex` has been created from the SageMath sources, version 9.0.beta10; the in-tree version of `CPLEXBackend` has been removed in Sage ticket https://trac.sagemath.org/ticket/28175.
The present standalone Python package `sage-numerical-backends-cplex` has been created from the SageMath sources, version 9.0.beta10; the in-tree version of `CPLEXBackend` has been removed in Sage ticket https://trac.sagemath.org/ticket/28175. SageMath 9.1 and later makes the package available as an optional Sage package (SPKG).

The current version of this package can also be installed on top of various Sage installations using pip.
(Your installation of Sage must be based on Python 3; if your SageMath is version 9.2 or newer, it is.)

The package can be installed on top of various Sage installations using pip, including older versions of Sage such as 8.1 (as shipped by Ubuntu bionic 18.04LTS). SageMath 9.1 and later makes the package available as an optional Sage package (SPKG).

## Installation of CPLEX

Expand All @@ -33,7 +35,7 @@ Now verify that the CPLEX binary that you will find in the subdirectory ``cplex/

(Alternatively, set compiler/linker flags (or use symbolic links) so that `cplex.h` and `libcplex.so` can be found.)

## Installation of this package in SageMath 9.1 or later
## Installation of the version of this package shipped by SageMath 9.1 or later

This package is prepared as an optional Sage package (SPKG) in SageMath 9.1 or later.
To install it, use
Expand All @@ -43,77 +45,22 @@ To install it, use
After a successful installation, Sage will automatically make this new backend
the default MIP solver.

## Installation of this package in older versions of SageMath
## Installation of the current version of this package in an existing installation of SageMath

Install this package from PyPI using

$ sage -python -m pip install sage-numerical-backends-cplex
$ sage -pip install sage-numerical-backends-cplex

or from a checked out source tree using

$ sage -python -m pip install .
$ sage -pip install .

or from GitHub using

$ sage -python -m pip install git+https://github.com/sagemath/sage-numerical-backends-cplex
$ sage -pip install git+https://github.com/sagemath/sage-numerical-backends-cplex

(See [`build.yml` in the related package sage-numerical-backends-coin package](https://github.com/sagemath/sage-numerical-backends-coin/blob/master/.github/workflows/build.yml) for details about package prerequisites on various systems.)

### Using this package in older versions of SageMath

To obtain a solver (backend) instance:

sage: from sage_numerical_backends_cplex.cplex_backend import CPLEXBackend
sage: CPLEXBackend()
<sage_numerical_backends_cplex.cplex_backend.CPLEXBackend object at 0x7fb72c2c7528>

Equivalently:

sage: from sage_numerical_backends_cplex.cplex_backend import CPLEXBackend
sage: from sage.numerical.backends.generic_backend import get_solver
sage: get_solver(solver=CPLEXBackend)
<sage_numerical_backends_cplex.cplex_backend.CPLEXBackend object at 0x7fe21ffbe2b8>

To use this solver (backend) with [`MixedIntegerLinearProgram`](http://doc.sagemath.org/html/en/reference/numerical/sage/numerical/mip.html):

sage: from sage_numerical_backends_cplex.cplex_backend import CPLEXBackend
sage: M = MixedIntegerLinearProgram(solver=CPLEXBackend)
sage: M.get_backend()
<sage_numerical_backends_cplex.cplex_backend.CPLEXBackend object at 0x7fb72c2c7868>

To make it available as the solver named `'CPLEX'`, we need to make the new module
known as `sage.numerical.backends.cplex_backend` (note dots, not underscores), using
the following commands:

sage: import sage_numerical_backends_cplex.cplex_backend as cplex_backend, sage.numerical.backends as backends, sys
sage: sys.modules['sage.numerical.backends.cplex_backend'] = backends.cplex_backend = cplex_backend

If these commands are executed in a Sage session before any `MixedIntegerLinearProgram` is created, then
the new `'CPLEX'` solver wins over the `'GLPK'` solver in the selection of the default MIP backend.
To select the `'CPLEX'` solver explicitly as the default MIP backend, additionally use the following command.

sage: default_mip_solver('CPLEX')

To make these settings permanent, add the above 2 + 1 commands to your `~/.sage/init.sage` file.
Note that this setting will not affect doctesting (`sage -t`) because this file is ignored in doctesting mode.

### Overriding the default solver in older versions of SageMath by patching the Sage installation

Another method is to patch the module in permanently to the sage installation (at your own risk).
This method will affect doctesting.

$ sage -c 'import os; import sage.numerical.backends as dm; import sage_numerical_backends_cplex.cplex_backend as sm; s = sm.__file__; f = os.path.basename(s); d = os.path.join(dm.__path__[0], f); (os.path.exists(d) or os.path.lexists(d)) and os.remove(d); os.symlink(s, d);'

Or use the script [`patch_into_sage_module.py`](patch_into_sage_module.py) in the source distribution that does the same:

$ sage -c 'load("patch_into_sage_module.py")'
Success: Patched in the module as sage.numerical.backends.cplex_backend

Verify with [`check_get_solver_with_name.py`](check_get_solver_with_name.py) that the patching script has worked:

$ sage -c 'load("check_get_solver_with_name.py")'
Success: get_solver(solver='cplex') gives <sage_numerical_backends_cplex.cplex_backend.CPLEXBackend object at 0x7f8f20218528>

## Running doctests

To run the (limited) testsuite of this package, use:
Expand All @@ -123,4 +70,3 @@ To run the (limited) testsuite of this package, use:
To run the Sage testsuite with the default MIP solver set to the backend provided by this package, use:

$ sage setup.py check_sage_testsuite

3 changes: 0 additions & 3 deletions patch_and_check.sh

This file was deleted.

13 changes: 0 additions & 13 deletions patch_into_sage_module.py

This file was deleted.

0 comments on commit 7d34cfb

Please sign in to comment.