-
Notifications
You must be signed in to change notification settings - Fork 198
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
base: main
Are you sure you want to change the base?
MIP log cleanup #1402
Changes from all commits
a7f5121
27f2973
501220b
9672194
8367299
b865ae9
6d7f0f5
e5ea499
da1015f
87cdf92
6c04ed4
f79029f
ffdc469
e47c61f
5eb9730
739aab2
3b9f99c
ec577e6
2e9059e
4b3a6b6
e7523fd
ae178fb
9e4e2a3
1d30f7f
c542637
3fbee38
1e992c0
651e2ba
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,9 @@ | |
| #include <cstdarg> | ||
| #include <cstdio> | ||
| #include <cstring> | ||
| #include <format> | ||
| #include <string_view> | ||
| #include <utility> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| namespace cuopt::linear_programming::dual_simplex { | ||
|
|
||
|
|
@@ -84,6 +87,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 +144,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 |
|---|---|---|
|
|
@@ -682,12 +682,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); | ||
|
|
||
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: