Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
23741ef
Fix: CasADi linking to work with pip isolated build environments
BradyPlanden Oct 9, 2025
7551a6d
tests: adds initial test suite w/ basic functionality
BradyPlanden Oct 9, 2025
8dd3ea2
infra: adds __version__ to package, adds nox to dev dependencies w/ u…
BradyPlanden Oct 10, 2025
90ca76c
tests: adds benchmark session, uv backend for nox, updates to unit su…
BradyPlanden Oct 10, 2025
ebffa02
benchmarks: remove icons
BradyPlanden Oct 13, 2025
9a70d96
Fix: RPath installation bool, updates PYBAMM_ENV in noxfile, adds nox…
BradyPlanden Oct 13, 2025
11cebde
test: try condition RPATH
BradyPlanden Oct 13, 2025
680e502
fix: precommit, integration workflow missing uv
BradyPlanden Oct 13, 2025
ccddae1
benchmarks: update regression threshold, increase repeats, try: fix w…
BradyPlanden Oct 13, 2025
046e98e
fix: integration workflow
BradyPlanden Oct 13, 2025
6abe878
CI: unifi package management
BradyPlanden Oct 13, 2025
184383c
benchmarks: timeit implementation
BradyPlanden Oct 13, 2025
afd14d3
test: adds casadi-based integration tests, removes simplistic unit te…
BradyPlanden Oct 15, 2025
1e78371
precommit additions
BradyPlanden Oct 15, 2025
728ec40
Suggestions from review
BradyPlanden Oct 16, 2025
dc5427f
precommit additions
BradyPlanden Oct 16, 2025
a204965
fix: avoid single-element vector operations for MacOS-intel
BradyPlanden Oct 16, 2025
accd07f
another test: separate negate from casadi symbol
BradyPlanden Oct 17, 2025
c573675
infra: skip macosx_x86_x64 tests for build_wheels.yml
BradyPlanden Oct 20, 2025
c137109
infra: test level skip instead of workflow level
BradyPlanden Oct 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Benchmarks

on:
pull_request:
branches:
- "main"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pytest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v5
with:
submodules: 'recursive'

- name: Install dependencies (macOS)
if: matrix.os == 'macos-15-intel' || matrix.os == 'macos-latest'
env:
HOMEBREW_NO_INSTALL_CLEANUP: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_COLOR: 1
NONINTERACTIVE: 1
run: |
brew analytics off
brew install libomp
brew reinstall gcc

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
run: |
pip install uv

- name: Run benchmarks
run: |
uvx nox -s benchmarks
27 changes: 5 additions & 22 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Clone PyBaMM repository
uses: actions/checkout@v5
with:
repository: pybamm-team/PyBaMM
path: PyBaMM
fetch-depth: 0
fetch-tags: true
- name: Install uv
run: |
pip install uv

- name: Build and test
run: |
# Install PyBaMM with dependencies
cd ./PyBaMM
pip install -e ".[all,dev,jax]"
cd ..

# Replace PyBaMM solvers
pip uninstall pybammsolvers --yes
python install_KLU_Sundials.py
pip install "numpy>=2" --upgrade
pip install .

# Run pybamm tests
cd ./PyBaMM
pytest tests/unit
pytest tests/integration
# Use PyBaMM-tests nox session
uvx nox -s pybamm-tests
6 changes: 3 additions & 3 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install nox
- name: Install uv
run: |
pip install nox
pip install uv

- name: Build and test
run: |
nox
uvx nox
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ build
# Extra directories for local work
workspace
deploy
PyBaMM

# benchmark results
performance_results.json
54 changes: 40 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,51 @@ if (${USE_PYTHON_CASADI})
message("Found Python CasADi library directory: ${CASADI_LIB_DIR}")
target_link_directories(idaklu PRIVATE ${CASADI_LIB_DIR})

set_target_properties(
idaklu PROPERTIES
INSTALL_RPATH "${CASADI_LIB_DIR}"
INSTALL_RPATH_USE_LINK_PATH TRUE
)
# Attempt to link the casadi library directly if found
find_library(CASADI_LIBRARY NAMES casadi PATHS ${CASADI_LIB_DIR} NO_DEFAULT_PATH)
if (CASADI_LIBRARY)
message("Found CasADi library: ${CASADI_LIBRARY}")
target_link_libraries(idaklu PRIVATE ${CASADI_LIBRARY})
else ()
message(WARNING "CasADi library not found in ${CASADI_LIB_DIR}. The target will rely on transitive linkage via CMake config if available.")
endif ()
# Set RPATH to find libraries relative to the module location
# This allows finding casadi in the same Python environment at runtime
# Module is at: site-packages/pybammsolvers/idaklu.so
# CasADi is at: site-packages/casadi/libcasadi.dylib
# SuiteSparse/SUNDIALS are found via DYLD_LIBRARY_PATH/LD_LIBRARY_PATH
# (set by noxfile or user environment) pointing to .idaklu/lib
# Note: Windows uses vcpkg with static linking, no RPATH needed

