Skip to content

Commit

Permalink
Merge branch 'develop' into issue-1429-simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Mar 17, 2021
2 parents c8be0f3 + daf7fa7 commit cd2ffcd
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 94 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build

on:
push:
branches: master
workflow_dispatch:
inputs:
target:
description: 'Deployment target. Can be "pypi" or "testpypi"'
default: 'pypi'

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macOS-10.15, ubuntu-20.04]

steps:
- uses: actions/checkout@v2

# Used to host cibuildwheel
- uses: actions/setup-python@v2

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==1.9.0

- name: Install sundials on macOS
if: matrix.os == 'macOS-10.15'
run: |
brew update
brew install sundials
- name: Clone pybind11 repo
run: git clone https://github.com/pybind/pybind11.git

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BEFORE_ALL_LINUX: "bash build_manylinux_wheels/install_sundials.sh 5.8.1 5.7.0"
CIBW_BEFORE_BUILD_LINUX: "python -m pip install cmake"

- uses: actions/upload-artifact@v2
with:
name: wheels
path: ./wheelhouse/*.whl


publish-pypi:
name: Upload wheels to PyPI
needs: build_wheels
runs-on: ubuntu-latest
steps:
- name: Download wheels
uses: actions/download-artifact@v1
with:
name: wheels

- name: Publish wheels on PyPI
if: ${{ github.events.inputs.target }} == 'pypi'
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
packages_dir: wheels/

- name: Publish wheels on TestPyPI
if: ${{ github.events.inputs.target }} == 'testpypi'
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.TESTPYPI_TOKEN }}
packages_dir: wheels/
repository_url: https://test.pypi.org/legacy/
72 changes: 0 additions & 72 deletions .github/workflows/build_wheels_and_publish.yml

This file was deleted.

3 changes: 1 addition & 2 deletions CMakeBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ def run(self):
def move_output(self, ext):
# Copy built module to dist/ directory
build_temp = Path(self.build_temp).resolve()
source_path = build_temp / self.get_ext_filename(ext.name)
# Get destination location
# self.get_ext_fullpath(ext.name) -->
# build/lib.linux-x86_64-3.5/idaklu.cpython-37m-x86_64-linux-gnu.so
# using resolve() with python < 3.6 will result in a FileNotFoundError
# since the location does not yet exists.
dest_path = Path(self.get_ext_fullpath(ext.name)).resolve()
source_path = build_temp / self.get_ext_filename(ext.name)
source_path = build_temp / os.path.basename(self.get_ext_filename(ext.name))
dest_directory = dest_path.parents[0]
dest_directory.mkdir(parents=True, exist_ok=True)
self.copy_file(source_path, dest_path)
81 changes: 63 additions & 18 deletions build_manylinux_wheels/install_sundials.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,80 @@
#!/bin/bash

mkdir /deps
wget https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/v5.7.2.tar.gz .
wget https://computing.llnl.gov/projects/sundials/download/sundials-5.3.0.tar.gz .
tar -xf v5.7.2.tar.gz --directory /deps
tar -xf sundials-5.3.0.tar.gz --directory /deps
rm v5.7.2.tar.gz
rm sundials-5.3.0.tar.gz
# This script installs both SuiteSparse
# (https://people.engr.tamu.edu/davis/suitesparse.html) and Sundials
# (https://computing.llnl.gov/projects/sundials) from source. For each
# two library:
# - Archive downloaded and source code extrated in current working
# directory.
# - Library is built and installed.
#
# Usage: ./install_sundials.sh suitesparse_version sundials_version

SUITESPARSE_DIR=/deps/SuiteSparse-5.7.2
SUNDIALS_DIR=/deps/sundials-5.3.0
function prepend_python_bin_dir_to_PATH {
python_bin_dir_cmd="print(os.path.split(sys.executable)[0])"
python_bin_dir=$(python -c "import sys, os;$python_bin_dir_cmd")
export PATH=$python_bin_dir:$PATH
}

function download {
ROOT_ADDR=$1
FILENAME=$2

wget -q $ROOT_ADDR/$FILENAME
}

function extract {
tar -xf $1
}

SUITESPARSE_VERSION=$1
SUNDIALS_VERSION=$2

SUITESPARSE_ROOT_ADDR=https://github.com/LLNL/sundials/releases/download/v$SUNDIALS_VERSION
SUNDIALS_ROOT_ADDR=https://computing.llnl.gov/projects/sundials/download

SUITESPARSE_ARCHIVE_NAME=v$SUITESPARSE_VERSION.tar.gz
SUNDIALS_ARCHIVE_NAME=sundials-$SUNDIALS_VERSION.tar.gz

yum -y update
yum -y install wget
download $SUITESPARSE_ROOT_ADDR $SUITESPARSE_ARCHIVE_NAME
download $SUNDIALS_ROOT_ADDR $SUNDIALS_ARCHIVE_NAME
extract $SUITESPARSE_ARCHIVE_NAME
extract $SUNDIALS_ARCHIVE_NAME

### Compile and install SUITESPARSE ###
# SuiteSparse is required to compile SUNDIALS's
# KLU solver.

SUITESPARSE_DIR=SuiteSparse-$SUITESPARSE_VERSION
for dir in SuiteSparse_config AMD COLAMD BTF KLU
do
cd $SUITESPARSE_DIR/$dir;
make library
make install INSTALL=/usr
cd ../
make -C $SUITESPARSE_DIR/$dir library
make -C $SUITESPARSE_DIR/$dir install INSTALL=/usr
done

### Compile and install SUNDIALS ###

# Building cmake requires cmake >= 3.5
python -m pip install cmake
prepend_python_bin_dir_to_PATH

# Building SUNDIALS requires a BLAS library
yum -y install openblas-devel

mkdir -p build_sundials
cd build_sundials
KLU_INCLUDE_DIR=/usr/include
KLU_LIBRARY_DIR=/usr/lib
mkdir -p /deps/build_sundials
cd /deps/build_sundials
cmake -DLAPACK_ENABLE=ON\
SUNDIALS_DIR=sundials-$SUNDIALS_VERSION
cmake -DENABLE_LAPACK=ON\
-DSUNDIALS_INDEX_SIZE=32\
-DEXAMPLES_ENABLE:BOOL=OFF\
-DKLU_ENABLE=ON\
-DENABLE_KLU=ON\
-DKLU_INCLUDE_DIR=$KLU_INCLUDE_DIR\
-DKLU_LIBRARY_DIR=$KLU_LIBRARY_DIR\
-DCMAKE_INSTALL_PREFIX=/usr\
$SUNDIALS_DIR
../$SUNDIALS_DIR
make install

2 changes: 1 addition & 1 deletion pybamm/solvers/idaklu_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import importlib

idaklu_spec = importlib.util.find_spec("idaklu")
idaklu_spec = importlib.util.find_spec("pybamm.solvers.idaklu")
if idaklu_spec is not None:
idaklu = importlib.util.module_from_spec(idaklu_spec)
idaklu_spec.loader.exec_module(idaklu)
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ def compile_KLU():
pybamm_data.append("./CITATIONS.txt")
pybamm_data.append("./plotting/pybamm.mplstyle")

idaklu_ext = Extension("idaklu", ["pybamm/solvers/c_solvers/idaklu.cpp"])
idaklu_ext = Extension(
"pybamm.solvers.idaklu",
["pybamm/solvers/c_solvers/idaklu.cpp"]
)
ext_modules = [idaklu_ext] if compile_KLU() else []

jax_dependencies = []
Expand Down

0 comments on commit cd2ffcd

Please sign in to comment.