Skip to content

Commit

Permalink
Add script to setup wheel building
Browse files Browse the repository at this point in the history
  • Loading branch information
tlestang committed Mar 17, 2020
1 parent 630f023 commit ce8f0ea
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ cmake_install.cmake


third-party/pybind11

# Build dependencies/
KLU_module_deps
93 changes: 93 additions & 0 deletions scripts/setup_KLU_module_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import os
import subprocess
import tarfile
import wget


def download_extract_library(url, directory):
# Download and extract archive at url
archive = wget.download(url, out=directory)
tar = tarfile.open(archive)
tar.extractall(directory)


# First check requirements: make and cmake
try:
subprocess.run(["make", "--version"])
except OSError:
raise RuntimeError("Make must be installed.")
try:
subprocess.run(["cmake", "--version"])
except OSError:
raise RuntimeError("CMake must be installed.")

# Get abs path to dir containing "scripts/"
# Likely PyBaMM/
parent_dir = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
directory = os.path.join(parent_dir, "KLU_module_deps")
if not os.path.exists(directory):
os.makedirs(directory)

# Download SuiteSparse
suitesparse_url = (
"https://github.com/DrTimothyAldenDavis/" + "SuiteSparse/archive/v5.6.0.tar.gz"
)
download_extract_library(suitesparse_url, directory)

# The SuiteSparse KLU module has 4 dependencies:
# - suitesparseconfig
# - AMD
# - COLAMD
# - BTF
suitesparse_src = os.path.join(directory, "SuiteSparse-5.6.0")
print("-" * 10, "Building SuiteSparse_config", "-" * 40)
make_cmd = ["make"]
build_dir = os.path.join(suitesparse_src, "SuiteSparse_config")
subprocess.run(make_cmd, cwd=build_dir)

print("-" * 10, "Building SuiteSparse KLU module dependencies", "-" * 40)
make_cmd = ["make", "library"]
for libdir in ["AMD", "COLAMD", "BTF"]:
build_dir = os.path.join(suitesparse_src, libdir)
subprocess.run(make_cmd, cwd=build_dir)

print("-" * 10, "Building SuiteSparse KLU module", "-" * 40)
build_dir = os.path.join(suitesparse_src, "KLU")
subprocess.run(make_cmd, cwd=build_dir)

# Download SUNDIALS
sundials_url = (
"https://computing.llnl.gov/" + "projects/sundials/download/sundials-5.0.0.tar.gz"
)
download_extract_library(sundials_url, directory)

sundials_inst = "../sundials5"
cmake_args = [
"-DLAPACK_ENABLE=ON",
"-DSUNDIALS_INDEX_SIZE=32",
"-DBUILD_ARKODE:BOOL=OFF",
"-DBUILD_CVODE=OFF",
"-DBUILD_CVODES=OFF",
"-DBUILD_IDAS=OFF",
"-DBUILD_KINSOL=OFF",
"-DEXAMPLES_ENABLE:BOOL=OFF",
"-DKLU_ENABLE=ON",
"-DKLU_INCLUDE_DIR=../SuiteSparse-5.6.0/include",
"-DKLU_LIBRARY_DIR=../SuiteSparse-5.6.0/lib",
"-DCMAKE_INSTALL_PREFIX=" + sundials_inst,
]

# SUNDIALS are built within directory 'build_sundials' in the PyBaMM root
# directory
build_directory = os.path.abspath(os.path.join(directory, "build_sundials"))
if not os.path.exists(build_directory):
print("\n-" * 10, "Creating build dir", "-" * 40)
os.makedirs(build_directory)

sundials_src = "../sundials-5.0.0"
print("-" * 10, "Running CMake prepare", "-" * 40)
subprocess.run(["cmake", sundials_src] + cmake_args, cwd=build_directory)

print("-" * 10, "Building the sundials", "-" * 40)
make_cmd = ["make", "install"]
subprocess.run(make_cmd, cwd=build_directory)

0 comments on commit ce8f0ea

Please sign in to comment.