Skip to content

Commit

Permalink
solvers: Remove f2c build flavor of SNOPT solver (RobotLocomotion#12299)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri authored Nov 4, 2019
1 parent 694b7b8 commit 8775793
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 1,184 deletions.
64 changes: 18 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,33 +341,13 @@ if(WITH_MOSEK)
list(APPEND BAZEL_CONFIGS --config=mosek)
endif()

set(WITH_SNOPT_STRINGS F2C Fortran OFF ON)
string(REPLACE ";" " " WITH_SNOPT_STRINGS_STRING "${WITH_SNOPT_STRINGS}")

set(WITH_ROBOTLOCOMOTION_SNOPT OFF CACHE STRING
"Build with support for SNOPT using the RobotLocomotion/snopt private GitHub repository, options are ${WITH_SNOPT_STRINGS_STRING}"
)
set_property(CACHE WITH_ROBOTLOCOMOTION_SNOPT PROPERTY
STRINGS "${WITH_SNOPT_STRINGS}"
set(WITH_ROBOTLOCOMOTION_SNOPT OFF CACHE BOOL
"Build with support for SNOPT using the RobotLocomotion/snopt private GitHub repository"
)

if(NOT WITH_ROBOTLOCOMOTION_SNOPT IN_LIST WITH_SNOPT_STRINGS)
message(FATAL_ERROR
"Value ${WITH_ROBOTLOCOMOTION_SNOPT} for the WITH_ROBOTLOCOMOTION_SNOPT "
"option is NOT supported"
)
endif()

set(WITH_SNOPT OFF CACHE STRING
"Build with support for SNOPT using a SNOPT source archive at SNOPT_PATH, options are ${WITH_SNOPT_STRINGS_STRING}"
set(WITH_SNOPT OFF CACHE BOOL
"Build with support for SNOPT using a SNOPT source archive at SNOPT_PATH"
)
set_property(CACHE WITH_SNOPT PROPERTY STRINGS "${WITH_SNOPT_STRINGS}")

if(NOT WITH_SNOPT IN_LIST WITH_SNOPT_STRINGS)
message(FATAL_ERROR
"Value ${WITH_SNOPT} for the WITH_SNOPT option is NOT supported"
)
endif()

if(WITH_ROBOTLOCOMOTION_SNOPT AND WITH_SNOPT)
message(FATAL_ERROR
Expand All @@ -376,32 +356,24 @@ if(WITH_ROBOTLOCOMOTION_SNOPT AND WITH_SNOPT)
endif()

if(WITH_ROBOTLOCOMOTION_SNOPT OR WITH_SNOPT)
if(WITH_ROBOTLOCOMOTION_SNOPT STREQUAL F2C OR WITH_SNOPT STREQUAL F2C)
list(APPEND BAZEL_CONFIGS --config=snopt_f2c)
else()
enable_language(Fortran)

if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS ${MINIMUM_GNU_VERSION})
message(FATAL_ERROR
"Compilation with gfortran ${CMAKE_Fortran_COMPILER_VERSION} is NOT "
"supported"
)
endif()
else()
message(WARNING
"Compilation with ${CMAKE_Fortran_COMPILER_ID} is NOT supported. "
"Compilation of project drake_cxx_python may fail."
)
endif()
enable_language(Fortran)

if(WITH_ROBOTLOCOMOTION_SNOPT STREQUAL Fortran OR WITH_SNOPT STREQUAL Fortran)
list(APPEND BAZEL_CONFIGS --config=snopt_fortran)
else()
list(APPEND BAZEL_CONFIGS --config=snopt)
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS ${MINIMUM_GNU_VERSION})
message(FATAL_ERROR
"Compilation with gfortran ${CMAKE_Fortran_COMPILER_VERSION} is NOT "
"supported"
)
endif()
else()
message(WARNING
"Compilation with ${CMAKE_Fortran_COMPILER_ID} is NOT supported. "
"Compilation of project drake_cxx_python may fail."
)
endif()

list(APPEND BAZEL_CONFIGS --config=snopt)

if(WITH_ROBOTLOCOMOTION_SNOPT)
list(APPEND BAZEL_ENV "SNOPT_PATH=git")
else()
Expand Down
15 changes: 3 additions & 12 deletions doc/bazel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,9 @@ these tests. If you will be developing with SNOPT regularly, you may wish
to specify a more convenient ``--test_tag_filters`` in a local ``.bazelrc``.
See https://docs.bazel.build/versions/master/user-manual.html#bazelrc.

Drake offers two flavors of SNOPT bindings for the MathematicalProgram:

- The ``--config snopt_f2c`` option selects the legacy bindings that use the
f2c compiler; these bindings will be removed on 2019-11-01.
- The ``--config snopt_fortran`` option selects the bindings that use the
gfortran compiler; these bindings will be supported for the foreseeable
future.
- The ``--config snopt`` is synonymous with ``--config snopt_fortran``.

The gfortran bindings are superior in several ways (such as being threadsafe),
but have some known problems on certain programs (see drake issue `#10422
<https://github.com/RobotLocomotion/drake/issues/10422>`_ for a summary).
SNOPT support has some known problems on certain programs (see drake issue
`#10422 <https://github.com/RobotLocomotion/drake/issues/10422>`_ for a
summary).

Optional Tools
==============
Expand Down
26 changes: 5 additions & 21 deletions solvers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -780,28 +780,21 @@ drake_cc_library(
}),
)

