Julia interfaces
This page shows how to use the Julia interface of HPR-LP: run demos, build custom problems, adjust solver settings, and interpret results.
Usage 1: Run LP instances in MPS format
Setting Data and Result Paths
Before running the scripts, please modify run_single_file.jl or run_dataset.jl in the scripts directory to specify the data path and result path according to your setup.
Running a Single Instance
To test the script on a single instance (.mps file):
julia --project scripts/run_single_file.jl
Running All Instances in a Directory
To process all .mps files in a directory:
julia --project scripts/run_dataset.jl
Usage 2: Define Your LP Model in Julia Scripts
Example 1: Build and Export an LP Model Using JuMP
This example shows how to build an LP model in JuMP, export it to MPS format, and solve it with HPR-LP.
julia --project demo/demo_JuMP.jl
The script:
Builds a linear programming (LP) model.
Saves the model as an MPS file.
Uses HPR-LP to solve the LP instance.
Tip: If the model may be infeasible or unbounded, you can use HiGHS to check it.
using JuMP, HiGHS
## read a model from file (or create in other ways)
mps_file_path = "xxx" # your file path
model = read_from_file(mps_file_path)
## set HiGHS as the optimizer
set_optimizer(model, HiGHS.Optimizer)
## solve it
optimize!(model)
Example 2: Define LP instance Directly in Julia
This example shows how to construct and solve a linear programming problem directly in Julia without relying on JuMP.
julia --project demo/demo_Abc.jl
The small LP instance demo_Abc is given by
Note on First-Time Execution Performance
The first run of an instance may feel slow because Julia compiles code on the first execution (JIT compilation).
Tip
Tip for Better Performance:
To reduce repeated compilation overhead, it’s recommended to run scripts from an IDE like VS Code or the Julia REPL in the terminal.
Start Julia REPL with the project environment
julia --project
Then, at the Julia REPL, run demo/demo_Abc.jl (or other scripts):
include("demo/demo_Abc.jl")
CAUTION
If you encounter the error message:
Error: Error during loading of extension AtomixCUDAExt of Atomix, use Base.retry_load_extensions() to retry.
This is usually temporary. Wait a few moments and the extension will load automatically.
Parameters
Below is a list of the parameters in HPR-LP along with their default values and usage:
Parameter |
Default Value |
Description |
|---|---|---|
|
|
Determines if a warm-up phase is performed before main execution. |
|
|
Maximum allowed runtime (seconds) for the algorithm. |
|
|
Stopping tolerance for convergence checks. |
|
|
GPU device number (only relevant if |
|
|
Maximum number of iterations allowed. |
|
|
Number of iterations to check residuals. |
|
|
Whether to apply Ruiz scaling. |
|
|
Whether to use the Pock-Chambolle scaling. |
|
|
Whether to use the scaling for b and c. |
|
|
Whether to use GPU or not. |
|
|
Print the log every |
Result Explanation
After solving an instance, you can access the result variables as shown below:
# Example from /demo/demo_Abc.jl
println("Objective value: ", result.primal_obj)
println("x1 = ", result.x[1])
println("x2 = ", result.x[2])
Category |
Variable |
Description |
|---|---|---|
Iteration Counts |
|
Total number of iterations performed by the algorithm. |
|
Number of iterations required to achieve an accuracy of |
|
|
Number of iterations required to achieve an accuracy of |
|
Time Metrics |
|
Total time in seconds taken by the algorithm. |
|
Time in seconds taken to achieve an accuracy of |
|
|
Time in seconds taken to achieve an accuracy of |
|
|
Time in seconds used by the power method. |
|
Objective Values |
|
The primal objective value obtained. |
|
The gap between the primal and dual objective values. |
|
Residuals |
|
Relative residuals of the primal feasibility, dual feasibility, and duality gap. |
Algorithm Status |
|
The final status of the algorithm:
|
Solution Vectors |
|
The final solution vector x. |
|
The final solution vector y. |
|
|
The final solution vector z. |
That’s it! With these steps you can run demos, build your own LPs, tune solver settings, and interpret results in Julia.