PyPSA / PyPSA/linopy

Mosek output not shown in console when log_fn is set

Open Beginner friendly
#948 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug solver interface
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 master branch 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
Bottleneck==1.6.0 click==8.5.0 cloudpickle==3.1.2 dask==2026.8.0 deprecation==2.1.0 fsspec==2026.7.0 linopy==0.9.1 locket==1.0.0 Mosek==11.2.3 numexpr==2.14.2 numpy==2.5.3 packaging==26.3 pandas==3.0.5 partd==1.4.2 polars==1.44.1 polars-runtime-32==1.44.1 python-dateutil==2.9.0.post0 PyYAML==6.0.3 scipy==1.18.1 six==1.17.0 toolz==1.1.0 tqdm==4.70.0 xarray==2026.7.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.