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

Migrate code and build library #4

Merged
merged 47 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4949fc8
build commit
santacodes Aug 29, 2024
5ecc6d4
fixing build
santacodes Sep 1, 2024
98083e7
change to has_idaklu
santacodes Sep 1, 2024
55f4cb5
final idaklu working build
santacodes Sep 1, 2024
754543b
added uv backend to noxfile
santacodes Sep 8, 2024
36e1d81
refactored .gitignore
santacodes Sep 25, 2024
d5fc30a
remove scikit
santacodes Sep 25, 2024
dc99f5a
Remove excess files, change install dir
kratman Sep 25, 2024
4825c83
Fix build
kratman Sep 25, 2024
9934040
Some cleanup
kratman Sep 25, 2024
a53df79
Get nox mostly working
kratman Sep 26, 2024
1c10c74
setup tests
kratman Sep 26, 2024
9bbfd83
nox config
kratman Sep 26, 2024
bff17b4
Move files
kratman Sep 26, 2024
8f3dff7
Attempt to fix install
kratman Sep 26, 2024
f25bbbb
Remove junk test
kratman Sep 26, 2024
a52d8d6
Rename test file
kratman Sep 26, 2024
12166a9
Fix workflow
kratman Sep 26, 2024
c694b1d
Fix workflow
kratman Sep 26, 2024
fcd3d6e
Try again
kratman Sep 26, 2024
084e440
Replace pybind11 with submodule
kratman Sep 26, 2024
1189c2f
Set pybind to a release
kratman Sep 26, 2024
239da0a
Add submodules to workflows
kratman Sep 26, 2024
cbafb53
Move source files
kratman Sep 27, 2024
930d05b
Copy newer cpp code
kratman Sep 27, 2024
e5e04f4
Adding missed source files
kratman Sep 27, 2024
4314200
Fix casadi path
kratman Sep 27, 2024
ac32bb6
Temporary fix
kratman Sep 27, 2024
1a1276e
Adding wheel workflow
kratman Sep 29, 2024
75ce8da
Simplify workflow for testing
kratman Sep 29, 2024
49b3591
Change title
kratman Sep 29, 2024
f1206be
Fix test command
kratman Sep 29, 2024
2489b4a
Replace install path
kratman Sep 30, 2024
483b5dd
Try another path
kratman Sep 30, 2024
264421d
Restrict max python version to 3.12
kratman Sep 30, 2024
6a017b5
Attempt to add windows wheel build
kratman Sep 30, 2024
a2006ec
Fix typo
kratman Sep 30, 2024
895ed8c
Minor updates, probably still broken
kratman Sep 30, 2024
54bd273
Fix test error
kratman Sep 30, 2024
b8b3053
Rename varible
kratman Sep 30, 2024
6984164
Adding publishing step
kratman Oct 1, 2024
5193477
Remove outdated workflows
kratman Oct 1, 2024
f13f9e0
Sync C++ code
kratman Oct 2, 2024
fa6b743
Fix include path
kratman Oct 2, 2024
ecccfd5
Fix path
kratman Oct 2, 2024
cdb48cc
Hopefully fix windows
kratman Oct 2, 2024
076f0cf
Updates for local IDEs
kratman Oct 2, 2024
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
285 changes: 285 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
name: Build wheels
on:
release:
types: [ published ]
workflow_dispatch:
pull_request:
branches:
- "main"

env:
CIBW_BUILD_VERBOSITY: 2
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
# Skip PyPy and MUSL builds in any and all jobs
CIBW_SKIP: "pp* *musllinux*"
FORCE_COLOR: 3

jobs:
build_windows_wheels:
name: Wheels (windows-latest)
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Get number of cores on Windows
id: get_num_cores
shell: python
run: |
from os import environ, cpu_count
num_cpus = cpu_count()
output_file = environ['GITHUB_OUTPUT']
with open(output_file, "a", encoding="utf-8") as output_stream:
output_stream.write(f"count={num_cpus}\n")

- name: Install vcpkg on Windows
run: |
cd C:\
rm -r -fo 'C:\vcpkg'
git clone https://github.com/microsoft/vcpkg
cd vcpkg
.\bootstrap-vcpkg.bat

