Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyomo/solvers/plugins/solvers/gurobi_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ def _apply_solver(self):
StaleFlagManager.mark_all_as_stale()

if self._tee:
self._solver_model.setParam('OutputFlag', 1)
self._solver_model.setParam('LogToConsole', 1)
else:
self._solver_model.setParam('OutputFlag', 0)
Copy link
Contributor

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

Copy link
Contributor Author

@rschwarz rschwarz Sep 3, 2025

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.

self._solver_model.setParam('LogToConsole', 0)
Copy link
Member

Choose a reason for hiding this comment

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

The following should resolve the test failures

        # We would like to just set OutputFlag to turn off the console
        # log, but that prevents users from using the Gurobi LogFile
        # option (see #3589 / #3716).  BUT just setting LogToConsole
        # triggers Gurobi to write a message to the console.  We will
        # capture that message here:
        with capture_output(capture_fd=True):
            self._solver_model.setParam('LogToConsole', int(bool(self._tee)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is replacing the existing code, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a commit using this version 🤞

(I also found that I had a partial fix locally, which I forgot to push, apparently. I added this as well, but reverted it, for the sake of documenting this option.)


if self._keepfiles:
# Only save log file when the user wants to keep it.
Expand Down
4 changes: 2 additions & 2 deletions pyomo/solvers/tests/checks/test_gurobi_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def setParam(self, param, value):
opt.solve(self.model, options={"MIPFocus": 2})

# Method should not be set again, but MIPFocus was changed.
# OutputFlag is explicitly set on the model.
# LogToConsole is explicitly set on the model.
assert envparams == {"Method": 2, "MIPFocus": 1}
assert modelparams == {"MIPFocus": 2, "OutputFlag": 0}
assert modelparams == {"MIPFocus": 2, "LogToConsole": 0}

# Try an erroneous parameter setting to ensure parameters go through in all
# cases. Expect an error to indicate pyomo tried to set the parameter.
Expand Down
Loading