Mosek output not shown in console when log_fn is set
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 257
- Forks
- 87
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 29
Description
Version Checks (indicate both or one)
-
I have confirmed this bug exists on the lastest release of Linopy.
-
I have confirmed this bug exists on the current
masterbranch of Linopy.
Issue Description
[!NOTE]
I've debugged this issue with AI (ChatGPT) and had it write a bug report which I mostly rewrote in my own words below.
I've encountered this bug (or, perhaps, an inconsistency in behaviour across solvers) while running a PyPSA-Eur model with HiGHS and then with Mosek. I like to watch the progress of the solve in order to assess the speed of convergence and diagnose potential pathologies early on, but I noticed that while HiGHS logs both to the console and the log file in parallel, Mosek only streams to the log file.
The problem seems to stem from the difference in how log_fn is handled. The Mosek backend currently does:
if log_fn is not None:
m.linkfiletostream(mosek.streamtype.log, path_to_string(log_fn), 0)
else:
m.set_Stream(mosek.streamtype.log, sys.stdout.write)
Therefore, when log_fn is given, the Mosek log stream is connected exclusively to the file and no stdout stream is attached. By contrast, the HiGHS backend sets its log_file option without disabling console logging.
Reproducible Example
import linopy
m = linopy.Model()
x = m.add_variables(lower=0, name="x")
y = m.add_variables(lower=0, name="y")
m.add_constraints(x + y >= 1)
m.add_objective(x + 2 * y)
m.solve(
solver_name="mosek",
io_api="direct",
log_fn="mosek.log",
MSK_IPAR_LOG=10,
MSK_IPAR_LOG_INTPNT=1
)
Expected Behavior
Setting log_fn should not disable Mosek's progress logging in the console.
Mosek should behave consistently with HiGHS: solver output should be displayed in the console while also being written to log_fn.
Installed Versions
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in linopy/solvers.py around the Mosek backend at lines 3705-3708, then compare its log_fn handling with the HiGHS backend. Run the provided Model example with Mosek and verify that solver output appears in the console while still being written to mosek.log.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100