- name: Build wheels on Windows
run: pipx run cibuildwheel --output-dir wheelhouse
env:
CIBW_ENVIRONMENT: >
PYBAMMSOLVERS_USE_VCPKG=ON
VCPKG_ROOT_DIR=C:\vcpkg
VCPKG_DEFAULT_TRIPLET=x64-windows-static-md
VCPKG_FEATURE_FLAGS=manifests,registries
CMAKE_GENERATOR="Visual Studio 17 2022"
CMAKE_GENERATOR_PLATFORM=x64
CMAKE_BUILD_PARALLEL_LEVEL=${{ steps.get_num_cores.outputs.count }}
CIBW_ARCHS: AMD64
CIBW_BEFORE_BUILD: python -m pip install setuptools wheel delvewheel # skip CasADi and CMake
CIBW_REPAIR_WHEEL_COMMAND: delvewheel repair --add-path C:/Windows/System32 -w {dest_dir} {wheel}
CIBW_TEST_EXTRAS: "dev"
CIBW_TEST_COMMAND: |
python -m pytest {project}/tests
- name: Upload Windows wheels
uses: actions/upload-artifact@v4
with:
name: wheels_windows
path: ./wheelhouse/*.whl
if-no-files-found: error

build_manylinux_wheels:
name: Wheels (linux-amd64)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'

- uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Build wheels on Linux
run: pipx run cibuildwheel --output-dir wheelhouse
env:
CIBW_ARCHS_LINUX: x86_64
CIBW_BEFORE_ALL_LINUX: >
yum -y install openblas-devel lapack-devel &&
bash install_sundials.sh
CIBW_BEFORE_BUILD_LINUX: python -m pip install cmake casadi setuptools wheel
CIBW_REPAIR_WHEEL_COMMAND_LINUX: auditwheel repair -w {dest_dir} {wheel}
CIBW_TEST_EXTRAS: "dev"
CIBW_TEST_COMMAND: |
set -e -x
python -m pytest {project}/tests

- name: Upload wheels for Linux
uses: actions/upload-artifact@v4
with:
name: wheels_manylinux
path: ./wheelhouse/*.whl
if-no-files-found: error

build_macos_wheels:
name: Wheels (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-13, macos-14]
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: '3.11'

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

- name: Build wheels on macOS
shell: bash
run: |
set -e -x

# Set LLVM-OpenMP URL
if [[ $(uname -m) == "x86_64" ]]; then
OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-64/llvm-openmp-11.1.0-hda6cdc1_1.tar.bz2"
elif [[ $(uname -m) == "arm64" ]]; then
OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-arm64/llvm-openmp-11.1.0-hf3c4609_1.tar.bz2"
fi

# Download gfortran with proper macOS minimum version (11.0)
if [[ $(uname -m) == "x86_64" ]]; then
GFORTRAN_URL="https://github.com/isuruf/gcc/releases/download/gcc-11.3.0-2/gfortran-darwin-x86_64-native.tar.gz"
KNOWN_SHA256="981367dd0ad4335613e91bbee453d60b6669f5d7e976d18c7bdb7f1966f26ae4 gfortran.tar.gz"
elif [[ $(uname -m) == "arm64" ]]; then
GFORTRAN_URL="https://github.com/isuruf/gcc/releases/download/gcc-11.3.0-2/gfortran-darwin-arm64-native.tar.gz"
KNOWN_SHA256="84364eee32ba843d883fb8124867e2bf61a0cd73b6416d9897ceff7b85a24604 gfortran.tar.gz"
fi

# Validate gfortran tarball
curl -L $GFORTRAN_URL -o gfortran.tar.gz
if ! echo "$KNOWN_SHA256" != "$(shasum --algorithm 256 gfortran.tar.gz)"; then
echo "Checksum failed"
exit 1
fi

mkdir -p gfortran_installed
tar -xv -C gfortran_installed/ -f gfortran.tar.gz

if [[ $(uname -m) == "x86_64" ]]; then
export FC=$(pwd)/gfortran_installed/gfortran-darwin-x86_64-native/bin/gfortran
export PATH=$(pwd)/gfortran_installed/gfortran-darwin-x86_64-native/bin:$PATH
elif [[ $(uname -m) == "arm64" ]]; then
export FC=$(pwd)/gfortran_installed/gfortran-darwin-arm64-native/bin/gfortran
export PATH=$(pwd)/gfortran_installed/gfortran-darwin-arm64-native/bin:$PATH
fi

# link libgfortran dylibs and place them in $SOLVER_LIB_PATH
# and then change rpath for each of them
# Note: libgcc_s.1.dylib not available on macOS arm64; skip for now
SOLVER_LIB_PATH=$(pwd)/.idaklu/lib
mkdir -p $SOLVER_LIB_PATH
if [[ $(uname -m) == "x86_64" ]]; then
lib_dir=$(pwd)/gfortran_installed/gfortran-darwin-x86_64-native/lib
for lib in libgfortran.5.dylib libgfortran.dylib libquadmath.0.dylib libquadmath.dylib libgcc_s.1.dylib libgcc_s.1.1.dylib; do
cp $lib_dir/$lib $SOLVER_LIB_PATH/
install_name_tool -id $SOLVER_LIB_PATH/$lib $SOLVER_LIB_PATH/$lib
codesign --force --sign - $SOLVER_LIB_PATH/$lib
done
elif [[ $(uname -m) == "arm64" ]]; then
lib_dir=$(pwd)/gfortran_installed/gfortran-darwin-arm64-native/lib
for lib in libgfortran.5.dylib libgfortran.dylib libquadmath.0.dylib libquadmath.dylib libgcc_s.1.1.dylib; do
cp $lib_dir/$lib $SOLVER_LIB_PATH/.
install_name_tool -id $SOLVER_LIB_PATH/$lib $SOLVER_LIB_PATH/$lib
codesign --force --sign - $SOLVER_LIB_PATH/$lib
done
fi

export SDKROOT=${SDKROOT:-$(xcrun --show-sdk-path)}

# Can't download LLVM-OpenMP directly, use conda/mamba and set environment variables
brew install miniforge
mamba create -n pybammsolvers-dev $OPENMP_URL
if [[ $(uname -m) == "x86_64" ]]; then
PREFIX="/usr/local/Caskroom/miniforge/base/envs/pybammsolvers-dev"
elif [[ $(uname -m) == "arm64" ]]; then
PREFIX="/opt/homebrew/Caskroom/miniforge/base/envs/pybammsolvers-dev"
fi

# Copy libomp.dylib from PREFIX to $SOLVER_LIB_PATH, needed for wheel repair
cp $PREFIX/lib/libomp.dylib $SOLVER_LIB_PATH/.
install_name_tool -id $SOLVER_LIB_PATH/libomp.dylib $SOLVER_LIB_PATH/libomp.dylib
codesign --force --sign - $SOLVER_LIB_PATH/libomp.dylib

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
export CFLAGS="$CFLAGS -I$PREFIX/include"
export CXXFLAGS="$CXXFLAGS -I$PREFIX/include"
export LDFLAGS="$LDFLAGS -L$PREFIX/lib -lomp"

# cibuildwheel not recognising its environment variable, so set manually
export CIBUILDWHEEL="1"

python install_KLU_Sundials.py
python -m cibuildwheel --output-dir wheelhouse
env:
# 10.13 for Intel (macos-12/macos-13), 11.0 for Apple Silicon (macos-14 and macos-latest)
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.os == 'macos-14' && '11.0' || '10.13' }}
CIBW_ARCHS_MACOS: auto
CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate
CIBW_REPAIR_WHEEL_COMMAND: |
if [[ $(uname -m) == "x86_64" ]]; then
delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel}
elif [[ $(uname -m) == "arm64" ]]; then
# Use higher macOS target for now since casadi/libc++.1.0.dylib is still not fixed
delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} --require-target-macos-version 11.1
for file in {dest_dir}/*.whl; do mv "$file" "${file//macosx_11_1/macosx_11_0}"; done
fi
CIBW_TEST_EXTRAS: "dev"
CIBW_TEST_COMMAND: |
set -e -x
python -m pytest {project}/tests

- name: Upload wheels for macOS (amd64, arm64)
uses: actions/upload-artifact@v4
with:
name: wheels_${{ matrix.os }}
path: ./wheelhouse/*.whl
if-no-files-found: error

build_sdist:
name: Build SDist
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Build SDist
run: pipx run build --sdist

- name: Upload SDist
uses: actions/[email protected]
with:
name: sdist
path: ./dist/*.tar.gz
if-no-files-found: error

publish_pypi:
if: github.repository == 'pybamm-team/pybammsolvers'
name: Upload package to PyPI
needs: [
build_manylinux_wheels,
build_macos_wheels,
build_windows_wheels,
build_sdist
]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pybammsolvers
permissions:
id-token: write

steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true

- name: Sanity check downloaded artifacts
run: ls -lA artifacts/

- name: Publish to PyPI
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: artifacts/
39 changes: 0 additions & 39 deletions .github/workflows/release.yml

This file was deleted.

33 changes: 9 additions & 24 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,25 @@ concurrency:
cancel-in-progress: true

jobs:
pytest-linux:
pytest:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- uses: actions/checkout@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -e ".[dev]"
- name: Test with pytest
run: |
pytest

pytest-windows:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
submodules: 'true'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -e ".[dev]"
- name: Test with pytest
sudo apt-get install gfortran gcc libopenblas-dev
pip install nox

- name: Build and test
run: |
pytest
nox
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
.idea
.vscode
cmake-build-*
*.egg-info
__pycache__
.venv
.env
.nox

setup.log
install_KLU_Sundials
.idaklu
build

# Extra directories for local work
workspace
deploy
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "pybind11"]
path = pybind11
url = [email protected]:pybind/pybind11.git
Loading
Loading