{"id":6724,"library":"mosek","title":"MOSEK Optimization Suite","description":"MOSEK is a high-performance software package for solving large-scale mathematical optimization problems, encompassing linear, quadratic, and conic optimization, as well as mixed-integer programming (LP, QP, SOCP, SDP, MIP, etc.). It provides a Python API, including the lower-level Optimizer API and the object-oriented Fusion API. As a commercial product, it requires a valid license, with free academic and trial licenses available. It follows a major.minor.revision semantic versioning, where major versions may introduce incompatibilities.","status":"active","version":"11.1.11","language":"en","source_language":"en","source_url":"https://www.mosek.com/documentation/","tags":["optimization","solver","linear programming","quadratic programming","conic programming","convex optimization","mixed-integer programming","operations research"],"install":[{"cmd":"pip install mosek","lang":"bash","label":"Install Python API"}],"dependencies":[{"reason":"Required Python version for compatibility.","package":"Python","version":">=3.9, <3.15"},{"reason":"Recommended for efficient data handling, especially with the Fusion API.","package":"NumPy","optional":true},{"reason":"The Python 'mosek' package is an interface to the underlying MOSEK solver, which needs to be installed and licensed separately. The pip package only contains the Python bindings.","package":"MOSEK Optimization Suite (native solver)","optional":false}],"imports":[{"note":"For the Optimizer API, or to access general MOSEK constants and environment.","symbol":"mosek","correct":"import mosek"},{"note":"For the object-oriented Fusion API. The 'pythonic' submodule provides convenience operators.","symbol":"fusion","correct":"import mosek.fusion as msk"}],"quickstart":{"code":"import mosek\nimport os\n\n# Configure MOSEK license path. Replace 'path/to/your/mosek.lic' with actual path.\n# For academic/trial licenses, it often defaults to ~/.mosek/mosek.lic\n# It's recommended to set MOSEKLM_LICENSE_FILE environment variable for production.\n# For quickstart, ensure the license file is accessible or MOSEKLM_LICENSE_FILE is set.\n# os.environ['MOSEKLM_LICENSE_FILE'] = os.environ.get('MOSEKLM_LICENSE_FILE', 'path/to/your/mosek.lic')\n\n# Define a stream printer to capture MOSEK output (optional)\ndef streamprinter(text):\n    # print(text.strip())\n    pass\n\ntry:\n    # Create a MOSEK environment\n    with mosek.Env() as env:\n        # Attach a stream printer to the environment\n        env.set_Stream(mosek.streamtype.log, streamprinter)\n\n        # Create a task for optimization\n        with env.Task() as task:\n            task.set_Stream(mosek.streamtype.log, streamprinter)\n\n            # Problem: Minimize x + y subject to x >= 0, y >= 0, x + y >= 1\n\n            # Append two variables\n            task.appendvars(2)\n            # Set variable bounds to be free initially\n            task.putvarboundlist([0, 1], [mosek.boundkey.fr, mosek.boundkey.fr], [0.0, 0.0], [0.0, 0.0])\n\n            # Append one constraint\n            task.appendcons(1)\n            # Set constraint bound (x + y >= 1)\n            task.putconbound(0, mosek.boundkey.lo, 1.0, 1.0)\n\n            # Set coefficients for constraint (x + y)\n            task.putaij(0, 0, 1.0) # Constraint 0, Variable 0, Coefficient 1.0\n            task.putaij(0, 1, 1.0) # Constraint 0, Variable 1, Coefficient 1.0\n\n            # Set objective coefficients (Minimize x + y)\n            task.putclist([0, 1], [1.0, 1.0])\n            # Set objective sense to minimize\n            task.putobjsense(mosek.objsense.minimize)\n\n            # Solve the problem\n            task.optimize()\n            task.solutionsummary(mosek.streamtype.log)\n\n            # Get and print the solution\n            prosta = task.getprosta(mosek.soltype.itr)\n            if prosta == mosek.prosta.prim_feas_obj_and_dual_feas_obj:\n                xx = [0.0] * 2\n                task.getxx(mosek.soltype.itr, xx)\n                print(f\"Solution: x = {xx[0]}, y = {xx[1]}\")\n            else:\n                print(\"Problem status: \", prosta)\n\nexcept mosek.Error as e:\n    print(f\"MOSEK Error: {e.code} {e.msg}\")\nexcept Exception as e:\n    print(f\"General Error: {e}\")","lang":"python","description":"This quickstart demonstrates a basic Linear Programming (LP) problem using MOSEK's Optimizer API. It initializes a MOSEK environment and task, defines variables and constraints, sets the objective, solves the problem, and retrieves the solution. A MOSEK license is required to run this code; ensure your license file is correctly configured, typically via the `MOSEKLM_LICENSE_FILE` environment variable or by placing `mosek.lic` in `~/.mosek/` (or `%USERPROFILE%\\mosek\\` on Windows)."},"warnings":[{"fix":"Obtain a trial, academic, or commercial license from mosek.com and follow the licensing guide to place the `mosek.lic` file or set the `MOSEKLM_LICENSE_FILE` environment variable.","message":"MOSEK is commercial software and requires a valid license to function. Even after `pip install mosek`, you must obtain and configure a license file (e.g., `mosek.lic`) by placing it in a default location or setting the `MOSEKLM_LICENSE_FILE` environment variable. Without a license, optimization calls will fail.","severity":"breaking","affected_versions":"All versions"},{"fix":"Consult the release notes and interface changes section in the documentation for the specific major version upgrade. Re-evaluate any custom solver parameter settings.","message":"Upgrading to a new major version (e.g., from MOSEK 10 to 11) can introduce API incompatibilities and changes in default parameter behaviors. Users who have tuned solver parameters are recommended to re-evaluate their settings.","severity":"breaking","affected_versions":"Across major versions (e.g., 10.x to 11.x)"},{"fix":"Migrate to using affine conic constraints instead.","message":"In the Optimizer API, conic constraints restricted to `x ∈ K` for a variable `x` are deprecated and will be removed in a future major version.","severity":"deprecated","affected_versions":"MOSEK 11.1.x and later"},{"fix":"Prefer `pip install mosek` for Python API installation.","message":"The MOSEK conda package is deprecated and may be dropped in a future release.","severity":"deprecated","affected_versions":"MOSEK 11.1.x and later"},{"fix":"Reuse the MOSEK environment (or `mosek.fusion.Model` object) for multiple optimizations where possible, as the license token remains checked out within the environment's lifetime. Set `cacheLicense` to 'off' or `Model.putlicensewait` if specific license management is needed.","message":"Repeatedly creating and destroying `mosek.Env()` or `mosek.fusion.Model` objects for many small optimization problems can incur significant performance overhead due to the license checkout system.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid assigning names to model elements if setup time is critical for performance. Names are primarily for debugging and readability.","message":"Using the Fusion API, assigning names to all variables, constraints, and other model elements can substantially increase problem setup time. This overhead should be avoided in time-critical applications.","severity":"gotcha","affected_versions":"All versions using Fusion API"},{"fix":"Ensure that NumPy arrays passed to the MOSEK API have the expected integer data types (typically `int32` for indices, `float64` for numerical data) to avoid unnecessary internal data conversions.","message":"Passing NumPy arrays of incorrect integer types (e.g., `int64` where `int32` is expected, or vice versa) to the MOSEK API will trigger warnings and cause the module to make internal copies, potentially impacting performance.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}