{"id":3511,"library":"highspy","title":"High-performance Open-source Mixed-Integer Linear Optimization Solver (HiGHS) Python Interface","description":"highspy is a thin set of pybind11 wrappers to HiGHS, a high-performance serial and parallel solver for large-scale sparse linear optimization, convex quadratic programming, and mixed-integer programming problems. It is currently at version 1.14.0 and maintains an active development and release cadence.","status":"active","version":"1.14.0","language":"en","source_language":"en","source_url":"https://github.com/ERGO-Code/HiGHS","tags":["optimization","linear programming","mixed integer programming","LP","MIP","solver","quadratic programming"],"install":[{"cmd":"pip install highspy","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for numerical array operations and data handling.","package":"numpy","optional":false}],"imports":[{"symbol":"Highs","correct":"import highspy\nh = highspy.Highs()"},{"symbol":"HighsLp","correct":"from highspy import HighsLp\nlp = HighsLp()"},{"note":"Enums are accessed via the enum class (e.g., ObjSense) within the highspy module, not directly as module-level constants.","wrong":"highspy.kMaximize","symbol":"ObjSense","correct":"from highspy import ObjSense\nlp.sense_ = ObjSense.kMaximize"}],"quickstart":{"code":"import highspy\nimport numpy as np\n\nh = highspy.Highs()\n\n# Define an LP problem (maximize 8x0 + 10x1 subject to constraints)\nlp = highspy.HighsLp()\nlp.num_col_ = 2\nlp.num_row_ = 2\nlp.sense_ = highspy.ObjSense.kMaximize\nlp.col_cost_ = np.array([8, 10], dtype=np.double)\nlp.col_lower_ = np.array([0, 0], dtype=np.double)\nlp.col_upper_ = np.array([highspy.kHighsInf, highspy.kHighsInf], dtype=np.double)\nlp.row_lower_ = np.array([-highspy.kHighsInf, -highspy.kHighsInf], dtype=np.double)\nlp.row_upper_ = np.array([120, 210], dtype=np.double)\n\n# Constraint matrix A (row-wise in this example for illustration)\n# 0.3*x0 + 0.5*x1 <= 120\n# 0.7*x0 + 0.5*x1 <= 210\nlp.a_matrix_.start_ = np.array([0, 2, 4]) # Column starts (for column-wise storage, but example uses row-wise interpretation)\nlp.a_matrix_.index_ = np.array([0, 1, 0, 1]) # Row indices for each element\nlp.a_matrix_.value_ = np.array([0.3, 0.7, 0.5, 0.5], dtype=np.double)\n\nh.passModel(lp)\n\n# Solve the model\nh.run()\n\n# Extract and print solution\nsolution = h.getSolution()\ninfo = h.getInfo()\nmodel_status = h.getModelStatus()\n\nprint(f\"Model status: {h.modelStatusToString(model_status)}\")\nif model_status == highspy.HighsModelStatus.kOptimal:\n    col_value = list(solution.col_value)\n    print(f\"Optimal objective: {info.obj_val}\")\n    print(f\"x0 = {col_value[0]}, x1 = {col_value[1]}\")\nelse:\n    print(\"No optimal solution found.\")","lang":"python","description":"This quickstart demonstrates how to define and solve a simple Linear Programming (LP) problem using `highspy`. It constructs an `HighsLp` object, populates it with objective coefficients, variable bounds, and constraint matrix, then passes it to the HiGHS solver instance to find an optimal solution."},"warnings":[{"fix":"Convert solution arrays to lists: `col_value = list(solution.col_value)` before accessing elements.","message":"Direct iteration or element-wise access of returned array-like solution values (e.g., `solution.col_value`) can be very slow. It is highly recommended to convert these to Python lists first for efficient access.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If an expression needs to be reused, ensure you are working with a copy or construct expressions explicitly for each use. More robust expression building might be available in newer versions (e.g., `ExprBuilder` mentioned in related discussions).","message":"When constructing linear expressions, the `highs_linear_expression.__add__` method modifies the expression in-place. Reusing an expression object after it has been modified can lead to unexpected and hard-to-debug results.","severity":"gotcha","affected_versions":"Versions prior to 1.14.0, and potentially current if not careful."},{"fix":"Use `h.setOptionValue('log_file', 'your_log_file.txt')` on your `highspy.Highs` instance to specify a log file.","message":"By default, HiGHS C++ logging is duplicated to `Highs.log`. In `highspy`, to redirect logging output to a specific file, you must explicitly set the 'log_file' option.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the documentation of the integrating modeling library. It may require setting an environment variable like `PMIP_HIGHS_LIBRARY` to explicitly point to the HiGHS shared library.","message":"Users integrating `highspy` with other modeling libraries like `python-mip` might encounter `FileNotFoundError: HiGHS not found` even after `highspy` is installed. This suggests a solver discovery issue in the integrating library.","severity":"gotcha","affected_versions":"Observed with `python-mip` v1.9.0 and earlier."},{"fix":"For high-level modeling, prefer `addVariable` and `addConstr` if available in your `highspy` version. For direct interaction with the solver's underlying data structures, use `addCol` and `addRow`.","message":"The `addVar` method within the direct `highspy` modeling interface was noted for clashes and potential confusion with internal methods. A new method, `addVariable`, is being introduced for clearer high-level modeling.","severity":"deprecated","affected_versions":"Versions 1.5.3, 1.7.1.dev1, and potentially others. Users attempting to use `addVar` for high-level modeling might experience issues."}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}