Skip to content

Commit

Permalink
added download of highs binary. And fixed errors in subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
pchtsp committed Jul 11, 2024
1 parent a812f00 commit e30f027
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ jobs:
# alternatively if: contains(fromJSON("['3.7', '3.8', '3.9', '3.10', '3.11']"), matrix.python-version)
run: |
pip install highspy numpy
- name: Install highspy cmd
if: matrix.os == 'ubuntu-latest'
uses: supplypike/setup-bin@v4
with:
uri: 'https://github.com/JuliaBinaryWrappers/HiGHSstatic_jll.jl/releases/download/HiGHSstatic-v1.7.1%2B0/HiGHSstatic.v1.7.1.x86_64-linux-gnu-cxx11.tar.gz'
subPath: 'bin'
name: 'highs'
version: '1.7.1'
- name: Install coptpy
run: |
pip install coptpy
Expand Down
13 changes: 9 additions & 4 deletions pulp/apis/highs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from typing import List

from .core import LpSolver, LpSolver_CMD, subprocess, PulpSolverError
import os, sys
import os
from .. import constants


Expand Down Expand Up @@ -149,14 +149,19 @@ def actualSolve(self, lp):

with open(tmpOptions, "w") as options_file:
options_file.write("\n".join(file_options))
process = subprocess.run(command, stdout=sys.stdout, stderr=sys.stderr)
# print(command)
process = subprocess.Popen(command, stdout=None, stderr=None)

# HiGHS return code semantics (see: https://github.com/ERGO-Code/HiGHS/issues/527#issuecomment-946575028)
# - -1: error
# - 0: success
# - 1: warning
if process.returncode == -1:
raise PulpSolverError("Error while executing HiGHS")
# process = subprocess.run(command, stdout=sys.stdout, stderr=sys.stderr)
if process.wait() == -1:
raise PulpSolverError(
"Pulp: Error while executing HiGHS, use msg=True for more details"
+ self.path
)

with open(highs_log_file, "r") as log_file:
lines = log_file.readlines()
Expand Down
12 changes: 6 additions & 6 deletions pulp/tests/test_pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,12 +836,11 @@ def test_msg_arg(self):
data = prob.toDict()
var1, prob1 = LpProblem.fromDict(data)
x, y, z, w = (var1[name] for name in ["x", "y", "z", "w"])
if self.solver.name in ["HiGHS"]:
# HiGHS has issues with displaying output in Ubuntu
return
self.solver.msg = True
pulpTestCheck(
prob1, self.solver, [const.LpStatusOptimal], {x: 4, y: -1, z: 6, w: 0}
prob1,
self.solveInst(msg=True),
[const.LpStatusOptimal],
{x: 4, y: -1, z: 6, w: 0},
)

def test_pulpTestAll(self):
Expand Down Expand Up @@ -1278,6 +1277,7 @@ def test_measuring_solving_time(self):
CPLEX_CMD=50,
GUROBI=50,
HiGHS=50,
HiGHS_CMD=50,
)
bins = solver_settings.get(self.solver.name)
if bins is None:
Expand Down Expand Up @@ -1308,7 +1308,7 @@ def test_time_limit_no_solution(self):
print("\t Test time limit with no solution")

time_limit = 1
solver_settings = dict(HiGHS=50, PULP_CBC_CMD=30, COIN_CMD=30)
solver_settings = dict(HiGHS_CMD=50, HiGHS=50, PULP_CBC_CMD=30, COIN_CMD=30)
bins = solver_settings.get(self.solver.name)
if bins is None:
# not all solvers have timeLimit support
Expand Down

0 comments on commit e30f027

Please sign in to comment.