8.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. 8 (Debugging Tutorials).

8.4.1 Usage

The tool requires Python 2 or 3. The MOSEK interface for Python must be installed following the installation instructions for Python API or Python Fusion API. In the basic case it should be sufficient to execute the script

python setup.py install --user

in the directory containing the MOSEK Python module.

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.

8.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

8.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 8.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
info [name] Get an information item
anapro Analyze problem data
hist Plot a histogram of problem data
histsol Plot a histogram of the solutions
spy Plot the sparsity pattern of the A matrix
truncate epsilon Truncate small coefficients down to 0
anasol Analyze solutions
removeitg Remove integrality constraints
infsub Replace current problem with its infeasible subproblem
writesol basename Write solution(s) to file(s) with given basename
delsol Remove all solutions from the task
exit Leave