# For CI wheel builds, use BUILD_WITH_INSTALL_RPATH=FALSE so that
# wheel repair tools (delocate/auditwheel) can properly analyze dependencies.
# For local development, use BUILD_WITH_INSTALL_RPATH=TRUE so the module
# works immediately after pip install without wheel repair.
if(DEFINED ENV{CIBUILDWHEEL})
set(USE_INSTALL_RPATH_AT_BUILD FALSE)
else()
set(USE_INSTALL_RPATH_AT_BUILD TRUE)
endif()

if (APPLE)
set_target_properties(
idaklu PROPERTIES
BUILD_RPATH "${CASADI_LIB_DIR}"
BUILD_RPATH_USE_LINK_PATH FALSE
INSTALL_RPATH "@loader_path/../casadi"
BUILD_WITH_INSTALL_RPATH ${USE_INSTALL_RPATH_AT_BUILD}
)
else()
set_target_properties(
idaklu PROPERTIES
BUILD_RPATH "${CASADI_LIB_DIR}"
BUILD_RPATH_USE_LINK_PATH FALSE
INSTALL_RPATH "$ORIGIN/../casadi"
BUILD_WITH_INSTALL_RPATH ${USE_INSTALL_RPATH_AT_BUILD}
)
endif()
# Link against casadi by name, not absolute path, to avoid issues with
# pip's isolated build environments changing paths between configure and build
target_link_libraries(idaklu PRIVATE casadi)
Comment on lines +175 to +177
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good catches here, thanks! and sorry for the trouble here, I realise I was responsible for all this 😄

else ()
message(FATAL_ERROR "Could not find CasADi library directory")
endif ()
else ()
message("Trying to link against any casadi package apart from the Python one")
find_package(casadi CONFIG REQUIRED)
target_link_libraries(idaklu PRIVATE casadi)
endif ()

# openmp
Expand All @@ -180,7 +206,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
find_package(SUNDIALS REQUIRED)
message("SUNDIALS found in ${SUNDIALS_INCLUDE_DIR}: ${SUNDIALS_LIBRARIES}")
target_include_directories(idaklu PRIVATE ${SUNDIALS_INCLUDE_DIR})
target_link_libraries(idaklu PRIVATE ${SUNDIALS_LIBRARIES} casadi)
target_link_libraries(idaklu PRIVATE ${SUNDIALS_LIBRARIES})

# link suitesparse
# if using vcpkg, use config mode to
Expand Down
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ pip install pybammsolvers
The following solvers are available:
- PyBaMM's IDAKLU solver

## Local builds
## Development

### Local builds

For testing new solvers and unsupported architectures, local builds are possible.

### Nox
#### Nox (Recommended)

Nox can be used to do a quick build:
```bash
Expand All @@ -26,7 +28,7 @@ nox
```
This will setup an environment and attempt to build the library.

### MacOS
#### MacOS

Mac dependencies can be installed using brew
```bash
Expand All @@ -37,7 +39,7 @@ python install_KLU_Sundials.py
pip install .
```

### Linux
#### Linux

Linux installs may vary based on the distribution, however, the basic build can
be performed with the following commands:
Expand All @@ -48,3 +50,33 @@ pip install cmake casadi setuptools wheel "pybind11[global]"
python install_KLU_Sundials.py
pip install .
```

### Testing

The project includes comprehensive test suites:

#### Unit Tests
Test pybammsolvers functionality in isolation:
```bash
nox -s unit # Run all unit tests
nox -s integration # Run all integration tests
```

#### PyBaMM Integration Tests
Verify compatibility with PyBaMM:
```bash
nox -s pybamm-tests # Clone/update PyBaMM and run all tests
nox -s pybamm-tests -- --unit-only # Run only unit tests
nox -s pybamm-tests -- --integration-only # Run only integration tests
nox -s pybamm-tests -- --no-update # Skip git pull (use current version)
nox -s pybamm-tests -- --pybamm-dir ./custom/path # Use existing PyBaMM clone
nox -s pybamm-tests -- --branch develop # Use specific branch/tag
```

The integration tests ensure that changes to pybammsolvers don't break PyBaMM functionality.

### Benchmarks
Test for performance regressions against released PyBaMM:
```bash
nox -s benchmarks
```
Loading
Loading