9.4 Python Console

The MOSEK Python Console is an alternative to the MOSEK Command Line Tool. It can be used for interactive loading, solving and debugging optimization problems stored in files, for example MOSEK task files. It facilitates debugging techniques described in Sec. 9 (Debugging Tutorials).

9.4.1 Usage

The tool requires Python 3. The MOSEK interface for Python must be installed following the installation instructions for Python API or Python Fusion API. The easiest option is

pip install Mosek

The Python Console is contained in the file mosekconsole.py in the folder with MOSEK binaries. It can be copied to an arbitrary location. The file is also available for download here (mosekconsole.py).

To run the console in interactive mode use

python mosekconsole.py

To run the console in batch mode provide a semicolon-separated list of commands as the second argument of the script, for example:

python mosekconsole.py "read data.task.gz; solve form=dual; writesol data"

The script is written using the MOSEK Python API and can be extended by the user if more specific functionality is required. We refer to the documentation of the Python API.

9.4.2 Examples

To read a problem from data.task.gz, solve it, and write solutions to data.sol, data.bas or data.itg:

read data.task.gz; solve; writesol data

To convert between file formats:

read data.task.gz; write data.mps

To set a parameter before solving:

read data.task.gz; param INTPNT_CO_TOL_DFEAS 1e-9; solve"

To list parameter values related to the mixed-integer optimizer in the task file:

read data.task.gz; param MIO

To print a summary of problem structure:

read data.task.gz; anapro

To solve a problem forcing the dual and switching off presolve:

read data.task.gz; solve form=dual presolve=no

To write an infeasible subproblem to a file for debugging purposes:

read data.task.gz; solve; infsub; write inf.opf

9.4.3 Full list of commands

Below is a brief description of all the available commands. Detailed information about a specific command cmd and its options can be obtained with

help cmd
Table 9.1 List of commands of the MOSEK Python Console.

Command

Description

help [command]

Print list of commands or info about a specific command

log filename

Save the session to a file

intro

Print MOSEK splashscreen

testlic

Test the license system

read filename

Load problem from file

reread

Reload last problem file

solve [options]

Solve current problem

write filename

Write current problem to file

param [name [value]]

Set a parameter or get parameter values

paramdef

Set all parameters to default values

paramdiff

Show parameters with non-default values

paramval name

Show available values for a parameter

info [name]

Get an information item

anapro

Analyze problem data

anapro+

Analyze problem data with the internal analyzer

hist

Plot a histogram of problem data

histsol

Plot a histogram of the solutions

spy

Plot the sparsity pattern of the data matrices

truncate epsilon

Truncate small coefficients down to 0

resobj [fac]

Rescale objective by a factor

anasol

Analyze solutions

removeitg

Remove integrality constraints

removecones

Remove all cones and leave just the linear part

delsol

Remove solutions

infsub

Replace current problem with its infeasible subproblem

dualize

Replace current problem with its dual

writesol basename

Write solution(s) to file(s) with given basename

writejsonsol name

Write solutions to JSON file with given name

ptf

Print the PTF representation of the problem

optserver [url]

Use an OptServer to optimize

exit

Leave