Skip to content

Commit

Permalink
added download of highs binary. And fixed errors in subprocess (#759)
Browse files Browse the repository at this point in the history
* added download of highs binary. And fixed errors in subprocess

* remove the prints. Show available solvers

* workaround to deactivate messages on licenses

* make it compatible with windows

* tests on windows.

* linter

* keep msg=True when detecting solvers since it's blocking the print of available solver.

* more tests

* undo hiding messages

* clean comments
  • Loading branch information
pchtsp authored Jul 12, 2024
1 parent c02692b commit eef6431
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 96 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
5 changes: 5 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# Copyright S.A.Mitchell ([email protected]), 2007-
# Copyright F.Peschiera ([email protected]), 2019-
# See the LICENSE file for copyright information.
2.9.0 2024-07-12
HiGHS available as solver
added HiGHS_CMD to github actions
deactivated warnings on msg=False
minor fixes
2.8.0 2024-01-12
mip start in HiGHS_CMD and SCIP_PY
GUROBI solver with environment handling
Expand Down
2 changes: 1 addition & 1 deletion pulp/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def listSolvers(onlyAvailable=False):
"""
result = []
for s in _all_solvers:
solver = s()
solver = s(msg=False)
if (not onlyAvailable) or solver.available():
result.append(solver.name)
del solver
Expand Down
4 changes: 3 additions & 1 deletion pulp/apis/coin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ def solve_CBC(self, lp, use_mps=True):
"Pulp: Error while trying to execute, use msg=True for more details"
+ self.path
)
if pipe:
try:
pipe.close()
except:
pass
if not os.path.exists(tmpSol):
raise PulpSolverError("Pulp: Error while executing " + self.path)
(
Expand Down
14 changes: 9 additions & 5 deletions pulp/apis/copt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
import warnings

from uuid import uuid4
from .core import sparse, ctypesArrayFill, PulpSolverError
from .core import clock, log

from .core import LpSolver, LpSolver_CMD
from .core import (
sparse,
ctypesArrayFill,
PulpSolverError,
LpSolver,
LpSolver_CMD,
clock,
operating_system,
)
from ..constants import (
LpStatusNotSolved,
LpStatusOptimal,
Expand Down Expand Up @@ -894,7 +899,6 @@ def __init__(
logPath=logPath,
warmStart=warmStart,
)

self.coptenv = coptpy.Envr()
self.coptmdl = self.coptenv.createModel()

Expand Down
3 changes: 2 additions & 1 deletion pulp/apis/gurobi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ def available(self):
# normal execution
return True
# error: we display the gurobi message
warnings.warn(f"GUROBI error: {out}.")
if self.msg:
warnings.warn(f"GUROBI error: {out}.")
return False

def actualSolve(self, lp):
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
7 changes: 1 addition & 6 deletions pulp/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@
from . import constants as const
from . import mps_lp as mpslp

try:
from collections.abc import Iterable
except ImportError:
# python 2.7 compatible
from collections.abc import Iterable

from collections.abc import Iterable
import logging

log = logging.getLogger(__name__)
Expand Down
4 changes: 4 additions & 0 deletions pulp/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@


def pulpTestAll(test_docs=False):
all_solvers = pulp.listSolvers(onlyAvailable=False)
available = pulp.listSolvers(onlyAvailable=True)
print(f"Available solvers: {available}")
print(f"Unavailable solvers: {set(all_solvers) - set(available)}")
runner = unittest.TextTestRunner()
suite_all = get_test_suite(test_docs)
# we run all tests at the same time
Expand Down
Loading

0 comments on commit eef6431

Please sign in to comment.