Skip to content

Commit

Permalink
highs_setup: Fix HiGHS automated setup issue
Browse files Browse the repository at this point in the history
  • Loading branch information
stroitzsch committed Oct 9, 2023
1 parent 3f99eee commit 6236317
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
35 changes: 1 addition & 34 deletions development_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import pathlib
import subprocess
import sys
import tarfile

import requests

submodules = [
"cobmo",
Expand Down Expand Up @@ -49,37 +46,7 @@ def main():
# Install HiGHS solver.
if run_all or run_highs:
print("Installing HiGHS solver.")
# Make HiGHS directory.
(base_path / "highs").mkdir(exist_ok=True)
# Construct HiGHS binary download URL.
base_url = "https://github.com/JuliaBinaryWrappers/HiGHSstatic_jll.jl/releases/download/"
version_string = "HiGHSstatic-v1.2.2%2B0/HiGHSstatic.v1.2.2"
if sys.platform == "win32":
architecture_string = "x86_64-w64-mingw32"
elif sys.platform == "darwin":
architecture_string = "x86_64-apple-darwin"
else:
architecture_string = "x86_64-linux-gnu-cxx11"
url = f"{base_url}{version_string}.{architecture_string}.tar.gz"
# Download and unpack HiGHS binary files.
try:
with requests.get(url, stream=True) as request:
request.raise_for_status()
with open(base_path / "highs" / "highs.tar.gz", "wb") as file:
for chunk in request.iter_content(chunk_size=10240):
file.write(chunk)
with tarfile.open(base_path / "highs" / "highs.tar.gz") as file:
file.extractall(base_path / "highs")
# Remove downloaded archive file.
(base_path / "highs" / "highs.tar.gz").unlink()
except requests.ConnectionError:
# Soft-fail on download connection errors.
print(
"WARNING: HiGHS solver could not be installed automatically. "
"Please configure optimization solver for MESMO manually."
)
else:
print("Successfully installed HiGHS solver.")
subprocess.check_call([sys.executable, "-m", "poetry", "run", "python", f"{base_path / 'highs_setup.py'}"])


if __name__ == "__main__":
Expand Down
48 changes: 48 additions & 0 deletions highs_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""HiGHS solver setup script."""

import pathlib
import sys
import tarfile

import requests

# Get repository base path.
base_path = pathlib.Path(__file__).parent.absolute()


def main():
# Make HiGHS directory.
(base_path / "highs").mkdir(exist_ok=True)
# Construct HiGHS binary download URL.
base_url = "https://github.com/JuliaBinaryWrappers/HiGHSstatic_jll.jl/releases/download/"
version_string = "HiGHSstatic-v1.2.2%2B0/HiGHSstatic.v1.2.2"
if sys.platform == "win32":
architecture_string = "x86_64-w64-mingw32"
elif sys.platform == "darwin":
architecture_string = "x86_64-apple-darwin"
else:
architecture_string = "x86_64-linux-gnu-cxx11"
url = f"{base_url}{version_string}.{architecture_string}.tar.gz"
# Download and unpack HiGHS binary files.
try:
with requests.get(url, stream=True) as request:
request.raise_for_status()
with open(base_path / "highs" / "highs.tar.gz", "wb") as file:
for chunk in request.iter_content(chunk_size=10240):
file.write(chunk)
with tarfile.open(base_path / "highs" / "highs.tar.gz") as file:
file.extractall(base_path / "highs")
# Remove downloaded archive file.
(base_path / "highs" / "highs.tar.gz").unlink()
except requests.ConnectionError:
# Soft-fail on download connection errors.
print(
"WARNING: HiGHS solver could not be installed automatically. "
"Please configure optimization solver for MESMO manually."
)
else:
print("Successfully installed HiGHS solver.")


if __name__ == "__main__":
main()

0 comments on commit 6236317

Please sign in to comment.