PyBaMM: Mac OS Sundials bug
Descirbe the bug scikits.odes does not work (“image not found”) when following installation instructions
Explanation
As I understand it the problem is that scikits.odes looks for libsundials_sunlinsolklu.3.dylib, but brew install sundials installs a more recent version, which only has
libsundials_sunlinsolklu.dylib
libsundials_sunlinsollapackband.3.5.0.dylib
so libsundials_sunlinsolklu.3.dylib cannot be found.
This is not caught by the Mac OS tests since in CI the Mac OS tests use the script install_KLU_Sundials.py
Furthermore, if installing locally, with tox -e pybamm-requires, the script is used (which installs the correct version of sundials) but only LD_LIBRARY_PATH is updated, and not DYLD_LIBRARY_PATH as should be the case for mac.
This means that scikits.odes is still looking in /usr/local/opt/ for sundials, where it finds the incorrect brew installation, instead of in ~/.local/lib
** Solution **
- Remove the requirement for
brew install sundialsfrom docs - Use the KLU script to install sundials on mac, and also update
DYLD_LIBRARY_PATH
This could also be an opportunity to clean up the install docs, which I still find a little bit confusing
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (9 by maintainers)
Hi @shday and @tinosulzer, I sense there is a bit of confusion here, which I hope I can clear.
Short answer
If you’re on MacOS, you must install the sundials library yourself. There are several ways to do that, but the most straightforward is to use Homebrew, following the instructions available here. I suggest you give it a try and tell us the result.
Longer answer:
Whenever you type
pip install pybamm, pip fetches the PyBaMM package from the Python Package Index (PyPI). However, pip does not download all python files one by one, but rather an archive that contains the PyBaMM’s source code, some metadata and compiled modules, like theidaklumodule. Indeed, if you look into PyBaMM’s sources, you’ll find that theidaklumodule is actually written in C++, and must therefore be compiled before being available for import. As a user, you don’t have to do that yourself though because the module was compiled by us before hand, and the resultingidaklu.cpython-38-darwin.sofile is included in the archive pip downloads and installs. However, theidaklumodule has a runtime dependency on the sundials library, that must be available (in the form of a shared library) on your system when you import the module. For GNU/Linux systems, the compiled version of sundials is also included in the archive pip downloads, therefore apip install pybammis all that is required to get everything running. On Mac however, the compiled sundials is not included in that archive, and therefore users must install sundials themselves. Thanks to Homebrew, that’s just another short command.Now, you could also choose to clone the PyBaMM repo and install pybamm from that instead of the archive available on PyPI. This would be a good choice if you wanted to e.g. modify/contribute to PyBaMM. In this case however, you don’t benefit from the pre-compiled modules and dependencies, and you’ll have to do it yourself. As you’ve noticed already, the PyBaMM repo contains a python script that automatically downloads, compile and install the sundials library (
install_KLU_Sundials.py). Theidaklumodule is automatically compiled when you invoke pip on the PyBaMM repo. The compilation and installation of PyBaMM from the repo is described here.I hope that’s helpful - both in practice as well as to help understand the different moving parts. Please let us know if youŕe confused by the installations instructions: we’re about to refine them to hopefully make them clearer, and any feedback is useful.