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

Support Gurobi 9.5.x #18464

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ set(BAZEL_CONFIGS)
option(WITH_GUROBI "Build with support for Gurobi" OFF)

if(WITH_GUROBI)
find_package(Gurobi 9.5.1 EXACT MODULE REQUIRED)
find_package(Gurobi 9.5 EXACT MODULE REQUIRED)

list(APPEND BAZEL_CONFIGS --config=gurobi)

Expand Down
15 changes: 9 additions & 6 deletions cmake/modules/FindGurobi.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# -*- mode: cmake -*-
# vi: set ft=cmake :

file(GLOB _GUROBI_SEARCH_PATHS
/Library/gurobi95*/macos_universal2
/opt/gurobi95*/linux64
/opt/gurobi95*/power64
)

find_path(Gurobi_INCLUDE_DIR NAMES gurobi_c.h
PATHS
/Library/gurobi951/macos_universal2
/opt/gurobi951/linux64
/opt/gurobi951/power64
${_GUROBI_SEARCH_PATHS}
ENV GUROBI_HOME
PATH_SUFFIXES include
)
Expand Down Expand Up @@ -38,14 +42,13 @@ find_library(Gurobi_LIBRARY
NAMES "gurobi${Gurobi_VERSION_MAJOR}${Gurobi_VERSION_MINOR}"
HINTS "${_GUROBI_ROOT}"
PATHS
/Library/gurobi951/macos_universal2
/opt/gurobi951/linux64
/opt/gurobi951/power64
${_GUROBI_SEARCH_PATHS}
ENV GUROBI_HOME
PATH_SUFFIXES lib
)

unset(_GUROBI_ROOT)
unset(_GUROBI_SEARCH_PATHS)

include(FindPackageHandleStandardArgs)

Expand Down
16 changes: 10 additions & 6 deletions doc/_pages/bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,31 @@ bazel build //tools/lint:buildifier

The Drake Bazel build currently supports the following proprietary solvers:

* Gurobi 9.5.1
* Gurobi 9.5
* MOSEK™ 10.0
* SNOPT 7.4

## Gurobi 9.5.1
## Gurobi 9.5

### Install on Ubuntu

