diff --git a/.github/workflows/build_wheels_and_publish.yml b/.github/workflows/build_wheels_and_publish.yml new file mode 100644 index 0000000000..35d4963a6b --- /dev/null +++ b/.github/workflows/build_wheels_and_publish.yml @@ -0,0 +1,70 @@ +name: Build and deployment + +on: + push: + branches: master + +jobs: + build-wheels: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest] + python-version: [3.6, 3.7] + include: + - os: ubuntu-latest + python-version: 3.8 + - os: windows-latest + python-version: 3.6 + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Build manylinux Python wheels + if: matrix.os == 'ubuntu-latest' + uses: './build_manylinux_wheels' + + - name: Install standard python dependencies + if: matrix.os != 'ubuntu-latest' + run: | + python -m pip install --upgrade pip wheel setuptools + + - name: Install build-time deps for MacOS + if: matrix.os == 'macos-latest' + run: | + brew update + brew install graphviz + brew install sundials + git clone https://github.com/pybind/pybind11.git + + - name: Build wheels for MacOS and Windows + if: matrix.os != 'ubuntu-latest' + run: | + python -m pip wheel . -w dist/ --no-deps + + - name: Upload wheels + uses: actions/upload-artifact@v1 + with: + name: dist + path: dist + + + publish-pyi: + name: Upload wheels to PyPI + needs: build-wheels + runs-on: ubuntu-latest + steps: + - name: Download wheels + uses: actions/download-artifact@v1 + with: + name: dist + + - name: Publish wheels + uses: pypa/gh-action-pypi-publish@master + with: + user: __token__ + password: ${{ secrets.TESTPYPI_TOKEN }} + repository_url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index f29392e07a..d187cf09b1 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -93,14 +93,22 @@ jobs: export LD_LIBRARY_PATH=$HOME/.local/lib:scikits.odes/sundials5/lib:$LD_LIBRARY_PATH pip install -e .[docs] python run-tests.py --doctest - + - name: Install dev dependencies and run example tests if: matrix.os != 'windows-latest' run: | export LD_LIBRARY_PATH=$HOME/.local/lib:scikits.odes/sundials5/lib:$LD_LIBRARY_PATH pip install -e .[dev] python run-tests.py --examples - - - name: Instal and run coverage - if: success() && (matrix.os == 'unbuntu-latest' && matrix.python-version == 3.7) + + - name: Install and run coverage + if: success() && (matrix.os == 'ubuntu-latest' && matrix.python-version == 3.7) + run: | + pip install coverage + export LD_LIBRARY_PATH=$HOME/.local/lib:scikits.odes/sundials5/lib:$LD_LIBRARY_PATH + coverage run run-tests.py --nosub + coverage xml + + - name: Upload coverage report + if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.7 uses: codecov/codecov-action@v1 diff --git a/.gitignore b/.gitignore index ee078ba2ce..66d86b2264 100644 --- a/.gitignore +++ b/.gitignore @@ -80,6 +80,7 @@ sundials4 sundials-* SuiteSparse-* build_sundials +KLU_module_deps # downloads *.gz @@ -96,6 +97,9 @@ cmake_install.cmake third-party/pybind11 +pybind11/ + +setup.log + + -# Build dependencies/ -KLU_module_deps \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 88c404b7d8..6ee541bdac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ New SEI models, simplification of submodel structure, as well as optimisations a ## Bug fixes +- Fix a bug where slider plots do not update properly in notebooks ([#1041](https://github.com/pybamm-team/PyBaMM/pull/1041)) - Fix storing and plotting external variables in the solution ([#1026](https://github.com/pybamm-team/PyBaMM/pull/1026)) - Fix running a simulation with a model that is already discretized ([#1025](https://github.com/pybamm-team/PyBaMM/pull/1025)) - Fix CI not triggering for PR. ([#1013](https://github.com/pybamm-team/PyBaMM/pull/1013)) diff --git a/build_manylinux_wheels/Dockerfile b/build_manylinux_wheels/Dockerfile new file mode 100644 index 0000000000..e4f8913244 --- /dev/null +++ b/build_manylinux_wheels/Dockerfile @@ -0,0 +1,17 @@ +FROM quay.io/pypa/manylinux2010_x86_64:2020-05-29-c06f15c + +ENV PLAT manylinux2010_x86_64 + +RUN yum -y remove cmake +RUN yum -y install wget openblas-devel +RUN /opt/python/cp37-cp37m/bin/pip install --upgrade pip cmake +RUN ln -s /opt/python/cp37-cp37m/bin/cmake /usr/bin/cmake + +COPY install_sundials.sh /install_sundials.sh +RUN chmod +x /install_sundials.sh +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +RUN ./install_sundials.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/build_manylinux_wheels/action.yml b/build_manylinux_wheels/action.yml new file mode 100644 index 0000000000..1e852e923f --- /dev/null +++ b/build_manylinux_wheels/action.yml @@ -0,0 +1,17 @@ +# action.yml +# Based on RalfG/python-wheels-manylinux-build/action.yml by Ralf Gabriels + +name: 'Python wheels manylinux build' +author: 'Thibault Lestang' +description: 'Build manylinux wheels for PyBaMM' +inputs: + python-versions: + description: 'Python versions to target, space-separated' + required: true + default: 'cp36-cp36m cp37-cp37m' + +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.python-versions }} diff --git a/build_manylinux_wheels/entrypoint.sh b/build_manylinux_wheels/entrypoint.sh new file mode 100644 index 0000000000..77c19ade58 --- /dev/null +++ b/build_manylinux_wheels/entrypoint.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e -x + +# CLI arguments +PY_VERSIONS=$1 + +git clone https://github.com/pybind/pybind11.git /github/workspace/pybind11 +# Compile wheels +arrPY_VERSIONS=(${PY_VERSIONS// / }) +for PY_VER in "${arrPY_VERSIONS[@]}"; do + # Update pip + /opt/python/"${PY_VER}"/bin/pip install --upgrade --no-cache-dir pip + + # Build wheels + /opt/python/"${PY_VER}"/bin/pip wheel /github/workspace/ -w /github/workspace/wheelhouse/ --no-deps || { echo "Building wheels failed."; exit 1; } +done +ls -l /github/workspace/wheelhouse/ + +# Bundle external shared libraries into the wheels +for whl in /github/workspace/wheelhouse/*-linux*.whl; do + auditwheel repair "$whl" --plat "${PLAT}" -w /github/workspace/dist/ || { echo "Repairing wheels failed."; auditwheel show "$whl"; exit 1; } +done + +echo "Succesfully built wheels:" +ls -l /github/workspace/dist/ diff --git a/build_manylinux_wheels/install_sundials.sh b/build_manylinux_wheels/install_sundials.sh new file mode 100644 index 0000000000..24059e59a1 --- /dev/null +++ b/build_manylinux_wheels/install_sundials.sh @@ -0,0 +1,35 @@ +#!/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 + +SUITESPARSE_DIR=/deps/SuiteSparse-5.7.2 +SUNDIALS_DIR=/deps/sundials-5.3.0 + +for dir in SuiteSparse_config AMD COLAMD BTF KLU +do + cd $SUITESPARSE_DIR/$dir; + make library + make install INSTALL=/usr + cd ../ +done + +KLU_INCLUDE_DIR=/usr/include +KLU_LIBRARY_DIR=/usr/lib +mkdir -p /deps/build_sundials +cd /deps/build_sundials +cmake -DLAPACK_ENABLE=ON\ + -DSUNDIALS_INDEX_SIZE=32\ + -DEXAMPLES_ENABLE:BOOL=OFF\ + -DKLU_ENABLE=ON\ + -DKLU_INCLUDE_DIR=$KLU_INCLUDE_DIR\ + -DKLU_LIBRARY_DIR=$KLU_LIBRARY_DIR\ + -DCMAKE_INSTALL_PREFIX=/usr\ + $SUNDIALS_DIR +make install + diff --git a/docs/index.rst b/docs/index.rst index daa1685940..25c2994611 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -22,10 +22,20 @@ PyBaMM is available on GNU/Linux, MacOS and Windows. Using pip ---------- +GNU/Linux and Windows +~~~~~~~~~~~~~~~~~~~~~~ + .. code:: bash pip install pybamm +macOS +~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: bash + + brew install sundials && pip install pybamm + Using conda ------------- PyBaMM is available as a conda package through the conda-forge channel. diff --git a/docs/install/GNU-linux.rst b/docs/install/GNU-linux.rst index 32a7ae9f57..5047136d36 100644 --- a/docs/install/GNU-linux.rst +++ b/docs/install/GNU-linux.rst @@ -1,10 +1,11 @@ -GNU-Linux & MacOS -====================== +=================== + GNU-Linux & MacOS +=================== .. contents:: Prerequisites ---------------- +============= To use and/or contribute to PyBaMM, you must have Python 3.6 or 3.7 installed (note that 3.8 is not yet supported). @@ -37,10 +38,12 @@ then follow instructions in link on adding brew to path, and run brew install python3 Install PyBaMM ------------------ +============== + +.. _user-install-label: User install -~~~~~~~~~~~~ +------------ We recommend to install PyBaMM within a virtual environment, in order not to alter any distribution python files. To create a virtual @@ -64,10 +67,20 @@ the environment and go back to your original system, just type: deactivate -PyBaMM can be installed via pip: +PyBaMM can be installed via pip. On macOS, it is necessary to install the `SUNDIALS `__ +library beforehand. + +GNU/Linux and Windows +~~~~~~~~~~~~~~~~~~~~~ +.. code:: bash + + pip install pybamm +macOS +~~~~~ .. code:: bash + brew install sundials pip install pybamm PyBaMM’s dependencies (such as ``numpy``, ``scipy``, etc) will be @@ -79,38 +92,35 @@ For an introduction to virtual environments, see .. _scikits.odes-label: Optional - scikits.odes solver -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +------------------------------ Users can install `scikits.odes `__ in order to use the wrapped SUNDIALS ODE and DAE `solvers `__. +Currently, only GNU/Linux and macOS are supported. -**A pre-requisite** is the installation of a BLAS library (such as -`openblas `__). On Ubuntu/debian - -:: +GNU/Linux +~~~~~~~~~ - sudo apt install libopenblas-dev - -and on Mac OS +.. code:: bash -:: + apt install libopenblas-dev + pybamm_install_odes --install-sundials - brew install openblas +The ``pybamm_install_odes`` command is installed with PyBaMM. It automatically downloads and installs the SUNDIALS library on your +system (under ``~/.local``), before installing ``sckits.odes`` (by running ``pip install scikits.odes``). -After installing PyBaMM, the following command can be used to -automatically install ``scikits.odes`` and its dependencies +macOS +~~~~~ -:: - - $ pybamm_install_odes --install-sundials +.. code:: bash -The ``--install-sundials`` option is used to activate automatic -downloads and installation of the sundials library, which is required by -``scikits.odes``. + pip install scikits.odes + +Assuming that the SUNDIALS were installed as described :ref:`above`. Developer install -~~~~~~~~~~~~~~~~~~ +----------------- If you wish to contribute to PyBaMM, you should get the latest version from the GitHub repository. To do so, you must have Git and graphviz @@ -159,7 +169,7 @@ Before you start contributing to PyBaMM, please read the `contributing guidelines `__. Uninstall PyBaMM --------------------- +================ PyBaMM can be uninstalled by running @@ -170,7 +180,7 @@ PyBaMM can be uninstalled by running in your virtual environment. Troubleshooting -------------------- +=============== **Problem:** I’ve made edits to source files in PyBaMM, but these are not being used when I run my Python script. diff --git a/pybamm/plotting/quick_plot.py b/pybamm/plotting/quick_plot.py index a4c02aa492..a14b8d435b 100644 --- a/pybamm/plotting/quick_plot.py +++ b/pybamm/plotting/quick_plot.py @@ -465,14 +465,14 @@ def plot(self, t): Parameters ---------- t : float - Dimensional time (in hours) at which to plot. + Dimensional time (in 'time_units') at which to plot. """ import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec from matplotlib import cm, colors - t_in_seconds = t / self.time_scaling_factor + t_in_seconds = t * self.time_scaling_factor self.fig = plt.figure(figsize=self.figsize) self.gridspec = gridspec.GridSpec(self.n_rows, self.n_cols) @@ -526,8 +526,8 @@ def plot(self, t): ax.set_ylim(y_min, y_max) (self.time_lines[key],) = ax.plot( [ - t_in_seconds * self.time_scaling_factor, - t_in_seconds * self.time_scaling_factor, + t_in_seconds / self.time_scaling_factor, + t_in_seconds / self.time_scaling_factor, ], [y_min, y_max], "k--", diff --git a/setup.py b/setup.py index 880a5a3f5b..04eb80e6a3 100644 --- a/setup.py +++ b/setup.py @@ -160,7 +160,7 @@ def compile_KLU(): setup( name="pybamm", - version=load_version() + ".post3", + version=load_version() + ".post2", description="Python Battery Mathematical Modelling.", long_description="description", long_description_content_type="text/markdown", @@ -202,6 +202,6 @@ def compile_KLU(): "pybamm_add_parameter = pybamm.parameters_cli:add_parameter", "pybamm_rm_parameter = pybamm.parameters_cli:remove_parameter", "pybamm_install_odes = pybamm.install_odes:main", - ], + ] }, )