Skip to main content

Model analysis tools for explaining ill-conditioning, analyzing solutions, and scaling problems.

Project description

PyPI Documentation Status

Gurobi Model Analyzer

Gurobi Model Analyzer is an open-source python package that provides detailed analysis of model solutions and model characteristics. It consists of a results_analyzer module that calculates explanations of ill-conditioned basis matrices and a solcheck module that analysizes a given solution.

Documentation

The latest user manual is available on readthedocs.

Contact us

For questions related to using Gurobi Model Analyzer, please use Gurobi's Forum.

For reporting bugs, issues, and feature requests please open an issue.

If you encounter issues with Gurobi or gurobipy please contact Gurobi Support.

Installation

Dependencies

  • Python >= 3.10
  • numpy >= 1.21.5 (although earlier versions compatible with python 3.7 will probably work).
  • questionary for the (optional) interactive version

Pip installation

The easiest way to install gurobi-modelanalyzer is using pip in a virtual environment:

(.venv) pip install gurobi-modelanalyzer

This will also install the numpy and gurobipy dependencies. One of the advanced functions makes use of matplotlib; if you haven't already installed that and plan to use this function (matrix_bitmap), you can either install the matplotlib package directly, or install it with the gurobi-modelanalyzer package via "pip install gurobi-modelanalyzer matplotlib".

Please note that gurobipy is commercial software and requires a license. When installed via pip or conda, gurobipy ships with a free license for testing and can only solve models of limited size.

Example usage

Using the explainer functions

import gurobipy as gp
import gurobi_modelanalyzer as gma

model = gp.read("myillconditionedmodel.mps")
model.optimize()
gma.kappa_explain(model)

# row-based explanation (default)
gma.kappa_explain(model, expltype="ROWS")

# column-based explanation
gma.kappa_explain(model, expltype="COLS")

# custom output file name
gma.kappa_explain(model, filename="myname.lp")

# angle-based explanation (only looks for pairs of rows or columns
# that cause ill-conditioning.
gma.angle_explain(model)

Use help(gma.kappa_explain) or help(gma.angle_explain) for information on more advanced usage.

Using the solution checker

Testing a suboptimal solution

import gurobipy as gp
import gurobi_modelanalyzer as gma

m = gp.read("examples/data/afiro.mps")

sol = {m.getVarByName("X01"): 78, m.getVarByName("X22"): 495}
sc = gma.SolCheck(m)

sc.test_sol(sol)
print(f"Solution Status: {sc.Status}")
sc.optimize()
for v in sol.keys():
    print(f"{v.VarName}: Fixed value: {sol[v]}, Computed value: {v.X}")

Testing an infeasible solution

m = gp.read("examples/data/misc07.mps")

sol = {m.getVarByName("COL260"): 2400.5}
sc = gma.sol_check(m)

sc.test_sol(sol)

print(f"Solution Status: {sc.Status}")
sc.inf_repair()
for c in m.getConstrs():
    if abs(c._Violation) > 0.0001:
        print(f"{c.ConstrName}: RHS: {c.RHS}, Violation: {c._Violation}")

Getting a Gurobi License

Alternatively to the bundled limited license, there are licenses that can handle models of all sizes.

As a student or staff member of an academic institution, you qualify for a free, full-product license. For more information, see:

For a commercial evaluation, you can request an evaluation license.

Other useful resources to get started:

Development

We value any level of experience in using Gurobi Model Analyzer and would like to encourage you to contribute directly to this project. Please see the Contributing Guide for more information.

Running the tests

Install the package and execute the unit tests from the project root:

python -m pip install .
python -m unittest discover -v

This runs all tests under the tests/ directory.

Submitting a Pull Request

Before opening a Pull Request, have a look at the full Contributing page to make sure your code complies with our guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gurobi_modelanalyzer-3.0.0a1.tar.gz (3.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gurobi_modelanalyzer-3.0.0a1-py3-none-any.whl (64.1 kB view details)

Uploaded Python 3

File details

Details for the file gurobi_modelanalyzer-3.0.0a1.tar.gz.

File metadata

  • Download URL: gurobi_modelanalyzer-3.0.0a1.tar.gz
  • Upload date:
  • Size: 3.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for gurobi_modelanalyzer-3.0.0a1.tar.gz
Algorithm Hash digest
SHA256 7b8cd537a306ace45aadf7e5ff1e7a939370b4772fefd50ad154eac6f9c5e203
MD5 fc3d507031f7231616cf5a741cdc12f9
BLAKE2b-256 b7a0d5a2250641983eeb1ba7f6fcd778332624b118947aec66e59f6346d46266

See more details on using hashes here.

File details

Details for the file gurobi_modelanalyzer-3.0.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for gurobi_modelanalyzer-3.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 adefe2277be45b8bef763cb53c1b7d647b582fc9b0abc97f01b9711b00016814
MD5 d4a9732708d140838e5867066cf9ce68
BLAKE2b-256 093386a1ac2817029bb5baf314aafd41d422c6e425f67dff73652d3d736ba186

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page