sage-numerical-backends-gurobi


Namesage-numerical-backends-gurobi JSON
Version 9.3.1 PyPI version JSON
download
home_pagehttps://github.com/sagemath/sage-numerical-backends-gurobi
SummaryGurobi backend for Sage MixedIntegerLinearProgram
upload_time2021-05-18 22:26:42
maintainer
docs_urlNone
authorNathann Cohen, Martin Albrecht, Matthias Koeppe, John Perry, David Coudert, Jori Mäntysalo, Jeroen Demeyer, Erik M. Bray, Emil R. Vaughan, and others
requires_python
licenseGPLv2+
keywords milp linear-programming optimization
VCS
bugtrack_url
requirements setuptools wheel Cython cysignals
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sage-numerical-backends-gurobi: Gurobi mixed integer linear programming backend for SageMath

[![PyPI](https://img.shields.io/pypi/v/sage-numerical-backends-gurobi)](https://pypi.org/project/sage-numerical-backends-gurobi/ "PyPI: sage-numerical-backends-gurobi")

`GurobiBackend` has previously been available as part of the [SageMath](http://www.sagemath.org/) source tree,
from which it is built as an "optional extension" if the proprietary Gurobi library and header files have been symlinked into `$SAGE_LOCAL` manually.

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

The present standalone Python package `sage-numerical-backends-gurobi` has been created from the SageMath sources, version 9.0.beta10; the in-tree version of `GurobiBackend` has been removed in [Sage ticket #28175](https://trac.sagemath.org/ticket/28175).  The present 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).

## Installation of Gurobi

Install Gurobi according to the instructions on the website,
which includes obtaining a license key.

- On a Linux system, after unpacking the Gurobi archive in the desired location,
  such as `/opt`, set the environment variable `GUROBI_HOME` to the directory containing the subdirectories `bin`, `lib`, ...:

        $ export GUROBI_HOME=/opt/gurobi900/linux64

  Then adjust your `PATH` (or create symbolic links) so that the interactive Gurobi shell `gurobi.sh` can be found from your `PATH`:

        $ export PATH="$GUROBI_HOME/bin:$PATH"

- On macOS, the Gurobi installer should make the interactive Gurobi shell ``gurobi.sh`` available in `/usr/local/bin` and therefore from your ``PATH``.

Verify this by typing the shell command ``gurobi.sh``::

    $ gurobi.sh
    Python 3.7.4 (default, Aug 27 2019, 11:27:39)
    ...
    Gurobi Interactive Shell (mac64), Version 9.0.0
    Copyright (c) 2019, Gurobi Optimization, LLC
    Type "help()" for help
    gurobi>

If this does not work, adjust your ``PATH`` (or create symbolic links) so
that ``gurobi.sh`` is found.

## Installation of this package

This package finds the Gurobi installation using the `GUROBI_HOME` environment variable.  (On macOS, it suffices to have `gurobi.sh` in your ``PATH``.)
An alternative method of build configuration is to set compiler/linker flags appropriately.

In [SageMath 9.1 and newer](https://wiki.sagemath.org/ReleaseTours/sage-9.1#Easier_installation_of_optional_linear_and_mixed_integer_linear_optimization_backends), this package is available as an optional SPKG and can be installed using

    $ sage -i sage_numerical_backends_gurobi

Alternatively, you can install this package from PyPI using

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

or from a checked out source tree using

    $ sage -python -m pip install .

or from GitHub using

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

(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

To obtain a solver (backend) instance:

    sage: from sage_numerical_backends_gurobi.gurobi_backend import GurobiBackend
    sage: GurobiBackend()
    <sage_numerical_backends_gurobi.gurobi_backend.GurobiBackend object at 0x7fb72c2c7528>

Equivalently:

    sage: from sage_numerical_backends_gurobi.gurobi_backend import GurobiBackend
    sage: from sage.numerical.backends.generic_backend import get_solver
    sage: get_solver(solver=GurobiBackend)
    <sage_numerical_backends_gurobi.gurobi_backend.GurobiBackend 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_gurobi.gurobi_backend import GurobiBackend
    sage: M = MixedIntegerLinearProgram(solver=GurobiBackend)
    sage: M.get_backend()
    <sage_numerical_backends_gurobi.gurobi_backend.GurobiBackend object at 0x7fb72c2c7868>

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

    sage: import sage_numerical_backends_gurobi.gurobi_backend as gurobi_backend, sage.numerical.backends as backends, sys
    sage: sys.modules['sage.numerical.backends.gurobi_backend'] = backends.gurobi_backend = gurobi_backend

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

    sage: default_mip_solver('Gurobi')

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.

## Running doctests

To run the (limited) testsuite of this package, use:

    $ sage setup.py test

If no Gurobi license is available, the testing is skipped without error.

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

If no Gurobi license is available, the testing is skipped without error.

## Running tests with tox

The doctests can also be invoked using `tox`:

    $ tox -e local
    $ tox -e local check_sage_testsuite.py

Testing multiple installed Gurobi versions in parallel (see `tox.ini`):

    $ tox -p auto

## Overriding the default solver 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_gurobi.gurobi_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.gurobi_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='gurobi') gives <sage_numerical_backends_gurobi.gurobi_backend.GurobiBackend object at 0x7f8f20218528>
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sagemath/sage-numerical-backends-gurobi",
    "name": "sage-numerical-backends-gurobi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "milp,linear-programming,optimization",
    "author": "Nathann Cohen, Martin Albrecht, Matthias Koeppe, John Perry, David Coudert, Jori M\u00e4ntysalo, Jeroen Demeyer, Erik M. Bray, Emil R. Vaughan, and others",
    "author_email": "sage-support@googlegroups.com",
    "download_url": "https://files.pythonhosted.org/packages/03/37/966dc91e81af330aa62c7baa426a7798e6964d752ca221c077e3e8c7c47b/sage_numerical_backends_gurobi-9.3.1.tar.gz",
    "platform": "",
    "description": "# sage-numerical-backends-gurobi: Gurobi mixed integer linear programming backend for SageMath\n\n[![PyPI](https://img.shields.io/pypi/v/sage-numerical-backends-gurobi)](https://pypi.org/project/sage-numerical-backends-gurobi/ \"PyPI: sage-numerical-backends-gurobi\")\n\n`GurobiBackend` has previously been available as part of the [SageMath](http://www.sagemath.org/) source tree,\nfrom which it is built as an \"optional extension\" if the proprietary Gurobi library and header files have been symlinked into `$SAGE_LOCAL` manually.\n\nBecause of the proprietary nature of the Gurobi software, `GurobiBackend` is not available in any binary distributions of SageMath.\n\nThe present standalone Python package `sage-numerical-backends-gurobi` has been created from the SageMath sources, version 9.0.beta10; the in-tree version of `GurobiBackend` has been removed in [Sage ticket #28175](https://trac.sagemath.org/ticket/28175).  The present 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).\n\n## Installation of Gurobi\n\nInstall Gurobi according to the instructions on the website,\nwhich includes obtaining a license key.\n\n- On a Linux system, after unpacking the Gurobi archive in the desired location,\n  such as `/opt`, set the environment variable `GUROBI_HOME` to the directory containing the subdirectories `bin`, `lib`, ...:\n\n        $ export GUROBI_HOME=/opt/gurobi900/linux64\n\n  Then adjust your `PATH` (or create symbolic links) so that the interactive Gurobi shell `gurobi.sh` can be found from your `PATH`:\n\n        $ export PATH=\"$GUROBI_HOME/bin:$PATH\"\n\n- On macOS, the Gurobi installer should make the interactive Gurobi shell ``gurobi.sh`` available in `/usr/local/bin` and therefore from your ``PATH``.\n\nVerify this by typing the shell command ``gurobi.sh``::\n\n    $ gurobi.sh\n    Python 3.7.4 (default, Aug 27 2019, 11:27:39)\n    ...\n    Gurobi Interactive Shell (mac64), Version 9.0.0\n    Copyright (c) 2019, Gurobi Optimization, LLC\n    Type \"help()\" for help\n    gurobi>\n\nIf this does not work, adjust your ``PATH`` (or create symbolic links) so\nthat ``gurobi.sh`` is found.\n\n## Installation of this package\n\nThis package finds the Gurobi installation using the `GUROBI_HOME` environment variable.  (On macOS, it suffices to have `gurobi.sh` in your ``PATH``.)\nAn alternative method of build configuration is to set compiler/linker flags appropriately.\n\nIn [SageMath 9.1 and newer](https://wiki.sagemath.org/ReleaseTours/sage-9.1#Easier_installation_of_optional_linear_and_mixed_integer_linear_optimization_backends), this package is available as an optional SPKG and can be installed using\n\n    $ sage -i sage_numerical_backends_gurobi\n\nAlternatively, you can install this package from PyPI using\n\n    $ sage -python -m pip install sage-numerical-backends-gurobi\n\nor from a checked out source tree using\n\n    $ sage -python -m pip install .\n\nor from GitHub using\n\n    $ sage -python -m pip install git+https://github.com/sagemath/sage-numerical-backends-gurobi\n\n(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.)\n\n## Using this package\n\nTo obtain a solver (backend) instance:\n\n    sage: from sage_numerical_backends_gurobi.gurobi_backend import GurobiBackend\n    sage: GurobiBackend()\n    <sage_numerical_backends_gurobi.gurobi_backend.GurobiBackend object at 0x7fb72c2c7528>\n\nEquivalently:\n\n    sage: from sage_numerical_backends_gurobi.gurobi_backend import GurobiBackend\n    sage: from sage.numerical.backends.generic_backend import get_solver\n    sage: get_solver(solver=GurobiBackend)\n    <sage_numerical_backends_gurobi.gurobi_backend.GurobiBackend object at 0x7fe21ffbe2b8>\n\nTo use this solver (backend) with [`MixedIntegerLinearProgram`](http://doc.sagemath.org/html/en/reference/numerical/sage/numerical/mip.html):\n\n    sage: from sage_numerical_backends_gurobi.gurobi_backend import GurobiBackend\n    sage: M = MixedIntegerLinearProgram(solver=GurobiBackend)\n    sage: M.get_backend()\n    <sage_numerical_backends_gurobi.gurobi_backend.GurobiBackend object at 0x7fb72c2c7868>\n\nTo make it available as the solver named `'Gurobi'`, we need to make the new module\nknown as `sage.numerical.backends.gurobi_backend` (note dots, not underscores), using\nthe following commands:\n\n    sage: import sage_numerical_backends_gurobi.gurobi_backend as gurobi_backend, sage.numerical.backends as backends, sys\n    sage: sys.modules['sage.numerical.backends.gurobi_backend'] = backends.gurobi_backend = gurobi_backend\n\nIf these commands are executed in a Sage session before any `MixedIntegerLinearProgram` is created, then\nthe new `'Gurobi'` solver wins over the `'GLPK'` solver in the selection of the default MIP backend.\nTo select the `'Gurobi'` solver explicitly as the default MIP backend, additionally use the following command.\n\n    sage: default_mip_solver('Gurobi')\n\nTo make these settings permanent, add the above 2 + 1 commands to your `~/.sage/init.sage` file.\nNote that this setting will not affect doctesting (`sage -t`) because this file is ignored in doctesting mode.\n\n## Running doctests\n\nTo run the (limited) testsuite of this package, use:\n\n    $ sage setup.py test\n\nIf no Gurobi license is available, the testing is skipped without error.\n\nTo run the Sage testsuite with the default MIP solver set to the backend provided by this package, use:\n\n    $ sage setup.py check_sage_testsuite\n\nIf no Gurobi license is available, the testing is skipped without error.\n\n## Running tests with tox\n\nThe doctests can also be invoked using `tox`:\n\n    $ tox -e local\n    $ tox -e local check_sage_testsuite.py\n\nTesting multiple installed Gurobi versions in parallel (see `tox.ini`):\n\n    $ tox -p auto\n\n## Overriding the default solver by patching the Sage installation\n\nAnother method is to patch the module in permanently to the sage installation (at your own risk).\nThis method will affect doctesting.\n\n    $ sage -c 'import os; import sage.numerical.backends as dm; import sage_numerical_backends_gurobi.gurobi_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);'\n\nOr use the script [`patch_into_sage_module.py`](patch_into_sage_module.py) in the source distribution that does the same:\n\n    $ sage -c 'load(\"patch_into_sage_module.py\")'\n    Success: Patched in the module as sage.numerical.backends.gurobi_backend\n\nVerify with [`check_get_solver_with_name.py`](check_get_solver_with_name.py) that the patching script has worked:\n\n    $ sage -c 'load(\"check_get_solver_with_name.py\")'\n    Success: get_solver(solver='gurobi') gives <sage_numerical_backends_gurobi.gurobi_backend.GurobiBackend object at 0x7f8f20218528>",
    "bugtrack_url": null,
    "license": "GPLv2+",
    "summary": "Gurobi backend for Sage MixedIntegerLinearProgram",
    "version": "9.3.1",
    "project_urls": {
        "Homepage": "https://github.com/sagemath/sage-numerical-backends-gurobi"
    },
    "split_keywords": [
        "milp",
        "linear-programming",
        "optimization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0337966dc91e81af330aa62c7baa426a7798e6964d752ca221c077e3e8c7c47b",
                "md5": "0a77377fad705950c4b7b14b366ebaa6",
                "sha256": "bb073ce2d7972aabafd2a074c46231204fe3a04d273b247ee9a03ca8938d17e0"
            },
            "downloads": -1,
            "filename": "sage_numerical_backends_gurobi-9.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0a77377fad705950c4b7b14b366ebaa6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 30339,
            "upload_time": "2021-05-18T22:26:42",
            "upload_time_iso_8601": "2021-05-18T22:26:42.074719Z",
            "url": "https://files.pythonhosted.org/packages/03/37/966dc91e81af330aa62c7baa426a7798e6964d752ca221c077e3e8c7c47b/sage_numerical_backends_gurobi-9.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-18 22:26:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sagemath",
    "github_project": "sage-numerical-backends-gurobi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "setuptools",
            "specs": []
        },
        {
            "name": "wheel",
            "specs": []
        },
        {
            "name": "Cython",
            "specs": []
        },
        {
            "name": "cysignals",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "sage-numerical-backends-gurobi"
}
        
Elapsed time: 0.27075s