1. Register for an account on [https://www.gurobi.com](https://www.gurobi.com).
2. Set up your Gurobi license file in accordance with Gurobi documentation.
3. ``export GRB_LICENSE_FILE=/path/to/gurobi.lic``.
4. Download ``gurobi9.5.1_linux64.tar.gz``. You may need to manually edit the URL to get the correct minor version.
5. Unzip it. We suggest that you use ``/opt/gurobi951`` to simplify working with Drake installations.
6. If you unzipped into a location other than ``/opt/gurobi951``, then call ``export GUROBI_HOME=GUROBI_UNZIP_PATH/linux64`` to set the path you used, where in ``GUROBI_HOME`` folder you can find ``bin`` folder.
4. Download ``gurobi9.5.2_linux64.tar.gz``. You may need to manually edit the URL to get the correct version.
5. Unzip it. We suggest that you use ``/opt/gurobi952`` to simplify working with Drake installations.
6. If you unzipped into a location other than ``/opt/gurobi952``, then call ``export GUROBI_HOME=GUROBI_UNZIP_PATH/linux64`` to set the path you used, where in ``GUROBI_HOME`` folder you can find ``bin`` folder.

Drake supports any patch version of Gurobi 9.5. At time of writing, the most
recent available version was 9.5.2; if using a newer patch version, the paths
and file names above should be adjusted accordingly.

### Install on macOS

1. Register for an account on [http://www.gurobi.com](http://www.gurobi.com).
2. Set up your Gurobi license file in accordance with Gurobi documentation.
3. ``export GRB_LICENSE_FILE=/path/to/gurobi.lic``
4. Download and install ``gurobi9.5.1_mac64.pkg``.
4. Download and install ``gurobi9.5.2_mac64.pkg``.

To confirm that your setup was successful, run the tests that require Gurobi:

Expand Down
2 changes: 1 addition & 1 deletion doc/_pages/python_bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ python3 -c 'import pydrake.all; print(pydrake.__file__)'
```

<div class="note" markdown="1">
If you are using Gurobi, you must either have it installed in the suggested location under `/opt/...` mentioned in Gurobi 9.5.1, or you must ensure that you define the `${GUROBI_HOME}` environment variable, or specify `${GUROBI_INCLUDE_DIR}` via CMake.
If you are using Gurobi, you must either have it installed in the suggested location under `/opt/...` mentioned in Gurobi 9.5, or you must ensure that you define the `${GUROBI_HOME}` environment variable, or specify `${GUROBI_INCLUDE_DIR}` via CMake.
</div>


Expand Down
2 changes: 1 addition & 1 deletion tools/workspace/gurobi/package-macos.BUILD.bazel.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ licenses(["by_exception_only"]) # Gurobi
genrule(
name = "error-message",
outs = ["error-message.h"],
cmd = "echo 'error: Gurobi 9.5.1 is not installed at {gurobi_home}' && false", # noqa
cmd = "echo 'error: Gurobi 9.5 is not installed at {gurobi_home}' && false", # noqa
visibility = ["//visibility:private"],
)

Expand Down
8 changes: 4 additions & 4 deletions tools/workspace/gurobi/package-ubuntu.BUILD.bazel.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ licenses(["by_exception_only"]) # Gurobi
genrule(
name = "error-message",
outs = ["error-message.h"],
cmd = "echo 'error: Gurobi 9.5.1 is not installed at {gurobi_home}, export GUROBI_HOME to the correct value' && false", # noqa
cmd = "echo 'error: Gurobi 9.5 is not installed at {gurobi_home}, export GUROBI_HOME to the correct value' && false", # noqa
visibility = ["//visibility:private"],
)

Expand All @@ -25,8 +25,8 @@ GUROBI_CXX_HDRS = glob([
"gurobi-distro/include/gurobi_c++.h",
]) or [":error-message.h"]

# In the Gurobi package, libgurobi95.so is a symlink to libgurobi.so.9.0.0.
# However, if we use libgurobi.so.9.0.0 in srcs, executables that link this
# In the Gurobi package, libgurobi95.so is a symlink to libgurobi.so.9.5.*.
# However, if we use libgurobi.so.9.5.* in srcs, executables that link this
# library will be unable to find it at runtime in the Bazel sandbox,
# because the NEEDED statements in the executable will not square with the
# RPATH statements. I don't really know why this happens, but I suspect it
Expand All @@ -42,7 +42,7 @@ GUROBI_CXX_SRCS = glob([
]) or [":error-message.h"]

GUROBI_INSTALL_LIBRARIES = glob([
"gurobi-distro/lib/libgurobi.so.9.5.1",
"gurobi-distro/lib/libgurobi.so.9.5.*",
"gurobi-distro/lib/libgurobi95.so",
]) or [":error-message.h"]

Expand Down
35 changes: 31 additions & 4 deletions tools/workspace/gurobi/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@

load("@drake//tools/workspace:os.bzl", "determine_os")

# Ubuntu only: GUROBI_HOME should be the linux64 directory in the Gurobi 9.5.1
# Finds the "latest" f'{path}/{prefix}*/{subdir}', where "latest" is determined
# by converting the part that matched the '*' to an integer and taking the
# match with the highest value.
def _find_latest(repo_ctx, path, prefix, subdir):
best_dir = None
best_version = None
for d in repo_ctx.path(path).readdir():
if d.basename.startswith(prefix):
full_dir = d.get_child(subdir)
if full_dir.exists:
version = int(d.basename[len(prefix):])
if best_version == None or version > best_version:
best_version = version
best_dir = full_dir.realpath

return best_dir or (path + "/" + prefix + "-notfound/" + subdir)

# Ubuntu only: GUROBI_HOME should be the linux64 directory in the Gurobi 9.5
# release.
#
def _gurobi_impl(repo_ctx):
Expand All @@ -14,17 +31,27 @@ def _gurobi_impl(repo_ctx):

if os_result.is_macos:
# Gurobi must be installed into its standard location.
gurobi_home = "/Library/gurobi951/macos_universal2"
gurobi_home = _find_latest(
repo_ctx,
"/Library",
"gurobi95",
"macos_universal2",
)
repo_ctx.symlink(gurobi_home, "gurobi-distro")
build_flavor = "macos"
else:
# The default directory for the downloaded gurobi is
# /opt/gurobi951/linux64. If the user does not use the default
# /opt/gurobi95*/linux64. If the user does not use the default
# directory, the he/she should set GUROBI_HOME environment variable to
# the gurobi file location.
gurobi_home = repo_ctx.os.environ.get("GUROBI_HOME", "")
repo_ctx.symlink(
gurobi_home or "/opt/gurobi951/linux64",
gurobi_home or _find_latest(
repo_ctx,
"/opt",
"gurobi95",
"linux64",
),
"gurobi-distro",
)
build_flavor = "ubuntu"
Expand Down