Gurobi/Note

From ScientificComputing
Revision as of 14:36, 7 February 2023 by Sfux (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Gurobi provides different interfaces (Python, Matlab, R) that can be used. Please find below instructions on how to install the interfaces locally for any version of Python, Matlab or R.

Matlab interface

For using the Matlab interface, you would need to load your favorite Matlab and Gurobi module and then add the path to the Gurobi Matlab package, using the Matlab command addpath:

addpath('/cluster/apps/gurobi/__VERSION__/x86_64/matlab')

where __VERSION__ needs to be replace with the Gurobi version for which you loaded the corresponding module. For Gurobi installations (9.0.2, 9.1.1) in the new software stack, the path that needs to be added is

addpath('/cluster/apps/nss/gurobi/__VERSION__/x86_64/matlab')

Please find below an example to use the Matlab interface with Gurobi 10.0.1:

[sfux@eu-login-47 test1]$ cp /cluster/apps/nss/gurobi/10.0.1/x86_64/examples/matlab/mip1.m .
[sfux@eu-login-47 test1]$ module load gurobi/10.0.1 matlab/R2022b
[sfux@eu-login-47 test1]$ matlab -nodisplay -nojvm -singleCompThread
MATLAB is selecting SOFTWARE OPENGL rendering.

                                                           < M A T L A B (R) >
                                                 Copyright 1984-2017 The MathWorks, Inc.
                                                 R2022b 64-bit (glnxa64)
                                                           September 14, 2022

 
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
 
>> addpath('/cluster/apps/nss/gurobi/10.0.1/x86_64/matlab')
>> mip1
          status: 'OPTIMAL'
     versioninfo: [1x1 struct]
         runtime: 0.0014
          objval: 3
               x: [3x1 double]
           slack: [2x1 double]
    poolobjbound: 3
            pool: [1x2 struct]
          mipgap: 0
        objbound: 3
       objboundc: 3
       itercount: 0
    baritercount: 0
       nodecount: 0 

x 1
y 0
z 1
Obj: 3.000000e+00
>> 

If you would like to install the Gurobi Matlab interface permanently, then it is sufficient to create a file

$HOME/matlab/startup.m

that contains the addpath command. Matlab will on startup automatically check the startup.m file.

R interface

For using the R interface, you would need to load your favorite R and Gurobi module, start an interactive R session and then use the following R command to install the interface:

install.packages('__TARBALL__', repos=NULL)

where __TARBALL__ needs to be replace with the corresponding path for the Gurobi R package. Please find below the list of options for __TARBALL__:

/cluster/apps/nss/gurobi/10.0.1/x86_64/R/gurobi_10.0-1_R_4.2.0.tar.gz
/cluster/apps/nss/gurobi/9.0.2/x86_64/R/gurobi_9.0-2_R_3.6.1.tar.gz
/cluster/apps/nss/gurobi/9.1.1/x86_64/R/gurobi_9.1-1_R_4.0.2.tar.gz
/cluster/apps/nss/gurobi/9.5.1/x86_64/R/gurobi_9.5-1_R_4.1.1.tar.gz
/cluster/apps/nss/gurobi/10.0.1/x86_64/R/gurobi_10.0-1_R_4.2.0.tar.gz

The interface only needs to be installed locally once and should afterwards automatically be found by R.

Python interface

For installing the Python interface, you can use pip. Load your preferred Python and Gurobi module and then run

pip install --user gurobipy==10.0.1

Please make sure that the version of gurobipy matches the version number of the Gurobi module that is loaded.

Alternatively, you can also install gurobipy in a virtual environment.