lp-analyzer


Namelp-analyzer JSON
Version 1.2.1 PyPI version JSON
download
home_page
SummaryAnalyze numerical issues in linear programs
upload_time2023-01-05 00:02:23
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT License Copyright (c) 2021 Martin Staadecker Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords linear programming numerical issues
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://patyhidalgo.github.io/)
on the [SWITCH](http://switch-model.org/) 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](https://en.wikipedia.org/wiki/MPS_(format)) with Pyomo, Switch or Gurobi.

## Detailed guide

### What are numerical issues in linear programming?

[Linear programming](https://en.wikipedia.org/wiki/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](https://www.gurobi.com/) 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. 10<sup>10</sup>
or 10<sup>-10</sup>), 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](https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf) 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](https://en.wikipedia.org/wiki/MPS_(format)). 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](https://www.gurobi.com/documentation/9.1/refman/presolve2.html).

#### Using with SWITCH

[SWITCH](https://github.com/switch-model/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`.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "lp-analyzer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "linear programming,numerical issues",
    "author": "",
    "author_email": "Martin Staadecker <machstg@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/9e/51/3c5bd5ce0ca42a82da914283451c04b03a7a7e10a1b407e717291009a77c/lp-analyzer-1.2.1.tar.gz",
    "platform": null,
    "description": "# Analyze numerical issues in linear programs\r\n\r\nThis tool helps analyze numerical issues in a linear programming\r\nmodel (LP and MIP). I started developing it will doing research for the [REAM Research Lab](https://patyhidalgo.github.io/)\r\non the [SWITCH](http://switch-model.org/) Power System Planning\r\nModel.\r\n\r\n\r\n## Usage\r\n\r\n1. `pip install lp-analyzer`\r\n2. `lp-analyzer <path_to_mps_model_file>`\r\n3. The generated output file gives\r\ninsight into the numerical properties of the model. For example, it outputs the range of the coefficients\r\nof each constraint type and each variable type.\r\n\r\nSee instructions below to learn how to generate a [`.mps` file](https://en.wikipedia.org/wiki/MPS_(format)) with Pyomo, Switch or Gurobi.\r\n\r\n## Detailed guide\r\n\r\n### What are numerical issues in linear programming?\r\n\r\n[Linear programming](https://en.wikipedia.org/wiki/Linear_programming) allows us to find optimal solutions\r\nto problems by defining problems as a set of linear equations.\r\n\r\nToday, there exists numerical solvers that can read millions\r\nof these equations and find the optimal solution automatically. \r\nFor example, [Gurobi](https://www.gurobi.com/) is one of these solvers.\r\n\r\nThese millions of equations have numerical coefficients. When these\r\ncoefficients are too large or too small in magnitude (e.g. 10<sup>10</sup>\r\nor 10<sup>-10</sup>), solvers like Gurobi struggle to find\r\nthe optimal solution. We say that we're encountering numerical\r\nissues. This is because such large or small\r\nvalues are challenging to store on a floating-point computer\r\n(see [here](https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf) for more info).\r\n\r\nOne solution to this problem is 'scaling' the equations.\r\nBasically if all the numbers are too big we can scale them down\r\nwithout affecting our results.\r\n\r\n### What does this tool do?\r\n\r\nTo scale our model, we need to know how big or small or numbers are\r\n(to know how much we should scale them by). This tool\r\nhelps you figure that out! Analyzing the equations by hand\r\nis challenging since models can get extremely large. This\r\ntool automatically analyzes a linear programming model\r\nand returns the range of different coefficients\r\n to help you determine which coefficients need scaling.\r\n\r\n### How to use this tool?\r\n\r\n#### Install it\r\n\r\nSimply run `pip install lp-analyzer`.\r\n\r\nIf you want to install from the source code, clone the repository to download the code\r\nand run within the directory `pip install .`.\r\n\r\n#### Run it on a `.mps` file\r\n\r\nFor now this tool only reads [`.mps` files](https://en.wikipedia.org/wiki/MPS_(format)). This\r\nfile type stores a linear program model.\r\n\r\nOnce you have your `.mps` file simply run:\r\n\r\n`lp_analyzer path/to/file.mps`\r\n\r\nThe relevant ranges will be automatically be saved to a file! \r\nTo change the output file use `-o output.txt`.\r\n\r\n#### Using with Pyomo\r\n\r\nIf you're trying to use\r\nthis tool with a Pyomo model you'll first need to generate\r\na `.lp` file then a `.mps` file. \r\n\r\nFirst solve the model with `keepfiles=True, symbolic_solver_labels=True`. For example,\r\n\r\n```\r\nresults = solver.solve(model, tee=True, keepfiles=True, symbolic_solver_labels=True)\r\n```\r\n\r\nThis will save an `.lp` file to a temporary directory (as listed in the console output).\r\n\r\n\r\nOnce you have your `.lp` file, you can use the Gurobi\r\nprompt to convert it to an `.mps` file.\r\n\r\nOpen the Gurobi prompt (normally just run `gurobi`),\r\nthen run the following commands. This will create a\r\n`model_file.mps` file which you can use with this tool (see above).\r\n\r\n```\r\ngurobi> m = read(\"model_file.lp\")\r\n...\r\ngurobi> m = m.presolve()\r\n...\r\ngurobi> m.write(\"model_file.mps\")\r\n```\r\nThe `presolve()` step is optional, but will remove\r\nunnecessary equations making your analysis more relevant.\r\nYou can read more about `presolve()` [here](https://www.gurobi.com/documentation/9.1/refman/presolve2.html).\r\n\r\n#### Using with SWITCH\r\n\r\n[SWITCH](https://github.com/switch-model/switch) \r\nis a platform for planning high-renewable power systems\r\nthat uses linear programming.\r\n\r\nThe steps to using this library with SWITCH are nearly identical to that of using it with Pyomo.\r\nThe only difference is you can use the following command to generate the `.lp` file.\r\n\r\n`switch solve --solver gurobi -v --keepfiles --tempdir temp --symbolic-solver-labels`\r\n\r\nThis will save the `.lp` file to the `temp` folder. \r\nTo learn more about what each flag does run `switch solve -h`.\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2021 Martin Staadecker  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Analyze numerical issues in linear programs",
    "version": "1.2.1",
    "split_keywords": [
        "linear programming",
        "numerical issues"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1bc33131e7f930160faa61043a6eb4398bd6043b2d98af8362a40a9243a7a525",
                "md5": "1bc99332089e2bce759da3f07128aa9e",
                "sha256": "21d188d7f5e87e171d8ba1e41a9672621db2aef4936e43dbb69f5ef35f83ae00"
            },
            "downloads": -1,
            "filename": "lp_analyzer-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1bc99332089e2bce759da3f07128aa9e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 12949,
            "upload_time": "2023-01-05T00:02:21",
            "upload_time_iso_8601": "2023-01-05T00:02:21.594567Z",
            "url": "https://files.pythonhosted.org/packages/1b/c3/3131e7f930160faa61043a6eb4398bd6043b2d98af8362a40a9243a7a525/lp_analyzer-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e513c5bd5ce0ca42a82da914283451c04b03a7a7e10a1b407e717291009a77c",
                "md5": "fb126a0d3d9061878960774dc03f9a65",
                "sha256": "8ed62a40cf93b90cc549665bbe6dd0aea6df73c1c4c69ae137021cc924ea6994"
            },
            "downloads": -1,
            "filename": "lp-analyzer-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "fb126a0d3d9061878960774dc03f9a65",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 13241,
            "upload_time": "2023-01-05T00:02:23",
            "upload_time_iso_8601": "2023-01-05T00:02:23.632316Z",
            "url": "https://files.pythonhosted.org/packages/9e/51/3c5bd5ce0ca42a82da914283451c04b03a7a7e10a1b407e717291009a77c/lp-analyzer-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-05 00:02:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "lp-analyzer"
}
        
Elapsed time: 0.05566s