Package: lp-analyzer
Analyze numerical issues in linear programsThis tool helps analyze numerical issues in a linear programming
model (LP and MIP). I started developing it will doing research for theREAM Research Labon theSWITCHPower System Planning
Model.Usagepip install lp-analyzerlp-analyzer <path_to_mps_model_file>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.mpsfilewith Pyomo, Switch or Gurobi.Detailed guideWhat are numerical issues in linear programming?Linear programmingallows 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,Gurobiis one of these solvers.These millions of equations have numerical coefficients. When these
coefficients are too large or too small in magnitude (e.g. 1010or 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
(seeherefor 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 itSimply runpip install lp-analyzer.If you want to install from the source code, clone the repository to download the code
and run within the directorypip install ..Run it on a.mpsfileFor now this tool only reads.mpsfiles. This
file type stores a linear program model.Once you have your.mpsfile simply run:lp_analyzer path/to/file.mpsThe relevant ranges will be automatically be saved to a file!
To change the output file use-o output.txt.Using with PyomoIf you're trying to use
this tool with a Pyomo model you'll first need to generate
a.lpfile then a.mpsfile.First solve the model withkeepfiles=True, symbolic_solver_labels=True. For example,results = solver.solve(model, tee=True, keepfiles=True, symbolic_solver_labels=True)This will save an.lpfile to a temporary directory (as listed in the console output).Once you have your.lpfile, you can use the Gurobi
prompt to convert it to an.mpsfile.Open the Gurobi prompt (normally just rungurobi),
then run the following commands. This will create amodel_file.mpsfile 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")Thepresolve()step is optional, but will remove
unnecessary equations making your analysis more relevant.
You can read more aboutpresolve()here.Using with SWITCHSWITCHis 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.lpfile.switch solve --solver gurobi -v --keepfiles --tempdir temp --symbolic-solver-labelsThis will save the.lpfile to thetempfolder.
To learn more about what each flag does runswitch solve -h.