-
Notifications
You must be signed in to change notification settings - Fork 557
Set LogToConsole instead of OutputFlag to handle "tee" #3716
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?
Conversation
In Gurobi, there are three parameters related to logging: LogToConsole is a boolean flag that toggles whether the solver output is logged to the console. (This fits the intention behind setting `tee` in Pyomo.) LogFile is a string that refers to a file name. If non-empty, solver output will be appended to that file. Finally, OutputFlag is a combination of the two: If set to 0, both LogToConsole is set to 0, as well as LogFile set to an empty string. In the old implementation, if a user has already specified a LogFile via the `options`, but then calls `solve(tee=False)`, the log files will not be written. This change makes sure that `tee` only affects what happens to the console. Only GurobiDirect and the derived GurobiPersistent have this logic implemented that way. For the `appsi_gurobi` implementation, `tee` already had no effect on what happened with log files.
There is still one annoying aspect, even after this change, which is that the line I think this can be improved by only calling The Gurobi-related tests pass locally for me, but I think there are some failing checks on the |
self._solver_model.setParam('OutputFlag', 1) | ||
self._solver_model.setParam('LogToConsole', 1) | ||
else: | ||
self._solver_model.setParam('OutputFlag', 0) |
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 should this be the new default ? It seems that what you want can be achieved by adding LogToConsole=1 to the params you pass in the inputs
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.
No, I actually want (in this case) LogToConsole=0
, which is implied by OutputFlag=0
, but the latter also disables writing to log files.
But I want to be able to have all 4 combinations of console and log files for different use cases.
My understand was that the tee
option refers to what is shown on the console, so it should not interfere with log files, which OutputFlag
does.
Conditionally calling To fix that problem (for me), I had to set Thus, no more changes are planned from my side on this. |
I looked into the failing tests, and apparently many of them fail because the log file now contains the additional line I do not know how to avoid that, but have accepted it in our application. Maybe temporarily setting |
Fixes #3589
Summary/Motivation:
In Gurobi, there are three parameters related to logging:
LogToConsole is a boolean flag that toggles whether the solver output is logged to the console. (This fits the intention behind setting
tee
in Pyomo.)LogFile is a string that refers to a file name. If non-empty, solver output will be appended to that file.
Finally, OutputFlag is a combination of the two: If set to 0, both LogToConsole is set to 0, as well as LogFile set to an empty string.
Changes proposed in this PR:
options
, but then callssolve(tee=False)
, the log files will not be written. This change makes sure thattee
only affects what happens to the console.Other notes
By the way: Only GurobiDirect and the derived GurobiPersistent have this logic implemented that way. For the
appsi_gurobi
implementation,tee
already had no effect on what happened with log files.Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: