0

I use Mosek through the cvxpy interface. When I use the verbose option, it shows some nice output, that I would like to further work with. I looked through the parameters in https://docs.mosek.com/latest/pythonapi/parameters.html#doc-sparam-list whether something would store me this output somewhere. The parameter stat_key seemed promising, but it does not work as I thought.

MWE:

import cvxpy as cvx
import mosek
import numpy as np

A = np.random.randint(10, size = (16,32))
b = np.random.randint(10, size = 16)
c = np.random.randint(10, size = 32)

x = cvx.Variable(32, integer = True)
prob = cvx.Problem(cvx.Maximize(c @ x), [A @ x <= b, x >= 0, x <= 10])
prob.solve(solver = cvx.MOSEK, mosek_params={mosek.sparam.stat_key: 'results.txt'}, verbose = True)

expected/wanted behaviour: There should be a file results.txt that contains the line that are printed on the terminal from the verbose option.

observed behaviour: No such file exists.

Hennich
  • 682
  • 3
  • 18
  • It is not possible through cvxpy because it only registers a handler that takes the Mosek log output and prints it to the stdout and nothing else. You need to slightly hack cvxpy source to achieve it. Or work with Mosek directly. The parameter means something else and there is no parameter for what you want. – Michal Adamaszek Jan 10 '23 at 13:37
  • The hack would be to add ``task.linkfiletostream(mosek.streamtype.log, "somename.txt", 0)`` just before ``task.optimize()`` in ``mosek_conif.py``. – Michal Adamaszek Jan 10 '23 at 14:02

0 Answers0