Skip to content

linear_solver: implement logcallback for HiGHS#5023

Open
kiijeonghoo wants to merge 1 commit intogoogle:mainfrom
kiijeonghoo:highs-logcallback
Open

linear_solver: implement logcallback for HiGHS#5023
kiijeonghoo wants to merge 1 commit intogoogle:mainfrom
kiijeonghoo:highs-logcallback

Conversation

@kiijeonghoo
Copy link

implement logcallback for HiGHS solver by calling setLogCalllback in Java/Python

if (request->enable_internal_solver_output()) {
highs.setOptionValue("log_to_console", true);
highs.setOptionValue("output_flag", true);
if (logging_callback != nullptr && *logging_callback) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why setup the logging callback only when the solver.enable_output(True) aka inside the if ?
I mean user may want to enable logging callback and still have no trace on the stdout/stderr i.e. both features (console output and logging callback) are orthogonals imho...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: for the sat solver we have:

SolverLogger* logger = sat_model.GetOrCreate<SolverLogger>();
if (logging_callback != nullptr) {
logger->AddInfoLoggingCallback(logging_callback);
}
logger->EnableLogging(params.log_search_progress());
logger->SetLogToStdOut(params.log_to_stdout());

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, let me update

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the HiGHS IO design

  • it seems only when the solver.enable_output(True), the log can be print;
  • and only logging callback OR stdout is chosen;

HighsIO

void highsLogUser(const HighsLogOptions& log_options_, const HighsLogType type,
                  const char* format, ...) {
  if (!*log_options_.output_flag ||
      (log_options_.log_stream == NULL && !*log_options_.log_to_console))
    return;
   //...

  const bool use_log_callback =
      log_options_.user_log_callback ||
      (log_options_.user_callback && log_options_.user_callback_active);
      
  if (!use_log_callback) {
    // Write to log file stream unless it is NULL
    if (log_options_.log_stream) {
       // ... fprintf(log_options_.log_stream ...
    }
    // Write to stdout unless log file stream is stdout
    if (*log_options_.log_to_console && log_options_.log_stream != stdout) {
       // ... fprintf(stdout ...
    }
  } else { 
    // callback
    // ...
    if (log_options_.user_log_callback) {
      log_options_.user_log_callback(...);
    }
    // ...
  }

So, do you have any suggestion? @Mizux

@Mizux Mizux added Feature Request Missing Feature/Wrapper Solver: HiGHS Issue specific to EDU HiGHS labels Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Request Missing Feature/Wrapper Solver: HiGHS Issue specific to EDU HiGHS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants