From c04faa63af8cc6a862cd1172861c04f1a5e8a5b0 Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Wed, 6 Nov 2024 13:34:25 -0800 Subject: [PATCH] [solvers] Fix Gurobi console logging config to happen first (#22134) --- solvers/gurobi_solver.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/solvers/gurobi_solver.cc b/solvers/gurobi_solver.cc index 710bd519bc3d..5cd1249608a2 100644 --- a/solvers/gurobi_solver.cc +++ b/solvers/gurobi_solver.cc @@ -952,7 +952,7 @@ void GurobiSolver::DoSolve2(const MathematicalProgram& prog, const std::optional grb_write = options->template Pop("GRBwrite"); - // Copy the remaining options into model_env. + // Convert the common options into their Gurobi flavor. options->Respell([](const auto& common, auto* respelled) { respelled->emplace("LogToConsole", common.print_to_console ? 1 : 0); if (!common.print_file_name.empty()) { @@ -986,6 +986,11 @@ void GurobiSolver::DoSolve2(const MathematicalProgram& prog, DRAKE_DEMAND(num_threads.has_value()); respelled->emplace("Threads", *num_threads); }); + + // Copy the remaining options into model_env. Set the logging level first, so + // that changes to any of the other options are uniformly logged (or not). + SetOptionOrThrow(model_env, "LogToConsole", + options->Pop("LogToConsole").value_or(0)); options->CopyToCallbacks( [&model_env](const std::string& key, double value) { SetOptionOrThrow(model_env, key, value);