Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify pybind11 as a build-time dependency #3560

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9855e9d
#3480 Specify `pybind11` as a build-time dependency
agriyakhetarpal Nov 25, 2023
60da4cb
#3480 Modify logic that finds `pybind11` CMake files
agriyakhetarpal Nov 25, 2023
cc67bba
#3480 use `find_package()` to find `pybind11`
agriyakhetarpal Nov 25, 2023
0cb4fb6
#3480 Don't git-clone `pybind11` now
agriyakhetarpal Nov 25, 2023
5b4f9af
#3480 remove `pybind11` references from gitignore
agriyakhetarpal Nov 25, 2023
81eb5f8
#3480 remove `pybind11` from caches
agriyakhetarpal Nov 25, 2023
d256206
#3480 remove `pybind11` clone step from wheel builds
agriyakhetarpal Nov 25, 2023
7b8f940
# remove `pybind11` git-clone from benchmarks
agriyakhetarpal Nov 25, 2023
354585f
#3480 remove pybind11 git-clone from Docker images
agriyakhetarpal Nov 25, 2023
e462292
#3480 remove `pybind11` git-clone instructions for source installation
agriyakhetarpal Nov 25, 2023
f20f035
#3480 add a CHANGELOG entry
agriyakhetarpal Nov 25, 2023
5887feb
#3480 use an alternative way for CMake to detect `pybind11`
agriyakhetarpal Nov 25, 2023
59f25e5
#3480 Surefire way for KLU compilation on various platforms
agriyakhetarpal Nov 25, 2023
daeb726
#3480 `pybind11` is to be installed for benchmarks
agriyakhetarpal Nov 25, 2023
f7995fa
Merge branch 'develop' into pybind11-build-time-dependency
agriyakhetarpal Dec 16, 2023
7c717f9
#3480 update build command for `asv` benchmarks
agriyakhetarpal Dec 16, 2023
92ca984
Merge branch 'develop' into pybind11-build-time-dependency
agriyakhetarpal Dec 16, 2023
f10b3a4
#3480 retry `setup.py` build command for asv
agriyakhetarpal Dec 16, 2023
5d902bc
#3480 retry asv build command without cache dir
agriyakhetarpal Dec 16, 2023
9f2d3db
#3480 Try asv singular build command instead of two
agriyakhetarpal Dec 16, 2023
9277940
#3480 reset benchmarks and update build command
agriyakhetarpal Dec 16, 2023
cc33154
#3480 update pybind11 for workflow + revert to 3.8
agriyakhetarpal Dec 16, 2023
891eab8
#3480 use default built-in asv build command
agriyakhetarpal Dec 16, 2023
87d7e40
#3480 skip specific missing workflows on forks
agriyakhetarpal Dec 16, 2023
36c7613
#3480 Install `CMake` alongside `nox`
agriyakhetarpal Dec 16, 2023
2da613d
#3480 Install `CMake` alongside `nox` and skip `pybamm-requires`
agriyakhetarpal Dec 16, 2023
91e40f3
#3480 Remove `CMake` as a build-time dependency
agriyakhetarpal Dec 16, 2023
4831708
#3480 Add notes about how to install CMake
agriyakhetarpal Dec 16, 2023
9118c2b
#3480 Modify logic that checks for CMake + pybind11
agriyakhetarpal Dec 16, 2023
44ce67e
Revert "#3480 Install `CMake` alongside `nox` and skip `pybamm-requir…
agriyakhetarpal Dec 16, 2023
e80aaef
#3480 Install nox and CMake wherever needed
agriyakhetarpal Dec 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/benchmark_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
- name: Install Linux system dependencies
run: |
sudo apt-get update
sudo apt install gfortran gcc libopenblas-dev
sudo apt-get install gfortran gcc libopenblas-dev

- name: Install python dependencies
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip wheel setuptools wget cmake casadi numpy
python -m pip install --upgrade pip wheel setuptools wget cmake casadi pybind11[global]
python -m pip install asv[virtualenv]

- name: Install SuiteSparse and SUNDIALS
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/periodic_benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:

publish-results:
name: Push and publish results
if: github.repository == 'pybamm-team/pybamm'
needs: benchmarks
runs-on: ubuntu-latest
steps:
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
with:
python-version: 3.8

- name: Clone pybind11 repo (no history)
run: git clone --depth 1 --branch v2.11.1 https://github.com/pybind/pybind11.git

- name: Install vcpkg on Windows
run: |
cd C:\
Expand Down Expand Up @@ -76,9 +73,6 @@ jobs:
with:
python-version: 3.8

- name: Clone pybind11 repo (no history)
run: git clone --depth 1 --branch v2.11.1 https://github.com/pybind/pybind11.git

# sometimes gfortran cannot be found, so reinstall gcc just to be sure
- name: Install SuiteSparse and SUNDIALS on macOS
if: matrix.os == 'macos-latest'
Expand Down Expand Up @@ -173,7 +167,7 @@ jobs:
open_failure_issue:
needs: [build_windows_wheels, build_wheels, build_sdist]
name: Open an issue if build fails
if: ${{ always() && contains(needs.*.result, 'failure') }}
if: contains(needs.*.result, 'failure') && github.repository == 'pybamm-team/PyBaMM'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run_periodic_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ jobs:
if: matrix.os == 'windows-latest'
run: choco install graphviz --version=2.38.0.20190211

