Gurobi: Difference between revisions

Jump to navigation Jump to search
no edit summary
mNo edit summary
No edit summary
Line 4: Line 4:


<!--T:1-->
<!--T:1-->
[http://www.gurobi.com/ Gurobi] is a commercial software suite for solving complex optimization problems.  This page wiki page describes the non-commercial use of Gurobi software on Compute Canada clusters and is currently a work in progress.
[http://www.gurobi.com/ Gurobi] is a commercial software suite for solving complex optimization problems.  This page wiki page describes the non-commercial use of Gurobi software on our clusters and is currently a work in progress.


== License Limitations == <!--T:2-->
== License Limitations == <!--T:2-->


<!--T:3-->
<!--T:3-->
Compute Canada supports and provides a free license to use Gurobi on the [[Graham]], [[Cedar]], [[Beluga/en|Béluga]] and [[Niagara]] clusters.  The license provides a total number of 4096 simultaneous uses (tokens in use) and permits distributed optimization with up to 100 nodes.  A single user can run multiple simultaneous jobs.  In order to use Gurobi you must agree to certain conditions. Please [[Technical_support | contact support]] and include a copy of the following completed Academic Usage Agreement.  You will then be added into the Compute Canada license file as a permitted user within a few days:
We support and provide a free license to use Gurobi on the [[Graham]], [[Cedar]], [[Beluga/en|Béluga]] and [[Niagara]] clusters.  The license provides a total number of 4096 simultaneous uses (tokens in use) and permits distributed optimization with up to 100 nodes.  A single user can run multiple simultaneous jobs.  In order to use Gurobi you must agree to certain conditions. Please [[Technical_support | contact support]] and include a copy of the following completed Academic Usage Agreement.  You will then be added into our license file as a permitted user within a few days.


===Academic Usage Agreement=== <!--T:4-->
===Academic Usage Agreement=== <!--T:4-->
Line 17: Line 17:


===Configuring your account=== <!--T:43-->
===Configuring your account=== <!--T:43-->
You do NOT need to create a <code>~/.licenses/gurobi.lic</code> file.  The required settings to use the Compute Canada Gurobi license are configured by default when you load a gurobi module on any cluster.  To verify your username has been added to the Compute Canada Gurobi license and working properly run the following command:
You do NOT need to create a <code>~/.licenses/gurobi.lic</code> file.  The required settings to use our Gurobi license are configured by default when you load a Gurobi module on any cluster.  To verify your username has been added to our Gurobi license and is working properly, run the following command:


  <!--T:143-->
  <!--T:143-->
Line 24: Line 24:


<!--T:44-->
<!--T:44-->
If it returns "Success" then you can begin using gurobi immediately! If the test returns "Fail" then check whether a file named <i>~/.license/gurobi</i> exists, if so then rename or remove it, reload the module and try the test again.  If it still returns "Fail" then check whether there are any environment variables containing GUROBI defined in either of our your <i>~/.bashrc</i> or <i>~/.bash_profile</I> files.  If you find any then comment or remove those lines, logout and login again, reload the gurobi module and try the test again.  If you still get "Fail" then contact [[Technical_support | contact support]] for help.
If it returns "Success" you can begin using Gurobi immediately. If the test returns "Fail" then check whether a file named <i>~/.license/gurobi</i> exists; if so, rename or remove this file, reload the module and try the test again.  If it still returns "Fail", check whether there are any environment variables containing GUROBI defined in either of our your <i>~/.bashrc</i> or <i>~/.bash_profile</I> files.  If you find any, comment or remove those lines, log out and log in again, reload the Gurobi module and try the test again.  If you still get "Fail", contact [[Technical_support | contact support]] for help.


===Minimizing License Checkouts=== <!--T:216-->
===Minimizing License Checkouts=== <!--T:216-->


<!--T:217-->
<!--T:217-->
Note that all Gurobi license checkouts are handled by a single license server located in Ontario, so that it is important for you to assure that your use of Gurobi limits as much as possible license checkout attempts.  Rather than checking out a license for each invocation of Gurobi in a job - which may occur dozens or even hundreds of times - you should ensure that your program, whatever the language or computing environment used, only makes a single license checkout and then reuses this license token throughout the lifetime of the job. This will improve your job's performance since contacting a remote license server is very costly in time and also improve the responsiveness of our license server for everyone who is using Gurobi.  <span style="color:red">Failure to use Gurobi carefully in this regard may ultimately result in random intermittent license checkout failures for all users.  If this happens you will be contacted and asked to kill all your jobs until your program is fixed and tested to ensure the problem is gone.</span>    Some documentation on this subject for C++ programs may be found [https://www.gurobi.com/documentation/9.5/refman/cpp_env2.html here], explaining how to create a single Gurobi environment which can then be used for all your models. Python users can consult this [https://www.gurobi.com/documentation/9.5/refman/py_env_start.html page], which discusses how to implement this same idea of using a single environment and thus a single license token with multiple models.  Other programs when run in parallel that call Gurobi such as R can also easily trigger the problem especially when many simultaneous jobs are submitted and/or run in parallel.
Note that all Gurobi license checkouts are handled by a single license server located in Ontario; it is therefore important for you to make sure that your use of Gurobi limits as much as possible license checkout attempts.  Rather than checking out a license for each invocation of Gurobi in a job--which may occur dozens or even hundreds of times--you should ensure that your program, whatever the language or computing environment used, only makes a single license checkout and then reuses this license token throughout the lifetime of the job. This will improve your job's performance since contacting a remote license server is very costly in time and will also improve the responsiveness of our license server for everyone who is using Gurobi.  <span style="color:red">Failure to use Gurobi carefully in this regard may ultimately result in random intermittent license checkout failures for all users.  If this happens, you will be contacted and asked to kill all your jobs until your program is fixed and tested to ensure the problem is gone.</span>    Some documentation on this subject for C++ programs may be found [https://www.gurobi.com/documentation/9.5/refman/cpp_env2.html here], explaining how to create a single Gurobi environment which can then be used for all your models. Python users can consult this [https://www.gurobi.com/documentation/9.5/refman/py_env_start.html page], which discusses how to implement this same idea of using a single environment and thus a single license token with multiple models.  Other programs when run in parallel that call Gurobi such as R can also easily trigger the problem especially when many simultaneous jobs are submitted and/or run in parallel.


== Interactive Allocations == <!--T:5-->
== Interactive Allocations == <!--T:5-->
Line 66: Line 66:


===Replaying API calls=== <!--T:6-->
===Replaying API calls=== <!--T:6-->
You can record API calls and repeat them with command
You can record API calls and repeat them with  


<!--T:61-->
<!--T:61-->
Line 77: Line 77:


<!--T:70-->
<!--T:70-->
Once a slurm script has been prepared for a Gurobi problem it can be submitted to the queue by running the <code>sbatch script-name.sh</code> command.  The jobs status in the queue can then be checked by running the <code>sq</code> command.  The following slurm scripts demonstrate solving 2 problems provided in the <tt> examples</tt> directory of each gurobi module:
Once a Slurm script has been prepared for a Gurobi problem, it can be submitted to the queue by running the <code>sbatch script-name.sh</code> command.  The jobs status in the queue can then be checked by running the <code>sq</code> command.  The following Slurm scripts demonstrate solving 2 problems provided in the <tt> examples</tt> directory of each Gurobi module.


=== Data Example === <!--T:71-->  
=== Data Example === <!--T:71-->  


<!--T:73-->
<!--T:73-->
The following slurm script utilizes the [https://www.gurobi.com/documentation/9.5/quickstart_linux/solving_the_model_using_th.html Gurobi command-line interface] to solve a [https://www.gurobi.com/documentation/9.5/quickstart_linux/solving_a_simple_model_the.html simple coin production model] written in [https://www.gurobi.com/documentation/9.5/refman/lp_format.html LP format].  The last line demonstrates how [https://www.gurobi.com/documentation/9.5/refman/parameters.html parameters] can be passed directly to the Gurobi command-line tool <code>gurobi_cl</code> using simple command line arguments.  For help selecting which [https://www.gurobi.com/documentation/9.5/refman/parameters.html parameters] are best used for a particular problem and choosing optimal values refer to both the <i>Performance and Parameters</i> & <i>Algorithms and Search</I> sections found in the Gurobi [https://support.gurobi.com/hc/en-us/categories/360000840331-Knowledge-Base Knowledge Base] as well as the extensive online Gurobi [https://www.gurobi.com/documentation/ Documentation].
The following Slurm script utilizes the [https://www.gurobi.com/documentation/9.5/quickstart_linux/solving_the_model_using_th.html Gurobi command-line interface] to solve a [https://www.gurobi.com/documentation/9.5/quickstart_linux/solving_a_simple_model_the.html simple coin production model] written in [https://www.gurobi.com/documentation/9.5/refman/lp_format.html LP format].  The last line demonstrates how [https://www.gurobi.com/documentation/9.5/refman/parameters.html parameters] can be passed directly to the Gurobi command-line tool <code>gurobi_cl</code> using simple command line arguments.  For help selecting which [https://www.gurobi.com/documentation/9.5/refman/parameters.html parameters] are best used for a particular problem and for choosing optimal values, refer to both the <i>Performance and Parameters</i> and <i>Algorithms and Search</I> sections found in the [https://support.gurobi.com/hc/en-us/categories/360000840331-Knowledge-Base Gurobi Knowledge Base] as well as the extensive online [https://www.gurobi.com/documentation/ Gurobi documentation].
{{File
{{File
   |name=script-lp_coins.sh
   |name=script-lp_coins.sh
Line 109: Line 109:


<!--T:83-->
<!--T:83-->
This is an example slurm script for solving a [https://www.gurobi.com/documentation/9.5/examples/a_list_of_the_grb_examples.html simple facility location model] using [https://www.gurobi.com/documentation/9.5/examples/facility_py.html Gurobi Python].  The example shows how-to set the threads  [https://www.gurobi.com/documentation/9.5/refman/parameters.html#sec:Parameters parameter] with a dynamically created [https://www.gurobi.com/documentation/9.5/quickstart_linux/using_a_grb_env_file.html gurobi.env] file when using the [https://www.gurobi.com/documentation/9.5/refman/python_parameter_examples.html Gurobi python interface].  This must be done in the working directory for each submitted job otherwise gurobi will (by default) start as many execute [https://www.gurobi.com/documentation/9.5/refman/threads.html#parameter:Threads threads] as there are physical cores on the compute node, instead of using the number of physical cores allocated to the job by slurm, potentially slowing down the job and negatively impacting other user jobs running on the same node.
This is an example Slurm script for solving a [https://www.gurobi.com/documentation/9.5/examples/a_list_of_the_grb_examples.html simple facility location model] with [https://www.gurobi.com/documentation/9.5/examples/facility_py.html Gurobi Python].  The example shows how to set the threads  [https://www.gurobi.com/documentation/9.5/refman/parameters.html#sec:Parameters parameter] with a dynamically created [https://www.gurobi.com/documentation/9.5/quickstart_linux/using_a_grb_env_file.html gurobi.env] file when using the [https://www.gurobi.com/documentation/9.5/refman/python_parameter_examples.html Gurobi python interface].  This must be done in the working directory for each submitted job, otherwise Gurobi will (by default) start as many execute [https://www.gurobi.com/documentation/9.5/refman/threads.html#parameter:Threads threads] as there are physical cores on the compute node, instead of using the number of physical cores allocated to the job by Slurm, potentially slowing down the job and negatively impacting other user jobs running on the same node.
{{File
{{File
   |name=script-py_facility.sh
   |name=script-py_facility.sh
Line 138: Line 138:


<!--T:91-->
<!--T:91-->
Gurobi brings it's own version of Python but that one does not contain any 3rd-party Python packages except Gurobi.  In order to use Gurobi together with popular Python  
Gurobi brings it's own version of Python which does not contain any 3rd-party Python packages except Gurobi.  In order to use Gurobi together with popular Python  
packages like NumPy, Matplotlib, Pandas and others, we need to create a [[Python#Creating_and_using_a_virtual_environment|virtual Python environment]] in which we can install both <code>gurobipy</code> and e.g. <code>pandas</code>.  
packages like NumPy, Matplotlib, Pandas and others, we need to create a [[Python#Creating_and_using_a_virtual_environment|virtual Python environment]] in which we can install both <code>gurobipy</code> and e.g. <code>pandas</code>.  


<!--T:214-->
<!--T:214-->
Before we start, we need to decide which combination of versions for Gurobi and Python to use.  For example compare the python versions supported by the gurobi 8.11 and 9.0.1 modules:
Before we start, we need to decide which combination of versions for Gurobi and Python to use.  For example compare the Python versions supported by the Gurobi 8.11 and 9.0.1 modules:


<!--T:201-->
<!--T:201-->
Line 180: Line 180:
| source ~/env_gurobi/bin/activate
| source ~/env_gurobi/bin/activate
}}
}}
Now that the environment has been activated install the Python packages we want to use, in this case <code>pandas</code> for example:
Now that the environment has been activated, install the Python packages we want to use (in this case <code>pandas</code>) for example:


<!--T:110-->
<!--T:110-->
Line 234: Line 234:


<!--T:126-->
<!--T:126-->
Once created we can activate our Gurobi environment at any time with:
Once created we can activate our Gurobi environment at any time with


<!--T:203-->
<!--T:203-->
Line 294: Line 294:


<!--T:209-->
<!--T:209-->
Various topics can be found by visiting [https://www.gurobi.com/resources/ Resources] then clicking [https://www.gurobi.com/resources/?category-filter=code-example Code and Modeling Examples] and finally [https://www.gurobi.com/resource/modeling-examples-using-the-gurobi-python-api-in-jupyter-notebook/ Optimization with Python – Jupyter Notebook Modeling Examples].  Alternatively visit [https://support.gurobi.com/ support.gurobi.com] and search on <I>Jupyter Notebooks</I>.   
Various topics can be found by visiting [https://www.gurobi.com/resources/ Resources], then clicking [https://www.gurobi.com/resources/?category-filter=code-example Code and Modeling Examples] and finally [https://www.gurobi.com/resource/modeling-examples-using-the-gurobi-python-api-in-jupyter-notebook/ Optimization with Python – Jupyter Notebook Modeling Examples].  Alternatively visit [https://support.gurobi.com/ support.gurobi.com] and search on <I>Jupyter Notebooks</I>.   


<!--T:215-->
<!--T:215-->
A demo case of using Gurobi with Jupyter notebooks on Compute Canada systems can be found in this [https://youtu.be/Qk3Le5HBxeg?t=2310 video recording, i.e. at time 38:28].
A demo case of using Gurobi with Jupyter notebooks on our systems can be found in this [https://youtu.be/Qk3Le5HBxeg?t=2310 video recording, i.e. at time 38:28].


== Cite Gurobi == <!--T:140-->
== Cite Gurobi == <!--T:140-->
rsnt_translations
56,430

edits

Navigation menu