# If --config snopt (or one of --config snopt_{fortran,f2c}) is used, this
# target builds object code that satisfies SolverInterface by calling
# SNOPT. Otherwise, this target builds dummy object code that fails at runtime.
# If --config snopt (or --config snopt_fortran) is used, this target builds
# object code that satisfies SolverInterface by calling SNOPT. Otherwise, this
# target builds dummy object code that fails at runtime.
drake_cc_library(
name = "snopt_solver",
srcs = select({
# The `--config snopt` ("Use the default SNOPT flavor") is a synonym
# for `--config snopt_fortran` ("Use the Fortran SNOPT flavor").
# For `--config snopt` or `--config snopt_fortran`.
"//tools:with_snopt": [
"snopt_solver.cc",
"snopt_solver_common.cc",
],
# This is always the Fortran flavor.
"//tools:with_snopt_fortran": [
"snopt_solver.cc",
"snopt_solver_common.cc",
],
# This is always the f2c flavor.
"//tools:with_snopt_f2c": [
"snopt_solver_f2c.cc",
"snopt_solver_common.cc",
],
# This is when SNOPT is disabled / unavailable.
"//conditions:default": [
"no_snopt.cc",
Expand All @@ -810,27 +803,19 @@ drake_cc_library(
}),
hdrs = ["snopt_solver.h"],
deps = select({
# This is Drake's default flavor (Fortran).
# For `--config snopt` or `--config snopt_fortran`.
"//tools:with_snopt": [
":mathematical_program",
":solver_base",
"//math:autodiff",
"@snopt//:snopt_cwrap",
],
# This is always the Fortran flavor.
"//tools:with_snopt_fortran": [
":mathematical_program",
":solver_base",
"//math:autodiff",
"@snopt//:snopt_cwrap",
],
# This is always the f2c flavor.
"//tools:with_snopt_f2c": [
":mathematical_program",
":solver_base",
"//math:autodiff",
"@snopt//:snopt_c",
],
# This is when SNOPT is disabled / unavailable.
"//conditions:default": [
":mathematical_program",
Expand Down Expand Up @@ -1740,5 +1725,4 @@ add_lint_tests(cpplint_extra_srcs = [
"snopt_solver.cc",
"snopt_solver.h",
"snopt_solver_common.cc",
"snopt_solver_f2c.cc",
])
5 changes: 4 additions & 1 deletion solvers/snopt_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>

#include "drake/common/drake_copyable.h"
#include "drake/common/drake_deprecated.h"
#include "drake/solvers/solver_base.h"

namespace drake {
Expand Down Expand Up @@ -44,9 +45,11 @@ class SnoptSolver final : public SolverBase {
SnoptSolver();
~SnoptSolver() final;

/// @return if the solver is thread safe. SNOPT f2c interface uses global
/// @return true.
/// variables, hence it is not thread safe. SNOPT fortran interface is thread
/// safe.
DRAKE_DEPRECATED("2020-02-01",
"The SnoptSolver::is_thread_safe always returns true.")
static bool is_thread_safe();

/// For some reason, SNOPT 7.4 fails to detect a simple LP being unbounded.
Expand Down
4 changes: 1 addition & 3 deletions solvers/snopt_solver_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ SnoptSolver::~SnoptSolver() = default;

SolverId SnoptSolver::id() {
static const never_destroyed<SolverId> singleton{
SnoptSolver::is_available() ?
(SnoptSolver::is_thread_safe() ? "SNOPT/fortran" : "SNOPT/f2c") :
"SNOPT/unavailable"};
SnoptSolver::is_available() ? "SNOPT/fortran" : "SNOPT/unavailable"};
return singleton.access();
}

Expand Down
Loading

0 comments on commit 8775793

Please sign in to comment.