- name: Install nox
run: python -m pip install nox
- name: Install nox and CMake
run: python -m pip install nox cmake

- name: Install SuiteSparse and SUNDIALS on GNU/Linux and macOS
if: matrix.os != 'windows-latest'
Expand Down
31 changes: 13 additions & 18 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,15 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install nox
run: python -m pip install nox
- name: Install nox and CMake
run: python -m pip install nox cmake

- name: Cache pybamm-requires nox environment for GNU/Linux and macOS
uses: actions/cache@v3
if: matrix.os != 'windows-latest'
with:
path: |
# Repository files
${{ github.workspace }}/pybind11/
${{ github.workspace }}/install_KLU_Sundials/
# Headers and dynamic library files for SuiteSparse and SUNDIALS
${{ env.HOME }}/.local/lib/
Expand Down Expand Up @@ -148,15 +147,14 @@ jobs:
python-version: 3.11
cache: 'pip'

- name: Install nox
run: python -m pip install nox
- name: Install nox and CMake
run: python -m pip install nox cmake

- name: Cache pybamm-requires nox environment for GNU/Linux
uses: actions/cache@v3
with:
path: |
# Repository files
${{ github.workspace }}/pybind11/
${{ github.workspace }}/install_KLU_Sundials/
# Headers and dynamic library files for SuiteSparse and SUNDIALS
${{ env.HOME }}/.local/lib/
Expand Down Expand Up @@ -229,16 +227,15 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install nox
run: python -m pip install nox
- name: Install nox and CMake
run: python -m pip install nox cmake

- name: Cache pybamm-requires nox environment for GNU/Linux and macOS
uses: actions/cache@v3
if: matrix.os != 'windows-latest'
with:
path: |
# Repository files
${{ github.workspace }}/pybind11/
${{ github.workspace }}/install_KLU_Sundials/
# Headers and dynamic library files for SuiteSparse and SUNDIALS
${{ env.HOME }}/.local/lib/
Expand Down Expand Up @@ -270,15 +267,15 @@ jobs:
- name: Install Linux system dependencies
uses: awalsh128/cache-apt-pkgs-action@v1.3.1
with:
packages: gfortran gcc graphviz pandoc
packages: graphviz pandoc
execute_install_scripts: true

# dot -c is for registering graphviz fonts and plugins
- name: Install OpenBLAS and TeXLive for Linux
- name: Install TeXLive for Linux
run: |
sudo apt-get update
sudo dot -c
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng
sudo apt-get install texlive-latex-extra dvipng

- name: Set up Python 3.11
id: setup-python
Expand Down Expand Up @@ -329,15 +326,14 @@ jobs:
python-version: 3.11
cache: 'pip'

- name: Install nox
run: python -m pip install nox
- name: Install nox and CMake
run: python -m pip install nox cmake

- name: Cache pybamm-requires nox environment for GNU/Linux
uses: actions/cache@v3
with:
path: |
# Repository files
${{ github.workspace }}/pybind11/
${{ github.workspace }}/install_KLU_Sundials/
# Headers and dynamic library files for SuiteSparse and SUNDIALS
${{ env.HOME }}/.local/lib/
Expand Down Expand Up @@ -384,15 +380,14 @@ jobs:
python-version: 3.11
cache: 'pip'

- name: Install nox
run: python -m pip install nox
- name: Install nox and CMake
run: python -m pip install nox cmake

- name: Cache pybamm-requires nox environment for GNU/Linux
uses: actions/cache@v3
with:
path: |
# Repository files
${{ github.workspace }}/pybind11/
${{ github.workspace }}/install_KLU_Sundials/
# Headers and dynamic library files for SuiteSparse and SUNDIALS
${{ env.HOME }}/.local/lib/
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ Makefile
cmake_install.cmake
*.so

third-party/pybind11
pybind11/

# Build dependencies/
KLU_module_deps

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

## Optimizations

