Skip to main content

Analyze numerical issues in linear programs

Project description

Analyze numerical issues in linear programs

This tool helps analyze numerical issues in a linear programming model (LP and MIP). I started developing it will doing research for the REAM Research Lab on the SWITCH Power System Planning Model.

Usage

  1. pip install lp-analyzer
  2. lp-analyzer <path_to_mps_model_file>
  3. The generated output file gives insight into the numerical properties of the model. For example, it outputs the range of the coefficients of each constraint type and each variable type.

See instructions below to learn how to generate a .mps file with Pyomo, Switch or Gurobi.

Detailed guide

What are numerical issues in linear programming?

Linear programming allows us to find optimal solutions to problems by defining problems as a set of linear equations.

Today, there exists numerical solvers that can read millions of these equations and find the optimal solution automatically. For example, Gurobi is one of these solvers.

These millions of equations have numerical coefficients. When these coefficients are too large or too small in magnitude (e.g. 1010 or 10-10), solvers like Gurobi struggle to find the optimal solution. We say that we're encountering numerical issues. This is because such large or small values are challenging to store on a floating-point computer (see here for more info).

One solution to this problem is 'scaling' the equations. Basically if all the numbers are too big we can scale them down without affecting our results.

What does this tool do?

To scale our model, we need to know how big or small or numbers are (to know how much we should scale them by). This tool helps you figure that out! Analyzing the equations by hand is challenging since models can get extremely large. This tool automatically analyzes a linear programming model and returns the range of different coefficients to help you determine which coefficients need scaling.

How to use this tool?

Install it

Simply run pip install lp-analyzer.

If you want to install from the source code, clone the repository to download the code and run within the directory pip install ..

Run it on a .mps file

For now this tool only reads .mps files. This file type stores a linear program model.

Once you have your .mps file simply run:

lp_analyzer path/to/file.mps

The relevant ranges will be automatically be saved to a file! To change the output file use -o output.txt.

Using with Pyomo

If you're trying to use this tool with a Pyomo model you'll first need to generate a .lp file then a .mps file.

First solve the model with keepfiles=True, symbolic_solver_labels=True. For example,

results = solver.solve(model, tee=True, keepfiles=True, symbolic_solver_labels=True)

This will save an .lp file to a temporary directory (as listed in the console output).

Once you have your .lp file, you can use the Gurobi prompt to convert it to an .mps file.

Open the Gurobi prompt (normally just run gurobi), then run the following commands. This will create a model_file.mps file which you can use with this tool (see above).

gurobi> m = read("model_file.lp")
...
gurobi> m = m.presolve()
...
gurobi> m.write("model_file.mps")

The presolve() step is optional, but will remove unnecessary equations making your analysis more relevant. You can read more about presolve() here.

Using with SWITCH

SWITCH is a platform for planning high-renewable power systems that uses linear programming.

The steps to using this library with SWITCH are nearly identical to that of using it with Pyomo. The only difference is you can use the following command to generate the .lp file.

switch solve --solver gurobi -v --keepfiles --tempdir temp --symbolic-solver-labels

This will save the .lp file to the temp folder. To learn more about what each flag does run switch solve -h.

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

lp-analyzer-1.2.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

lp_analyzer-1.2.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file lp-analyzer-1.2.1.tar.gz.

File metadata

  • Download URL: lp-analyzer-1.2.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for lp-analyzer-1.2.1.tar.gz
Algorithm Hash digest
SHA256 8ed62a40cf93b90cc549665bbe6dd0aea6df73c1c4c69ae137021cc924ea6994
MD5 fb126a0d3d9061878960774dc03f9a65
BLAKE2b-256 9e513c5bd5ce0ca42a82da914283451c04b03a7a7e10a1b407e717291009a77c

See more details on using hashes here.

File details

Details for the file lp_analyzer-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: lp_analyzer-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for lp_analyzer-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 21d188d7f5e87e171d8ba1e41a9672621db2aef4936e43dbb69f5ef35f83ae00
MD5 1bc99332089e2bce759da3f07128aa9e
BLAKE2b-256 1bc33131e7f930160faa61043a6eb4398bd6043b2d98af8362a40a9243a7a525

See more details on using hashes here.

Supported by

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