-
Notifications
You must be signed in to change notification settings - Fork 219
MIP log cleanup #1402
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
MIP log cleanup #1402
Changes from all commits
e2d8add
7b2d92b
9489191
dad242a
3056ba2
83d60b9
9cd175e
88299ef
c4595f9
43e87c2
5ffd98e
459d9f3
aaf3efd
333723a
dfe3416
4970167
dfdb29e
b2bafe6
63940b6
78eaa87
38bd283
5478c7f
e7426df
bbab9ee
05b929d
500b4e6
6e22eb2
b3850eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| #include <cstdarg> | ||
| #include <cstdio> | ||
| #include <cstring> | ||
| #include <format> | ||
| #include <utility> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| namespace cuopt::mathematical_optimization::simplex { | ||
|
|
||
|
|
@@ -84,6 +86,29 @@ class logger_t { | |
| } | ||
| } | ||
|
|
||
| template <typename... Args> | ||
| void print_format(std::format_string<Args...> fmt, Args&&... args) | ||
| { | ||
| if (log) { | ||
| std::string msg = std::format(fmt, std::forward<Args>(args)...); | ||
| if (log_to_console) { | ||
| #ifdef CUOPT_LOG_ACTIVE_LEVEL | ||
| std::string msg_no_newline = msg; | ||
| if (msg_no_newline.size() > 0 && msg.ends_with("\n")) { msg_no_newline.pop_back(); } | ||
|
|
||
| CUOPT_LOG_INFO("%s%s", log_prefix.c_str(), msg_no_newline.c_str()); | ||
| #else | ||
| std::printf("%s", msg.c_str()); | ||
| fflush(stdout); | ||
| #endif | ||
| } | ||
| if (log_to_file && log_file != nullptr) { | ||
| std::fprintf(log_file, "%s", msg.c_str()); | ||
| fflush(log_file); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If all logs are ported. We can remove debug and printf now, so that we have a single logging mechanism.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept the old log calls to avoid too many code changes. In terms of consistency, it would be best if we just use the new ones. |
||
| void debug([[maybe_unused]] const char* fmt, ...) | ||
| { | ||
| if (log) { | ||
|
|
@@ -118,6 +143,28 @@ class logger_t { | |
| } | ||
| } | ||
|
|
||
| template <typename... Args> | ||
| void debug_format(std::format_string<Args...> fmt, Args&&... args) | ||
| { | ||
| if (log) { | ||
| std::string msg = std::format(fmt, std::forward<Args>(args)...); | ||
| if (log_to_console) { | ||
| #ifdef CUOPT_LOG_DEBUG | ||
| std::string msg_no_newline = msg; | ||
| if (msg_no_newline.size() > 0 && msg.ends_with("\n")) { msg_no_newline.pop_back(); } | ||
| CUOPT_LOG_TRACE("%s%s", log_prefix.c_str(), msg_no_newline.c_str()); | ||
| #else | ||
| std::printf("%s", msg.c_str()); | ||
| fflush(stdout); | ||
| #endif | ||
| } | ||
| if (log_to_file && log_file != nullptr) { | ||
| std::fprintf(log_file, "%s", msg.c_str()); | ||
| fflush(log_file); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bool log; | ||
| bool log_to_console; | ||
| std::string log_prefix; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -683,12 +683,12 @@ third_party_presolve_result_t<i_t, f_t> third_party_presolve_t<i_t, f_t>::apply( | |
|
|
||
| papilo::Problem<f_t> papilo_problem = build_papilo_problem(op_problem, category, maximize_); | ||
|
|
||
| CUOPT_LOG_INFO("Original problem: %d constraints, %d variables, %d nonzeros", | ||
| papilo_problem.getNRows(), | ||
| papilo_problem.getNCols(), | ||
| papilo_problem.getConstraintMatrix().getNnz()); | ||
| CUOPT_LOG_DEBUG("Original problem: %d constraints, %d variables, %d nonzeros", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already log the dimensions of the problems in another place. This is duplicated info |
||
| papilo_problem.getNRows(), | ||
| papilo_problem.getNCols(), | ||
| papilo_problem.getConstraintMatrix().getNnz()); | ||
|
|
||
| CUOPT_LOG_INFO("Calling Papilo presolver (git hash %s)", PAPILO_GITHASH); | ||
| CUOPT_LOG_INFO("\nRunning Papilo presolve (git hash %s)", PAPILO_GITHASH); | ||
| if (category == problem_category_t::MIP) { dual_postsolve = false; } | ||
| papilo::Presolve<f_t> papilo_presolver; | ||
| set_presolve_methods(papilo_presolver, category, dual_postsolve); | ||
|
|
@@ -735,7 +735,7 @@ third_party_presolve_result_t<i_t, f_t> third_party_presolve_t<i_t, f_t>::apply( | |
|
|
||
| // Check if presolve found the optimal solution (problem fully reduced) | ||
| if (papilo_problem.getNRows() == 0 && papilo_problem.getNCols() == 0) { | ||
| CUOPT_LOG_INFO("Optimal solution found during presolve"); | ||
| status = third_party_presolve_status_t::OPTIMAL; | ||
| } | ||
|
|
||
| auto opt_problem = build_optimization_problem<i_t, f_t>( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this log? I think running ... logs are unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly for separating between parts of the solver. Otherwise, we will have only these lines:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Running" logs provide valuable info on when a task is started. This allows users (and developers) to identify if a significant amount of time is spent in a particular task.