Skip to content

Mosek output not shown in console when log_fn is set #948

Description

@mgrabovsky

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

Details 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions