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 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.
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
Command |
Description |
---|---|
|
Print list of commands or info about a specific command |
|
Save the session to a file |
|
Print MOSEK splashscreen |
|
Test the license system |
|
Load problem from file |
|
Reload last problem file |
|
Solve current problem |
|
Write current problem to file |
|
Set a parameter or get parameter values |
|
Set all parameters to default values |
|
Show parameters with non-default values |
|
Show available values for a parameter |
|
Get an information item |
|
Analyze problem data |
|
Analyze problem data with the internal analyzer |
|
Plot a histogram of problem data |
|
Plot a histogram of the solutions |
|
Plot the sparsity pattern of the data matrices |
|
Truncate small coefficients down to 0 |
|
Rescale objective by a factor |
|
Analyze solutions |
|
Remove integrality constraints |
|
Remove all cones and leave just the linear part |
|
Remove solutions |
|
Replace current problem with its infeasible subproblem |
|
Replace current problem with its dual |
|
Write solution(s) to file(s) with given basename |
|
Write solutions to JSON file with given name |
|
Print the PTF representation of the problem |
|
Use an OptServer to optimize |
|
Leave |