- Added `pybind11` as a build-time dependency, therefore simplifying the installation process ([#3560](https://github.com/pybamm-team/PyBaMM/pull/3560))
- Updated `jax` and `jaxlib` to the latest available versions and added Windows (Python 3.9+) support for the Jax solver ([#3550](https://github.com/pybamm-team/PyBaMM/pull/3550))

## Breaking changes
Expand Down
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ endif()
# casadi seems to compile without the newer versions of std::string
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)

if(NOT PYBIND11_DIR)
set(PYBIND11_DIR pybind11)
endif()
find_package(pybind11 CONFIG REQUIRED)

add_subdirectory(${PYBIND11_DIR})
pybind11_add_module(idaklu
pybamm/solvers/c_solvers/idaklu/casadi_functions.cpp
pybamm/solvers/c_solvers/idaklu/casadi_functions.hpp
Expand Down
12 changes: 3 additions & 9 deletions asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"version": 1,

// The name of the project being benchmarked
"project": "PyBaMM",
"project": "pybamm",

// The project's homepage
"project_url": "https://www.pybamm.org/",
"project_url": "https://pybamm.org/",

// The URL or local path of the source code repository for the
// project being benchmarked
Expand All @@ -23,12 +23,6 @@
//
// "install_command": ["in-dir={env_dir} python -mpip install {wheel_file}"],
// "uninstall_command": ["return-code=any python -mpip uninstall -y {project}"],
"build_command": [
"/bin/rm -rf pybind11",
"/usr/bin/git clone --depth 1 --branch v2.6.2 https://github.com/pybind/pybind11.git",
"python setup.py build",
"PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
],

// List of branches to benchmark. If not provided, defaults to "master"
// (for git) or "default" (for mercurial).
Expand Down Expand Up @@ -87,7 +81,7 @@
"sympy": [],
"bpx": [],
"tqdm": [],
"matplotlib": [],
"matplotlib": []
},
"env": {
"LD_LIBRARY_PATH": "/home/runner/.local/lib"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ Manual install of build time requirements

If you'd rather do things yourself,

1. Make sure you have CMake installed
1. Make sure you have CMake installed. CMake can be installed using ``pip``, ``brew``, or your system's package manager.
2. Compile and install SuiteSparse (PyBaMM only requires the ``KLU`` component).
3. Compile and install SUNDIALS.
4. Clone the pybind11 repository in the ``PyBaMM/`` directory (make sure the directory is named ``pybind11``).


PyBaMM ships with a Python script that automates points 2. and 3. You can run it with

Expand Down
8 changes: 0 additions & 8 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ def run_pybamm_requires(session):
if sys.platform != "win32":
session.install("wget", "cmake", silent=False)
session.run("python", "scripts/install_KLU_Sundials.py")
if not os.path.exists("./pybind11"):
session.run(
"git",
"clone",
"https://github.com/pybind/pybind11.git",
"pybind11/",
external=True,
)
else:
session.error("nox -s pybamm-requires is only available on Linux & macOS.")

Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
requires = [
"setuptools>=64",
"wheel",
# On Windows, use the CasADi vcpkg registry and CMake bundled from MSVC
# On Windows, use the CasADi vcpkg registry
"casadi>=3.6.3; platform_system!='Windows'",
"cmake; platform_system!='Windows'",
"pybind11[global]>=2.11.1",
]
build-backend = "setuptools.build_meta"
# Note: CMake is required to compile the IDAKLU solver but is not bundled with
# PyBaMM as a build-time dependency. If CMake is not installed, the IDAKLU
# solver compilation does not proceed.

[project]
name = "pybamm"
Expand Down
4 changes: 0 additions & 4 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ RUN pip install cmake

RUN if [ "$IDAKLU" = "true" ]; then \
python scripts/install_KLU_Sundials.py && \
rm -rf pybind11 && \
git clone https://github.com/pybind/pybind11.git && \
pip install --user -e ".[all,dev,docs]"; \
fi

Expand All @@ -54,8 +52,6 @@ RUN if [ "$JAX" = "true" ]; then \

RUN if [ "$ALL" = "true" ]; then \
python scripts/install_KLU_Sundials.py && \
rm -rf pybind11 && \
git clone https://github.com/pybind/pybind11.git && \
pip install --user -e ".[all,dev,docs,jax,odes]"; \
fi

Expand Down
36 changes: 17 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,37 +241,35 @@ def run(self):


def compile_KLU():
# Return whether or not the KLU extension should be compiled.
# Return True if:
# - Not running on Windows AND
# - CMake is found AND
# - The pybind11/ directory is found in the PyBaMM project directory
# Decide whether or not the KLU extension should be compiled.
# Return True if both of the following conditions are met:
#
# 1. CMake is found
# 2. pybind11 is found
#
# Otherwise, return False

CMakeFound = True
PyBind11Found = True
windows = (not system()) or system() == "Windows"

msg = "Running on Windows" if windows else "Not running on windows"
logger.info(msg)

# CMake
try:
subprocess.run(["cmake", "--version"])
logger.info("Found CMake.")
except OSError:
CMakeFound = False
logger.info("Could not find CMake. Skipping compilation of KLU module.")

pybamm_project_dir = os.path.dirname(os.path.abspath(__file__))
pybind11_dir = os.path.join(pybamm_project_dir, "pybind11")
# pybind11
try:
open(os.path.join(pybind11_dir, "tools", "pybind11Tools.cmake"))
logger.info(f"Found pybind11 directory ({pybind11_dir})")
except FileNotFoundError:
from pybind11 import get_cmake_dir
pybind11_config = os.path.join(get_cmake_dir(), "pybind11Tools.cmake")
if not os.path.isfile(pybind11_config):
raise FileNotFoundError
logger.info("Found pybind11")
except ModuleNotFoundError or FileNotFoundError:
PyBind11Found = False
msg = (
f"Could not find PyBind11 directory ({pybind11_dir})."
" Skipping compilation of KLU module."
)
logger.info(msg)
logger.info("Could not find pybind11. Skipping compilation of KLU module.")

return CMakeFound and PyBind11Found

Expand Down